amath  1.8.5
Simple command line calculator
tan.c File Reference

Tangent function. More...

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

Go to the source code of this file.

Functions

double tan (double x)
 Tangent function. More...
 

Detailed Description

Tangent function.

Definition in file tan.c.

Function Documentation

◆ tan()

double tan ( double  x)

Tangent function.

Returns
Tangent 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 87 of file tan.c.

References __kernel_tan(), and rempio2().

Referenced by RealNumber::Tangent().

88 {
89  double y[2], z = 0.0;
90  int32_t n, ix;
91 
92  GET_HIGH_WORD(ix, x);
93  ix &= 0x7FFFFFFF;
94 
95  // |x| ~< pi/4
96  if (ix <= 0x3FE921FB)
97  {
98  return __kernel_tan(x, z, 1);
99  }
100 
101  // tan(Inf or NaN) is NaN
102  if (ix >= 0x7FF00000)
103  {
104  return NAN;
105  }
106 
107  // |x| ~< pi/4
108  n = rempio2(x, y);
109  return __kernel_tan(y[0], y[1], 1 - ((n & 1) << 1));
110 }
#define GET_HIGH_WORD(i, d)
Get the more significant 32 bit int from a double.
Definition: prim.h:167
#define NAN
Definition: mathr.h:53
int rempio2(double x, double *y)
Definition: remp2.c:104
double __kernel_tan(double x, double y, int iy)
Kernel tan function.
Definition: ktan.c:108
Here is the call graph for this function:
Here is the caller graph for this function: