Back to index

glibc  2.9
Defines | Functions | Variables
k_sincosl.c File Reference
#include "math.h"
#include "math_private.h"

Go to the source code of this file.

Defines

#define ONE   c[0]
#define SCOS1   c[1]
#define SCOS2   c[2]
#define SCOS3   c[3]
#define SCOS4   c[4]
#define SCOS5   c[5]
#define COS1   c[6]
#define COS2   c[7]
#define COS3   c[8]
#define COS4   c[9]
#define COS5   c[10]
#define COS6   c[11]
#define COS7   c[12]
#define COS8   c[13]
#define SSIN1   c[14]
#define SSIN2   c[15]
#define SSIN3   c[16]
#define SSIN4   c[17]
#define SSIN5   c[18]
#define SIN1   c[19]
#define SIN2   c[20]
#define SIN3   c[21]
#define SIN4   c[22]
#define SIN5   c[23]
#define SIN6   c[24]
#define SIN7   c[25]
#define SIN8   c[26]
#define SINCOSL_COS_HI   0
#define SINCOSL_COS_LO   1
#define SINCOSL_SIN_HI   2
#define SINCOSL_SIN_LO   3

Functions

void __kernel_sincosl (long double x, long double y, long double *sinx, long double *cosx, int iy)

Variables

static const long double c []
const long double __sincosl_table []

Define Documentation

#define COS1   c[6]
#define COS2   c[7]
#define COS3   c[8]
#define COS4   c[9]
#define COS5   c[10]
#define COS6   c[11]
#define COS7   c[12]
#define COS8   c[13]
#define ONE   c[0]
#define SCOS1   c[1]
#define SCOS2   c[2]
#define SCOS3   c[3]
#define SCOS4   c[4]
#define SCOS5   c[5]
#define SIN1   c[19]
#define SIN2   c[20]
#define SIN3   c[21]
#define SIN4   c[22]
#define SIN5   c[23]
#define SIN6   c[24]
#define SIN7   c[25]
#define SIN8   c[26]
#define SINCOSL_COS_HI   0

Definition at line 93 of file k_sincosl.c.

#define SINCOSL_COS_LO   1

Definition at line 94 of file k_sincosl.c.

#define SINCOSL_SIN_HI   2

Definition at line 95 of file k_sincosl.c.

#define SINCOSL_SIN_LO   3

Definition at line 96 of file k_sincosl.c.

#define SSIN1   c[14]
#define SSIN2   c[15]
#define SSIN3   c[16]
#define SSIN4   c[17]
#define SSIN5   c[18]

Function Documentation

void __kernel_sincosl ( long double  x,
long double  y,
long double *  sinx,
long double *  cosx,
int  iy 
)

Definition at line 100 of file k_sincosl.c.

{
  long double h, l, z, sin_l, cos_l_m1;
  int64_t ix;
  u_int32_t tix, hix, index;
  GET_LDOUBLE_MSW64 (ix, x);
  tix = ((u_int64_t)ix) >> 32;
  tix &= ~0x80000000;                     /* tix = |x|'s high 32 bits */
  if (tix < 0x3fc30000)                   /* |x| < 0.1484375 */
    {
      /* Argument is small enough to approximate it by a Chebyshev
        polynomial of degree 16(17).  */
      if (tix < 0x3c600000)        /* |x| < 2^-57 */
       if (!((int)x))                     /* generate inexact */
         {
           *sinx = x;
           *cosx = ONE;
           return;
         }
      z = x * x;
      *sinx = x + (x * (z*(SIN1+z*(SIN2+z*(SIN3+z*(SIN4+
                     z*(SIN5+z*(SIN6+z*(SIN7+z*SIN8)))))))));
      *cosx = ONE + (z*(COS1+z*(COS2+z*(COS3+z*(COS4+
                   z*(COS5+z*(COS6+z*(COS7+z*COS8))))))));
    }
  else
    {
      /* So that we don't have to use too large polynomial,  we find
        l and h such that x = l + h,  where fabsl(l) <= 1.0/256 with 83
        possible values for h.  We look up cosl(h) and sinl(h) in
        pre-computed tables,  compute cosl(l) and sinl(l) using a
        Chebyshev polynomial of degree 10(11) and compute
        sinl(h+l) = sinl(h)cosl(l) + cosl(h)sinl(l) and
        cosl(h+l) = cosl(h)cosl(l) - sinl(h)sinl(l).  */
      int six = tix;
      tix = ((six - 0x3ff00000) >> 4) + 0x3fff0000;
      index = 0x3ffe - (tix >> 16);
      hix = (tix + (0x200 << index)) & (0xfffffc00 << index);
      x = fabsl (x);
      switch (index)
       {
       case 0: index = ((45 << 10) + hix - 0x3ffe0000) >> 8; break;
       case 1: index = ((13 << 11) + hix - 0x3ffd0000) >> 9; break;
       default:
       case 2: index = (hix - 0x3ffc3000) >> 10; break;
       }
      hix = (hix << 4) & 0x3fffffff;
/*
    The following should work for double but generates the wrong index.
    For now the code above converts double to ieee extended to compute
    the index back to double for the h value. 
    

      index = 0x3fe - (tix >> 20);
      hix = (tix + (0x2000 << index)) & (0xffffc000 << index);
      x = fabsl (x);
      switch (index)
       {
       case 0: index = ((45 << 14) + hix - 0x3fe00000) >> 12; break;
       case 1: index = ((13 << 15) + hix - 0x3fd00000) >> 13; break;
       default:
       case 2: index = (hix - 0x3fc30000) >> 14; break;
       }
*/
      SET_LDOUBLE_WORDS64(h, ((u_int64_t)hix) << 32, 0);
      if (iy)
       l = y - (h - x);
      else
       l = x - h;
      z = l * l;
      sin_l = l*(ONE+z*(SSIN1+z*(SSIN2+z*(SSIN3+z*(SSIN4+z*SSIN5)))));
      cos_l_m1 = z*(SCOS1+z*(SCOS2+z*(SCOS3+z*(SCOS4+z*SCOS5))));
      z = __sincosl_table [index + SINCOSL_SIN_HI]
         + (__sincosl_table [index + SINCOSL_SIN_LO]
            + (__sincosl_table [index + SINCOSL_SIN_HI] * cos_l_m1)
            + (__sincosl_table [index + SINCOSL_COS_HI] * sin_l));
      *sinx = (ix < 0) ? -z : z;
      *cosx = __sincosl_table [index + SINCOSL_COS_HI]
             + (__sincosl_table [index + SINCOSL_COS_LO]
               - (__sincosl_table [index + SINCOSL_SIN_HI] * sin_l
                  - __sincosl_table [index + SINCOSL_COS_HI] * cos_l_m1));
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const long double __sincosl_table[]

Definition at line 29 of file t_sincosl.c.

const long double c[] [static]

Definition at line 24 of file k_sincosl.c.