用法:
math.fsum(iterable)
返回可迭代項中值的準確浮點總和。通過跟蹤多個中間部分和來避免精度損失:
>>> sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1]) 0.9999999999999999 >>> fsum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1]) 1.0
該算法的準確性取決於 IEEE-754 算術保證以及舍入模式為 half-even 的典型情況。在某些非 Windows 版本中,底層 C 庫使用擴展精度加法,並且可能偶爾會 double-round 是一個中間和,導致它的最低有效位關閉。
有關進一步的討論和兩種替代方法,請參閱用於準確浮點求和的 ASPN 食譜食譜.
相關用法
- Python math.fsum()用法及代碼示例
- Python math.fmod()用法及代碼示例
- Python math.factorial()用法及代碼示例
- Python math.fabs()用法及代碼示例
- Python math.frexp()用法及代碼示例
- Python math.floor()用法及代碼示例
- Python math.cos()用法及代碼示例
- Python math.cosh()用法及代碼示例
- Python math.acosh()用法及代碼示例
- Python math.remainder()用法及代碼示例
- Python math.asinh()用法及代碼示例
- Python math.prod()用法及代碼示例
- Python math.atanh()用法及代碼示例
- Python math.log1p()用法及代碼示例
- Python math.gcd()用法及代碼示例
- Python math.isqrt()用法及代碼示例
- Python math.erf用法及代碼示例
- Python math.ldexp()用法及代碼示例
- Python math.acos()用法及代碼示例
- Python math.sin()用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 math.fsum。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。