This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: correct rounding or not?


Hi Paul,

> for [1] I don't know what "it computes *the* rounded value of sin(x)" means.
> The header of the file says that the error is ~0.55ulp, that would be clearer.
> Maybe the original libultim source contained an error bound for the fast path,
> but unfortunately I do not have it any more.

Well we don't have good error bounds for sin/cos, the ULP estimates are based
on the original code with the slow paths.

> However, in revision e4d8276, I see the largest 'corr' factor is 1.07,
> which corresponds to a relative error of 0.07/2^55, thus to a maximum
> error of 0.5175 ulps. But maybe the code was changed since then.

__sin used to have this:

  else if (k < 0x3feb6000)
    {
      res = do_sin (x, 0, &cor);
      retval = (res == res + 1.096 * cor) ? res : slow1 (x);

>From this I estimated the worst-case ULP as < 0.55. It could well be a bit
better in reality.

> Note also that we can still find "correctly rounded" in e_atan2.c, s_atan.c,
> and s_tan.c.

Yes, those still have slow paths which give correctly rounded results.

> /tmp/mpcheck-double --num=14400000 --seed=1

That looks like a useful tool - we did something similar for random testing
using long double math to test double functions.

> Also, "make bench" on my machine gives the following results:

    function & fast path & slow path \\ \hline

    acos     & 168 & 160894 \\ % 235 after patch [2]
    asin     & 160 & 163083 \\ % 216 after patch [2]
    atan     & 127 & 29389 \\ % 144 bits
    sin      & 92 & 198 \\ % 768 bits
    cos      & 115 & 211 \\ % 768 bits
    tan      & 189 & 172531 \\ % 768 bits
    exp      & 25  & 26 \\ % 144 bits
    log      & 20  &    \\
    pow      & 35 & 67 \\ % 240 bits

> Note that atan and tan still have slow "slow paths".

Yes the 1000x slowdown to try to round correctly is completely ridiculous!

It's also interesting to see that the new exp/log worst case is 5x faster than
sin/cos fast case...

> Also I wonder, now that the "slow path" for asin takes only 216 cycles,
> whereas the fast path takes 160 cycles, what would you obtain if you use
> the slow path only?

The fast path is likely already more than accurate enough. It's unlikely to be
worth it though - rewriting these functions from scratch is the way forward.

Cheers,
Wilco

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]