看板 Python 關於我們 聯絡資訊
一般來說用math.log2(數字)就能取對數 但是數字太大好像就不太準 像是2**87-1 會出現87 正確來說應該是86.多吧 請問有什麼解決方法呢? 感謝大大 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.141.88.170 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1589858663.A.325.html
pmove: 要絕對準的話,就是要自己寫? 05/19 12:22
GeoMeTric: decimal module 05/19 13:47
kenduest: decimal 內沒看到 log2(), 但是有log10() ,轉一下 05/19 14:25
kenduest: from decimal import Decimal, getcontext 05/19 14:25
kenduest: getcontext().prec = 30 05/19 14:25
kenduest: r = Decimal(2**87-1).log10() / Decimal(2).log10() 05/19 14:26
kenduest: r 應該就是你要的? 05/19 14:26
s90104123: 感謝樓上的各位 05/19 18:00