久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Python中不準確的對數

Inaccurate Logarithm in Python(Python中不準確的對數)
本文介紹了Python中不準確的對數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我每天都在公司使用 Python 2.4.我使用了標準數學庫中的通用對數函數log",當我輸入 log(2**31, 2) 時,它返回 31.000000000000004,這讓我覺得有點奇怪.

I work daily with Python 2.4 at my company. I used the versatile logarithm function 'log' from the standard math library, and when I entered log(2**31, 2) it returned 31.000000000000004, which struck me as a bit odd.

我對 2 的其他冪也做了同樣的事情,而且效果很好.我跑了 'log10(2**31)/log10(2)' 得到了 31.0 輪

I did the same thing with other powers of 2, and it worked perfectly. I ran 'log10(2**31) / log10(2)' and I got a round 31.0

我嘗試在 Python 3.0.1 中運行相同的原始函數,假設它已在更高級的版本中得到修復.

I tried running the same original function in Python 3.0.1, assuming that it was fixed in a more advanced version.

為什么會這樣?Python中的數學函數是否可能存在一些不準確之處?

Why does this happen? Is it possible that there are some inaccuracies in mathematical functions in Python?

推薦答案

這對于計算機算術來說是意料之中的.它遵循特定規則,例如 IEEE 754,可能與您所學的數學不符在學校.

This is to be expected with computer arithmetic. It is following particular rules, such as IEEE 754, that probably don't match the math you learned in school.

如果這確實很重要,請使用 Python 的 十進制類型.

If this actually matters, use Python's decimal type.

例子:

from decimal import Decimal, Context
ctx = Context(prec=20)
two = Decimal(2)
ctx.divide(ctx.power(two, Decimal(31)).ln(ctx), two.ln(ctx))

這篇關于Python中不準確的對數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Python 3 Float Decimal Points/Precision(Python 3 浮點小數點/精度)
Converting Float to Dollars and Cents(將浮點數轉換為美元和美分)
What are some possible calculations with numpy or scipy that can return a NaN?(numpy 或 scipy 有哪些可能的計算可以返回 NaN?)
Python float to ratio(Python浮動比率)
How to manage division of huge numbers in Python?(如何在 Python 中管理大量數字的除法?)
mean from pandas and numpy differ(pandas 和 numpy 的意思不同)
主站蜘蛛池模板: 欧美国产免费 | 精品国产一区二区三区免费 | 欧美一级二级三级视频 | 久久久免费毛片 | 中文字幕亚洲一区二区三区 | 久热中文字幕 | 国产美女永久免费无遮挡 | www.99热这里只有精品 | 一级久久久久久 | 亚洲精品欧美精品 | 成人免费共享视频 | 狠狠躁天天躁夜夜躁婷婷老牛影视 | 中文在线www | 日韩免费高清视频 | 狠狠干av | 成人av电影网 | 99精品国产一区二区三区 | 一区二区三区av | www.久久| 成人影院网站ww555久久精品 | 中文字幕在线不卡 | 日本天堂一区二区 | 欧美激情一区二区三区 | 亚洲欧美国产毛片在线 | 99久久久国产精品免费消防器 | 亚洲风情在线观看 | 热久色| 精品国产乱码一区二区三区a | 国产精品一区二区久久 | 极品粉嫩国产48尤物在线播放 | 日本精品一区二区三区四区 | 91在线免费视频 | 久草在线免费资源 | 国产电影一区二区在线观看 | www.久久 | 精品1区| 久久久久久久综合色一本 | 国产一级片网站 | 国产精品成人一区二区三区 | 亚洲综合在 | 日韩在线观看网站 |