How best to sum up lots of floating point numbers?

前端 未结 5 1571
我寻月下人不归
我寻月下人不归 2020-11-28 22:11

Imagine you have a large array of floating point numbers, of all kinds of sizes. What is the most correct way to calculate the sum, with the least error? For example, when t

5条回答
  •  猫巷女王i
    2020-11-28 22:45

    For "more precise": this recipe in the Python Cookbook has summation algorithms which keep the full precision (by keeping track of the subtotals). Code is in Python but even if you don't know Python it's clear enough to adapt to any other language.

    All the details are given in this paper.

提交回复
热议问题