What is a good solution for calculating an average where the sum of all values exceeds a double's limits?

前端 未结 17 2201

I have a requirement to calculate the average of a very large set of doubles (10^9 values). The sum of the values exceeds the upper bound of a double, so does anyone know a

17条回答
  •  醉酒成梦
    2020-11-29 19:08

    Option 1 is to use an arbitrary-precision library so you don't have an upper-bound.

    Other options (which lose precision) are to sum in groups rather than all at once, or to divide before summing.

提交回复
热议问题