ReactOS 0.4.15-dev-8349-g6f277e9
tanf.c File Reference
#include "libm.h"
#include "libm_util.h"
#include "libm_inlines.h"
#include "libm_errno.h"
Include dependency graph for tanf.c:

Go to the source code of this file.

Macros

#define USE_REMAINDER_PIBY2F_INLINE
 
#define USE_VALF_WITH_FLAGS
 
#define USE_NANF_WITH_FLAGS
 
#define USE_HANDLE_ERRORF
 

Functions

static double tanf_piby4 (double x, int recip)
 
float tanf (float x)
 

Macro Definition Documentation

◆ USE_HANDLE_ERRORF

#define USE_HANDLE_ERRORF

Definition at line 33 of file tanf.c.

◆ USE_NANF_WITH_FLAGS

#define USE_NANF_WITH_FLAGS

Definition at line 32 of file tanf.c.

◆ USE_REMAINDER_PIBY2F_INLINE

#define USE_REMAINDER_PIBY2F_INLINE

Definition at line 30 of file tanf.c.

◆ USE_VALF_WITH_FLAGS

#define USE_VALF_WITH_FLAGS

Definition at line 31 of file tanf.c.

Function Documentation

◆ tanf()

float tanf ( float  x)

Definition at line 72 of file tanf.c.

73{
74 double r, dx;
75 int region, xneg;
76
77 unsigned long long ux, ax;
78
79 dx = x;
80
81 GET_BITS_DP64(dx, ux);
82 ax = (ux & ~SIGNBIT_DP64);
83
84 if (ax <= 0x3fe921fb54442d18) /* abs(x) <= pi/4 */
85 {
86 if (ax < 0x3f80000000000000) /* abs(x) < 2.0^(-7) */
87 {
88 if (ax < 0x3f20000000000000) /* abs(x) < 2.0^(-13) */
89 {
90 if (ax == 0x0000000000000000)
91 return x;
92 else
93 return valf_with_flags(x, AMD_F_INEXACT);
94 }
95 else
96 return (float)(dx + dx*dx*dx*0.333333333333333333);
97 }
98 else
99 return (float)tanf_piby4(x, 0);
100 }
101 else if ((ux & EXPBITS_DP64) == EXPBITS_DP64)
102 {
103 /* x is either NaN or infinity */
104 if (ux & MANTBITS_DP64)
105 {
106 /* x is NaN */
107 unsigned int ufx;
108 GET_BITS_SP32(x, ufx);
109 return _handle_errorf("tanf", OP_TAN, ufx|0x00400000, _DOMAIN, 0,
110 EDOM, x, 0.0F, 1);
111 }
112 else
113 {
114 /* x is infinity. Return a NaN */
115 return _handle_errorf("tanf", OP_TAN, INDEFBITPATT_SP32, _DOMAIN, AMD_F_INVALID,
116 EDOM, x, 0.0F, 1);
117 }
118 }
119
120 xneg = (int)(ux >> 63);
121
122 if (xneg)
123 dx = -dx;
124
125 if (dx < 5.0e5)
126 {
127 /* For these size arguments we can just carefully subtract the
128 appropriate multiple of pi/2, using extra precision where
129 dx is close to an exact multiple of pi/2 */
130 static const double
131 twobypi = 6.36619772367581382433e-01, /* 0x3fe45f306dc9c883 */
132 piby2_1 = 1.57079632673412561417e+00, /* 0x3ff921fb54400000 */
133 piby2_1tail = 6.07710050650619224932e-11, /* 0x3dd0b4611a626331 */
134 piby2_2 = 6.07710050630396597660e-11, /* 0x3dd0b4611a600000 */
135 piby2_2tail = 2.02226624879595063154e-21, /* 0x3ba3198a2e037073 */
136 piby2_3 = 2.02226624871116645580e-21, /* 0x3ba3198a2e000000 */
137 piby2_3tail = 8.47842766036889956997e-32; /* 0x397b839a252049c1 */
138 double t, rhead, rtail;
139 int npi2;
140 unsigned long long uy, xexp, expdiff;
141 xexp = ax >> EXPSHIFTBITS_DP64;
142 /* How many pi/2 is dx a multiple of? */
143 if (ax <= 0x400f6a7a2955385e) /* 5pi/4 */
144 {
145 if (ax <= 0x4002d97c7f3321d2) /* 3pi/4 */
146 npi2 = 1;
147 else
148 npi2 = 2;
149 }
150 else if (ax <= 0x401c463abeccb2bb) /* 9pi/4 */
151 {
152 if (ax <= 0x4015fdbbe9bba775) /* 7pi/4 */
153 npi2 = 3;
154 else
155 npi2 = 4;
156 }
157 else
158 npi2 = (int)(dx * twobypi + 0.5);
159 /* Subtract the multiple from dx to get an extra-precision remainder */
160 rhead = dx - npi2 * piby2_1;
161 rtail = npi2 * piby2_1tail;
162 GET_BITS_DP64(rhead, uy);
163 expdiff = xexp - ((uy & EXPBITS_DP64) >> EXPSHIFTBITS_DP64);
164 if (expdiff > 15)
165 {
166 /* The remainder is pretty small compared with dx, which
167 implies that dx is a near multiple of pi/2
168 (dx matches the multiple to at least 15 bits) */
169 t = rhead;
170 rtail = npi2 * piby2_2;
171 rhead = t - rtail;
172 rtail = npi2 * piby2_2tail - ((t - rhead) - rtail);
173 if (expdiff > 48)
174 {
175 /* dx matches a pi/2 multiple to at least 48 bits */
176 t = rhead;
177 rtail = npi2 * piby2_3;
178 rhead = t - rtail;
179 rtail = npi2 * piby2_3tail - ((t - rhead) - rtail);
180 }
181 }
182 r = rhead - rtail;
183 region = npi2 & 3;
184 }
185 else
186 {
187 /* Reduce x into range [-pi/4,pi/4] */
188 __remainder_piby2f_inline(ax, &r, &region);
189 }
190
191 if (xneg)
192 return (float)-tanf_piby4(r, region & 1);
193 else
194 return (float)tanf_piby4(r, region & 1);
195}
float __cdecl _handle_errorf(char *fname, int opcode, unsigned long long value, int type, int flags, int error, float arg1, float arg2, int nargs)
Definition: _handle_error.c:56
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define EDOM
Definition: errno.h:39
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble GLdouble t
Definition: gl.h:2047
#define _DOMAIN
Definition: math.h:39
#define AMD_F_INEXACT
Definition: libm_new.h:82
#define AMD_F_INVALID
Definition: libm_new.h:86
static double tanf_piby4(double x, int recip)
Definition: tanf.c:51
#define INDEFBITPATT_SP32
Definition: libm_util.h:76
#define GET_BITS_SP32(x, ux)
Definition: libm_util.h:105
#define EXPSHIFTBITS_DP64
Definition: libm_util.h:56
#define GET_BITS_DP64(x, ux)
Definition: libm_util.h:118
#define EXPBITS_DP64
Definition: libm_util.h:45
#define MANTBITS_DP64
Definition: libm_util.h:46
GLint dx
Definition: linetemp.h:97
ecx edi movl ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx movl TEMP incl eax andl eax ecx incl ebx testl eax jnz xchgl ecx incl TEMP esp ecx subl ebx pushl ecx ecx edx ecx shrl ecx mm0 mm4 mm0 mm4 mm1 mm5 mm1 mm5 mm2 mm6 mm2 mm6 mm3 mm7 mm3 mm7 paddd mm0 paddd mm4 paddd mm0 paddd mm4 paddd mm0 paddd mm4 movq mm1 movq mm5 psrlq mm1 psrlq mm5 paddd mm0 paddd mm4 psrad mm0 psrad mm4 packssdw mm0 packssdw mm4 mm1 punpckldq mm0 pand mm1 pand mm0 por mm1 movq edi esi edx edi decl ecx jnz popl ecx andl ecx jecxz mm0 mm0 mm1 mm1 mm2 mm2 mm3 mm3 paddd mm0 paddd mm0 paddd mm0 movq mm1 psrlq mm1 paddd mm0 psrad mm0 packssdw mm0 movd eax movw ax
Definition: synth_sse3d.h:180

◆ tanf_piby4()

static double tanf_piby4 ( double  x,
int  recip 
)
inlinestatic

Definition at line 51 of file tanf.c.

52{
53 double r, t;
54
55 /* Core Remez [1,2] approximation to tan(x) on the
56 interval [0,pi/4]. */
57 r = x*x;
58 t = x + x*r*
59 (0.385296071263995406715129e0 -
60 0.172032480471481694693109e-1 * r) /
61 (0.115588821434688393452299e+1 +
62 (-0.51396505478854532132342e0 +
63 0.1844239256901656082986661e-1 * r) * r);
64
65 if (recip)
66 return -1.0 / t;
67 else
68 return t;
69}

Referenced by tanf().