久久久久久久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 的意思不同)
主站蜘蛛池模板: 毛片在线看片 | 亚洲91精品| 久久久久久久久91 | 91一区 | 毛片免费在线 | 欧美一级免费 | 99re国产视频| 色综合天天综合网国产成人网 | 亚洲一区二区三区在线 | 欧美片网站免费 | 国产精品2| 麻豆视频在线免费观看 | 国产一区二区三区高清 | 美女国内精品自产拍在线播放 | 日本一区不卡 | jizz视频 | 国产精品揄拍一区二区 | 天天爽网站 | 国产精品视频免费观看 | av色站| 日本黄视频在线观看 | 精品亚洲一区二区三区 | 一区二区亚洲 | 久久久久久亚洲欧洲 | 特级丰满少妇一级aaaa爱毛片 | 成人免费视频观看 | 国产一级淫片a直接免费看 免费a网站 | 天天干亚洲 | 久久久久无码国产精品一区 | 日韩精品在线视频 | 日韩视频二区 | 美女久久视频 | 成人二区 | 日本特黄a级高清免费大片 成年人黄色小视频 | 成人高清在线 | 日韩精品免费一区二区在线观看 | 成人在线视频免费播放 | 亚洲视频在线观看 | 免费观看毛片 | 亚洲欧美日韩国产 | 中文字幕视频免费 |