Back to index

glibc  2.9
Defines | Functions | Variables
k_cosl.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 SINCOSL_COS_HI   0
#define SINCOSL_COS_LO   1
#define SINCOSL_SIN_HI   2
#define SINCOSL_SIN_LO   3

Functions

long double __kernel_cosl (long double x, long double y)

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 SINCOSL_COS_HI   0

Definition at line 74 of file k_cosl.c.

#define SINCOSL_COS_LO   1

Definition at line 75 of file k_cosl.c.

#define SINCOSL_SIN_HI   2

Definition at line 76 of file k_cosl.c.

#define SINCOSL_SIN_LO   3

Definition at line 77 of file k_cosl.c.

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

Function Documentation

long double __kernel_cosl ( long double  x,
long double  y 
)

Definition at line 81 of file k_cosl.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.  */
      if (tix < 0x3c600000)        /* |x| < 2^-57 */
       if (!((int)x)) return ONE;  /* generate inexact */
      z = x * x;
      return 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
        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 + (0x200 << index)) & (0xfffffc00 << 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);
      l = y - (h - x);
      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))));
      return __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:


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_cosl.c.