Boost logo

Boost :

From: Guillaume Melquiond (gmelquio_at_[hidden])
Date: 2003-07-05 15:13:50


On Sat, 5 Jul 2003, Beman Dawes wrote:

> So where does that leave us? There must be some reason Gennadiy's code is
> producing results one or two epsilons greater than expected.

It's just because the testcases are wrong. For example, line 157, there
is:

    tmp = 11; tmp /= 10;
    BOOST_CHECK_CLOSE_SHOULD_PASS_N( (tmp*tmp-tmp), 11./100, 1+3 );

The test will pass only if the result is at most 2 ulps away. Is it
possible?

Let t be tmp and e? be error values (smaller than ulp/2).

rounded(rounded(t*t) - t)
  = ((t*t) * (1+e1) - t) * (1+e2)
  = t*t - t + t*t * (e1+e2+e1*e2) - t*e2

So how much is the relative error? For example, if e1=ulp/2 and e2=0, the
absolute error reaches t*t*ulp/2 = 0.605*ulp. So the relative error is
0.605*ulp / (11/100) = 5.5*ulp. The result may be 6 ulps away! (and maybe
more)

Thinking rounding errors just add themselves is a misunderstanding of
floating-point arithmetic (if it was that easy, interval arithmetic
wouldn't be useful).

Guillaume


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk