久久久久久久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 的意思不同)
主站蜘蛛池模板: 成人久久久 | 懂色tv | 亚洲精品欧美精品 | 久久这里有精品 | 亚洲一区二区三区在线播放 | 影视一区 | 超碰91在线 | 国产精品久久毛片av大全日韩 | 久久久久久久久久久国产 | 精品久久久久久中文字幕 | 日韩福利 | 精品美女在线观看视频在线观看 | 91一区二区三区 | 亚洲国产免费 | 五月天婷婷丁香 | 亚洲国产精品一区二区三区 | 国产95在线 | 欧洲成人免费视频 | 在线国产中文字幕 | 中文字幕日韩欧美一区二区三区 | 免费黄色在线 | 一区二区在线不卡 | 久久91| 天天干天天爱天天 | 女人一区 | 午夜欧美| 国产亚洲黄色片 | 婷婷色国产偷v国产偷v小说 | 亚洲精品自在在线观看 | 涩涩视频在线观看免费 | 天天干狠狠操 | 韩国精品一区 | 欧美日韩久 | 久久一区二区三区四区五区 | 亚洲午夜精品一区二区三区他趣 | 亚洲欧美一区二区三区国产精品 | 伊人在线视频 | 亚洲欧美久久 | 久久在线| 亚洲一区不卡 | 日韩毛片在线视频 |