[Haskell-cafe] rounding errors with real numbers.

Henning Thielemann lemming at henning-thielemann.de
Fri Mar 3 07:29:06 EST 2006


On Thu, 2 Mar 2006, Matthias Fischmann wrote:

> > cancellation happens for instance here: 1 + 1e-50 - 1 == 0
>
> the function again (in the wasteful original form, for clarity).
> where do you think cancellation may take place?  isn't what you call
> canellation a generic rounding error?

 Cancellation is a special kind of rounding error. Rounding errors appear
everywhere, in (*), sin, exp and so on, but cancellations only arise on
differences. They are especially bad, because as the example above shows,
even if all numbers are given in double precision in the computation
a+b-a, no digit of the result is correct, that is 100% rounding error! The
danger of cancellation is everywhere where you subtract numbers of similar
magnitude.
 In your example: If lower=-100000, upper=1, x approximately oldUpper then
you get the effect at the '+' in ((x - oldLower) * stretch + lower).



More information about the Haskell-Cafe mailing list