How can a small correction survive cancellation in a floating-point total?
fsum tracks multiple intermediate partial sums to reduce rounding error in a floating-point total.
Python example and interpretation
A unit adjustment between a 1e16 entry and its reversal should survive as one. More accurate summation cannot recover digits lost before ingestion.
import math
math.fsum([1e16,1.,-1e16])Result 1.0
中文
正负大数抵消时,怎样保住总和里的小项?
fsum 跟踪多个中间部分和,以降低浮点连续加法的舍入误差。
Python 算例与适用条件
一笔 1e16 与其反向冲销之间夹有 1,最终应剩 1。更准确的加法无法恢复输入在采集阶段已经丢掉的数字。
import math
math.fsum([1e16,1.,-1e16])结果 1.0