Can anyone recommend any C++ libraries/routines/packages that contain strategies for maintaining the stability of various floating point operations?
Example: suppose you would like to sum across a vector/array of one million long double
in the unit interval (0,1), and that each number is of about the same order of magnitude. Naively summing for (int i=0;i<1000000;++i) sum += array[i];
is unreliable - for large enough i
, sum
will be of a much larger order of magnitude than array[i]
, and so sum += array[i]
would be equivalent to sum += 0.00
.
(Note: the solution to this example is a binary summing strategy.)
I deal with sums and products of thousands/millions of miniscule probabilities. I am using the arbitrary-precision library MPFRC++
with a 2048 bit significand, but the same concerns still apply.
I am chiefly concerned with:
- Strategies for accurately summing many numbers (e.g. above Example).
- When is multiplication and division potentially unstable? (If I want to normalize a large array of numbers, what should my normalization constant be? The smallest value? The largest? A median?)