This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Fix sin, cos, tan in non-default rounding modes (bug 3976)
On Fri, 2012-03-02 at 19:15 +0100, Andreas Jaeger wrote:
> On 03/02/2012 06:39 PM, Joseph S. Myers wrote:
> > Similar to the patch for exp, this patch fixes problems with sin, cos
> > and tan producing wild results in non-default rounding modes by making
> > them save and restore the rounding mode and do computations in
> > round-to-nearest.
> >
> > Tested on x86_64 and x86 and ULPs updated based on those tests.
> >
> > 2012-03-02 Joseph Myers<joseph@codesourcery.com>
> >
> > [BZ #3976]
> > * sysdeps/ieee754/dbl-64/s_sin.c: Include<fenv.h>
> > (__sin): Save and restore rounding mode and use round-to-nearest
> > for all computations.
> > (__cos): Save and restore rounding mode and use round-to-nearest
> > for all computations.
> > * sysdeps/ieee754/dbl-64/s_tan.c: Include "math_private.h" and
> > <fenv.h>.
> > (tan): Save and restore rounding mode and use round-to-nearest for
> > all computations.
> > * math/libm-test.inc (cos_test_tonearest): New function.
> > (cos_test_towardzero): Likewise.
> > (cos_test_downward): Likewise.
> > (cos_test_upward): Likewise.
> > (sin_test_tonearest): Likewise.
> > (sin_test_towardzero): Likewise.
> > (sin_test_downward): Likewise.
> > (sin_test_upward): Likewise.
> > (tan_test_tonearest): Likewise.
> > (tan_test_towardzero): Likewise.
> > (tan_test_downward): Likewise.
> > (tan_test_upward): Likewise.
> > (main): Call the new functions.
> > * sysdeps/i386/fpu/libm-test-ulps: Update.
> > * sysdeps/x86_64/fpu/libm-test-ulps: Likewise.
> > [...]
>
> thanks, this looks fine, I just have a few suggestions for minor nits below.
>
>
>
> > diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c
> > index 5b79854..32ba66d 100644
> > --- a/sysdeps/ieee754/dbl-64/s_sin.c
> > +++ b/sysdeps/ieee754/dbl-64/s_sin.c
> > @@ -53,6 +53,7 @@
> > #include "usncs.h"
> > #include "MathLib.h"
> > #include "math_private.h"
> > +#include<fenv.h>
> >
> > #ifndef SECTION
> > # define SECTION
> > @@ -107,12 +108,16 @@ __sin(double x){
> > #if 0
> > int4 nn;
> > #endif
> > + fenv_t env;
> > + double retval = 0;
> > +
> > + libc_feholdexcept_setround (&env, FE_TONEAREST);
> >
For Powerpc we will want to override these functions with inline
functions from math-private.h or fenv_libc.h.