4 ms·
> It fails for x-y when x and y are close. Subtraction is the easiest way to get big floating point errors. And note: addition might be subtraction, while subt
by dragontamer 6y ago
> It fails for x-y when x and y are close. Subtraction is the easiest way to get big floating point errors.
And note: addition might be subtraction, while subtraction might be addition.
Consider x=1.0 and y=-0.99999.
x + y = 0.00001
You did addition, but you got cancellation error. The only solution is to sort the numbers from largest to smallest dynamically during runtime.