amath  1.8.5
Simple command line calculator
sin.c File Reference

Sine function. More...

#include "prim.h"
Include dependency graph for sin.c:

Go to the source code of this file.

Functions

double sin (double x)
 Sine function. More...
 

Detailed Description

Sine function.

Definition in file sin.c.

Function Documentation

◆ sin()

double sin ( double  x)

Sine function.

Returns
Sine function of x
Kernel function:
__kernel_sin        ... sine function on [-pi/4,pi/4]
__kernel_cos        ... cose function on [-pi/4,pi/4]
__ieee754_rem_pio2  ... argument reduction routine
Method:
Let S,C and T denote the sin, cos and tan respectively on
[-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
in [-pi/4 , +pi/4], and let n = k mod 4.

We have

     n        sin(x)      cos(x)        tan(x)
----------------------------------------------------------
     0          S           C             T
     1          C          -S           -1/T
     2         -S          -C             T
     3         -C           S           -1/T
----------------------------------------------------------
Special cases:
Let trig be any of sin, cos, or tan.
trig(+-INF)  is NaN
trig(NaN)    is that NaN
Accuracy:
TRIG(x) returns trig(x) nearly rounded

Definition at line 86 of file sin.c.

References __kernel_cos(), __kernel_sin(), and rempio2().

Referenced by ccos(), ccosh(), ccot(), ccoth(), ccsc(), ccsch(), cexp(), cot(), cpow(), crd(), csc(), csec(), csech(), csin(), csinh(), ctan(), ctanh(), cvc(), cvs(), hcc(), hcv(), RealNumber::Sine(), and ver().

87 {
88  double y[2], z = 0.0;
89  int32_t n, ix;
90 
91  GET_HIGH_WORD(ix, x);
92  ix &= 0x7FFFFFFF;
93 
94  // |x| ~< pi/4
95  if (ix <= 0x3FE921FB)
96  {
97  return __kernel_sin(x, z, 0);
98  }
99 
100  // sin(Inf or NaN) is NaN
101  if (ix >= 0x7FF00000)
102  {
103  return NAN;
104  }
105 
106  // argument reduction needed
107  n = rempio2(x, y);
108  switch (n & 3)
109  {
110  case 0:
111  return __kernel_sin(y[0], y[1], 1);
112  case 1:
113  return __kernel_cos(y[0], y[1]);
114  case 2:
115  return -__kernel_sin(y[0], y[1], 1);
116  default:
117  return -__kernel_cos(y[0], y[1]);
118  }
119 }
#define GET_HIGH_WORD(i, d)
Get the more significant 32 bit int from a double.
Definition: prim.h:167
double __kernel_cos(double x, double y)
Kernel cosine function.
Definition: kcos.c:94
#define NAN
Definition: mathr.h:53
int rempio2(double x, double *y)
Definition: remp2.c:104
double __kernel_sin(double x, double y, int iy)
Kernel sin function.
Definition: ksin.c:89
Here is the call graph for this function:
Here is the caller graph for this function: