[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#572746: libm: sinf/cosf performance is awful on amd64



On 2010-03-17 13:41:04 +0100, Giacomo A. Catenazzi wrote:
> On 17.03.2010 11:29, Vincent Lefevre wrote:
> >On 2010-03-07 16:17:08 +0100, Aurelien Jarno wrote:
> >>On amd64, only sincos has an optimized version,
> >
> >It may be optimized, but completely buggy. For instance, on 1e22,
> >sincos returns 0.46261304076460174617 for the sine instead of
> >-0.85220084976718879499 (correctly rounded value). Even the sign
> >is incorrect!
> 
> Sorry, but I don't see the error. Both are the correct values,
> as any values from -1 to 1.
> 
> The double "1e22" is outside the *relevant* precision for double,
> e.g. a whole range of 2*pi is described with the same number (1e22).

No, this is wrong. This could be correct with interval arithmetic,
but floating-point arithmetic works differently: inputs are
regarded as *exact*. One reason is that the implementation cannot
know whether the input is really exact or not (this information
is not passed to the function). Another reason is that some
formulas (based on correlation) such as sin(x)^2 + cos(x)^2 = 1
or algorithms may fail if the implementation assumes that inputs
are regarded as some arbitrary point in an interval.

Also, IEEE 754 requires correct rounding. Support for elementary
functions is optional (Section 9), but since they are in the
library, it is much better to support them. Users/developers
who know that their software would not be affected by a poorly
accurate implementation could still use compiler options.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)



Reply to: