Sine and Cosine Accuracy

Menezes, Evandro evandro.menezes@amd.com
Sat May 28 04:32:00 GMT 2005


Scott, 

> Actually, it tested every 1.8°, but who wants to be picky. 
> I've rerun the test overnight at greater resolution, testing every
> 0.00000018 degress, and saw no change in the result.

That's because the error is the same but symmetrical for sin and cos, so that, when you calculate the sum of their squares, one cancels the other out.

The lack of accuracy in x87 is well known: see http://www.gnu.org/software/libc/manual/html_node/Errors-in-Math-Functions.html#Errors-in-Math-Functions.

I modified your test slightly to return the number of error bits.  My results using GCC 4.0.0 on an Opteron system running SUSE 9.1 were:

x87sincos-32-fst
cumulative error: 4 (ulp)
                 -5.10702591327572e-15 (decimal)
x87sincos-32-sse
cumulative error: 4 (ulp)
                 -5.10702591327572e-15 (decimal)
x87sincos-32-x87
cumulative error: 2 (ulp)
                  -1.4432899320127e-15 (decimal)
x87sincos-64-sse
cumulative error: 4 (ulp)
                 -4.77395900588817e-15 (decimal)
x87sincos-64-x87
cumulative error: 2 (ulp)
                 -1.22124532708767e-15 (decimal)

On an Athlon MP system running SUSE 9.1:

x87sincos-32-fst
cumulative error: 4 (ulp)
                 -5.10702591327572e-15 (decimal)
x87sincos-32-x87
cumulative error: 2 (ulp)
                  -1.4432899320127e-15 (decimal)

Now, adding -funsafe-math-optimizations, on the same systems:

x87sincos-32-fst
cumulative error: 4 (ulp)
                 -5.10702591327572e-15 (decimal)
x87sincos-32-sse
cumulative error: 4 (ulp)
                 -5.10702591327572e-15 (decimal)
x87sincos-32-x87
cumulative error: 0 (ulp)
                                    +0 (decimal)
x87sincos-64-sse
cumulative error: 4 (ulp)
                 -4.77395900588817e-15 (decimal)
x87sincos-64-x87
cumulative error: 0 (ulp)
                                    +0 (decimal)
And:

x87sincos-32-fst
cumulative error: 4 (ulp)
                 -5.10702591327572e-15 (decimal)
x87sincos-32-x87
cumulative error: 0 (ulp)
                                    +0 (decimal)

Any perceived increase in accuracy in this test comes from intermediary calculations being done with 80 bits and because the errors in fsin are complementary to those in fcos.

HTH


-- 
_______________________________________________________
Evandro Menezes            AMD               Austin, TX
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unsafe.tar.bz2
Type: application/octet-stream
Size: 1227 bytes
Desc: unsafe.tar.bz2
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20050528/9c7940f1/attachment.obj>


More information about the Gcc mailing list