1 | /* s_tanf.c -- float version of s_tan.c. |
2 | */ |
3 | |
4 | /* |
5 | * ==================================================== |
6 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
7 | * |
8 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
9 | * Permission to use, copy, modify, and distribute this |
10 | * software is freely granted, provided that this notice |
11 | * is preserved. |
12 | * ==================================================== |
13 | */ |
14 | |
15 | #if defined(LIBM_SCCS) && !defined(lint) |
16 | static char rcsid[] = "$NetBSD: s_tanf.c,v 1.4 1995/05/10 20:48:20 jtc Exp $" ; |
17 | #endif |
18 | |
19 | #include <errno.h> |
20 | #include <math.h> |
21 | #include <math_private.h> |
22 | #include <libm-alias-float.h> |
23 | #include "s_sincosf.h" |
24 | |
25 | /* Reduce range of X to a multiple of PI/2. The modulo result is between |
26 | -PI/4 and PI/4 and returned as a high part y[0] and a low part y[1]. |
27 | The low bit in the return value indicates the first or 2nd half of tanf. */ |
28 | static inline int32_t |
29 | rem_pio2f (float x, float *y) |
30 | { |
31 | double dx = x; |
32 | int n; |
33 | const sincos_t *p = &__sincosf_table[0]; |
34 | |
35 | if (__glibc_likely (abstop12 (x) < abstop12 (120.0f))) |
36 | dx = reduce_fast (dx, p, &n); |
37 | else |
38 | { |
39 | uint32_t xi = asuint (x); |
40 | int sign = xi >> 31; |
41 | |
42 | dx = reduce_large (xi, &n); |
43 | dx = sign ? -dx : dx; |
44 | } |
45 | |
46 | y[0] = dx; |
47 | y[1] = dx - y[0]; |
48 | return n; |
49 | } |
50 | |
51 | float __tanf(float x) |
52 | { |
53 | float y[2],z=0.0; |
54 | int32_t n, ix; |
55 | |
56 | GET_FLOAT_WORD(ix,x); |
57 | |
58 | /* |x| ~< pi/4 */ |
59 | ix &= 0x7fffffff; |
60 | if(ix <= 0x3f490fda) return __kernel_tanf(x,z,1); |
61 | |
62 | /* tan(Inf or NaN) is NaN */ |
63 | else if (ix>=0x7f800000) { |
64 | if (ix==0x7f800000) |
65 | __set_errno (EDOM); |
66 | return x-x; /* NaN */ |
67 | } |
68 | |
69 | /* argument reduction needed */ |
70 | else { |
71 | n = rem_pio2f(x,y); |
72 | return __kernel_tanf(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even |
73 | -1 -- n odd */ |
74 | } |
75 | } |
76 | libm_alias_float (__tan, tan) |
77 | |