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

Python中不準(zhǔn)確的對數(shù)

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

問題描述

我每天都在公司使用 Python 2.4.我使用了標(biāo)準(zhǔn)數(shù)學(xué)庫中的通用對數(shù)函數(shù)log",當(dāng)我輸入 log(2**31, 2) 時(shí),它返回 31.000000000000004,這讓我覺得有點(diǎn)奇怪.

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 中運(yùn)行相同的原始函數(shù),假設(shè)它已在更高級的版本中得到修復(fù).

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

為什么會這樣?Python中的數(shù)學(xué)函數(shù)是否可能存在一些不準(zhǔn)確之處?

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

推薦答案

這對于計(jì)算機(jī)算術(shù)來說是意料之中的.它遵循特定規(guī)則,例如 IEEE 754,可能與您所學(xué)的數(shù)學(xué)不符在學(xué)校.

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.

如果這確實(shí)很重要,請使用 Python 的 十進(jìn)制類型.

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))

這篇關(guān)于Python中不準(zhǔn)確的對數(shù)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Python 3 Float Decimal Points/Precision(Python 3 浮點(diǎn)小數(shù)點(diǎn)/精度)
Converting Float to Dollars and Cents(將浮點(diǎn)數(shù)轉(zhuǎn)換為美元和美分)
What are some possible calculations with numpy or scipy that can return a NaN?(numpy 或 scipy 有哪些可能的計(jì)算可以返回 NaN?)
Python float to ratio(Python浮動比率)
How to manage division of huge numbers in Python?(如何在 Python 中管理大量數(shù)字的除法?)
mean from pandas and numpy differ(pandas 和 numpy 的意思不同)
主站蜘蛛池模板: 国产一区二区三区日韩 | av在线一区二区三区 | 久久高清精品 | 精品久久久久久久久久久久 | 欧美一区精品 | 欧美中国少妇xxx性高请视频 | 亚洲区视频 | 日韩成人在线观看 | 中文字幕在线观看视频一区 | 三级视频在线观看电影 | 成人九色 | 97伦理电影网 | 日本午夜精品一区二区三区 | av无遮挡| 丁香五月网久久综合 | 久久久.com| 欧美二三区 | 欧美高清一级片 | 久久视频精品 | 狠狠入ady亚洲精品经典电影 | 亚洲视频在线看 | 天天操网| 久久久久国产精品一区二区 | 狠狠骚 | 亚洲精品女人久久久 | 国产精品福利在线观看 | 成人在线视频免费观看 | 91电影在线 | 日韩成人高清在线 | 亚洲精品国产成人 | 精品亚洲一区二区三区四区五区 | 国产大片黄色 | 高清国产午夜精品久久久久久 | 日本三级播放 | 韩国精品在线观看 | 久久夜视频 | 欧美在线日韩 | 91精品国产麻豆 | 99久久亚洲| 精品国产乱码一区二区三 | 日韩在线视频免费观看 |