Re:Mean of two floating point numbers can be dangerous
by Scea91 on Sunday June 05, 2016 @12:43PM
(#11841771)
I think that it is necessary to make a compromise between absolute robustness and readability, maintainability etc.
I hope that the input to the program is sensible enough that floating point overflow won't be an issue, since there are more complicated formulas in the program than this simple one.
overflow breaks (x + y) / 2. where x and y are large underflow breaks (x / 2.) + (y / 2.) where x and y are small.
and of course the problem where x is outside the exponent of y. But one of these values gets treated as though it were insignificant and effectively 0.