日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

为什么在python中整数的值没有限制_python-为什么math.log接受大整数值?

發布時間:2024/7/19 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 为什么在python中整数的值没有限制_python-为什么math.log接受大整数值? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我終于鉆入python math lib source code,發現了這一點:

/* A decent logarithm is easy to compute even for huge ints, but libm can't

do that by itself -- loghelper can. func is log or log10, and name is

"log" or "log10". Note that overflow of the result isn't possible: an int

can contain no more than INT_MAX * SHIFT bits, so has value certainly less

than 2**(2**64 * 2**16) == 2**2**80, and log2 of that is 2**80, which is

small enough to fit in an IEEE single. log and log10 are even smaller.

However, intermediate overflow is possible for an int if the number of bits

in that int is larger than PY_SSIZE_T_MAX. */

static PyObject*

loghelper(PyObject* arg, double (*func)(double), const char *funcname)

{

/* If it is int, do it ourselves. */

if (PyLong_Check(arg)) {

double x, result;

Py_ssize_t e;

...

我會保留其余的源代碼(檢查鏈接),但是據我了解,Python會檢查傳遞的參數是否為整數,如果是,則不要使用math lib(如果為int,自己做.)評論.另外:即使對于很大的整數,也很容易計算出不錯的對數,但是libm本身不能做到這一點-loghelper可以

如果是雙精度數,則調用本地數學庫.

從源注釋中可以看出,即使發生溢出,Python也會盡最大努力提供結果(此處轉換為兩次溢出,但仍可以計算日志.清除異常并繼續)

因此,由于使用了log函數的python包裝,Python能夠計算巨大整數的對數(特定于某些函數,因為sqrt等其他函數無法做到),并且已在文檔中進行了記載,但僅在源代碼中有記錄.正如Jon所暗示的那樣,使其成為實現細節.

總結

以上是生活随笔為你收集整理的为什么在python中整数的值没有限制_python-为什么math.log接受大整数值?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。