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: [PATCH] math/libm-test.inc: Fix cos and sincos tests against zero.


On Tuesday, April 09, 2013 14:32:29 Carlos O'Donell wrote:
> Andreas, Joseph,
> 
> This is a precursor to my cleanup of the definition of ulp in the math
> test suite. This patch brings two tests to 1/2 ulp for x86-64 and
> x86, otherwise when I turn on precise ulp calculations these tests
> show up as errors. The problem here is independent of the definition
> of ulp.
> 
> The value of PI is never exactly PI in any floating point
> representation, and the value of PI/2 is never PI/2. It is wrong to
> expect cos(M_PI_2l) to return 0, instead it will return an answer
> that is  non-zero because M_PI_2l doesn't round to 0 in the type
> used.
> 
> That is to say that the correct answer is to do the following:
> * Take PI or PI/2.
> * Round to the floating point representation.
> * Take the rounded value and compute an infinite precision cos or sin.
> * Use the rounded result of the infinite precision cos or sin as the
> answer.
> 
> I used printf to do the type rounding e.g.
> printf ("%e, %.100e, %a\n", (float)(2.0L*M_PIl), (float)(2.0L*M_PIl),
> (float)(2.0L*M_PIl)); printf ("%e, %.100e, %a\n",
> (double)(2.0L*M_PIl), (double)(2.0L*M_PIl), (double)(2.0L*M_PIl));
> printf ("%Le, %.100Le, %La\n", (long double)(2.0L*M_PIl), (long
> double)(2.0L*M_PIl), (long double)(2.0L*M_PIl)); printf ("%e, %.100e,
> %a\n", (float)(M_El), (float)(M_El), (float)(M_El)); printf ("%e,
> %.100e, %a\n", (double)(M_El), (double)(M_El), (double)(M_El));
> printf ("%Le, %.100Le, %La\n", (long double)(M_El), (long
> double)(M_El), (long double)(M_El));
> 
> Then I used Wolfram's Alpha here to get an infinite precision sin/cos.
> http://www.wolframalpha.com/
> 
> The following changes bring x86-64 and x86 to 1/2 ulp for two tests.
> It shows that the x86 cos implementation is quite good, and that
> our test are flawed.
> 
> Unfortunately given that the rounding errors are type dependent we
> need to fix this for each type. No regressions on x86-64 or x86.

So, you need to fix this also for each long double variant as Andreas 
Schwab and you discussed elsewhere.

> Is this the right way forward, even if it is logically the correct
> answer? I would say yes. I would say the test suite as it is right
> now is testing against the "naive" expected result. It works because
> ulp(0) for the testsuite is a huge value that allows all sorts of
> inaccurate zero values.
> 
> Comments?

Thanks a lot for digging into this, I agree with your analysis and think 
this is fine,

Andreas
-- 
 Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
    GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126


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