> > s_sin.c normalizes the argument to [-pi/4, +pi/4].
> > This is how |x| <= pi/4 is tested:
> > 
> >     GET_HIGH_WORD(ix,x);
> >     ix &= 0x7fffffff;
> >     if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0);
> > 
> > Why is it done like that? Is it faster or more portable
> > or in any way better that comparing the value itself to M_PI_4?
> > (Or was it, in 1993?)
> 
> Hm, is 0x3fe921fb the nearest float <= pi/4?
> s_sinf.c uses 0x3f490fd8 for that test.

Yes.

#include <stdio.h>
#include <math.h>
#include "math_private.h"

int
main()
{
        double d = M_PI_4;
        double f = M_PI_4;
        int32_t i, j;

        GET_HIGH_WORD(i, d);
        GET_FLOAT_WORD(j, f);

        printf("double %f, high  word %#x\n", d, i);
        printf("float  %f, float word %#x\n", f, j);

        return 0;
}

This says

  double 0.785398, high  word 0x3fe921fb
  float  0.785398, float word 0x3f490fdb

In case of double, it's exactly 0x3fe921fb.
But why then does s_sinf.c use 0x3f490fd8 instead of 0x3f490fdb?

        Jan

Reply via email to