OLD | NEW |
1 /* origin: FreeBSD /usr/src/lib/msun/src/s_tan.c */ | 1 /* origin: FreeBSD /usr/src/lib/msun/src/s_tan.c */ |
2 /* | 2 /* |
3 * ==================================================== | 3 * ==================================================== |
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | 4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
5 * | 5 * |
6 * Developed at SunPro, a Sun Microsystems, Inc. business. | 6 * Developed at SunPro, a Sun Microsystems, Inc. business. |
7 * Permission to use, copy, modify, and distribute this | 7 * Permission to use, copy, modify, and distribute this |
8 * software is freely granted, provided that this notice | 8 * software is freely granted, provided that this notice |
9 * is preserved. | 9 * is preserved. |
10 * ==================================================== | 10 * ==================================================== |
(...skipping 23 matching lines...) Expand all Loading... |
34 * Let trig be any of sin, cos, or tan. | 34 * Let trig be any of sin, cos, or tan. |
35 * trig(+-INF) is NaN, with signals; | 35 * trig(+-INF) is NaN, with signals; |
36 * trig(NaN) is that NaN; | 36 * trig(NaN) is that NaN; |
37 * | 37 * |
38 * Accuracy: | 38 * Accuracy: |
39 * TRIG(x) returns trig(x) nearly rounded | 39 * TRIG(x) returns trig(x) nearly rounded |
40 */ | 40 */ |
41 | 41 |
42 #include "libm.h" | 42 #include "libm.h" |
43 | 43 |
44 double tan(double x) | 44 double tan(double x) { |
45 { | 45 double y[2]; |
46 » double y[2]; | 46 uint32_t ix; |
47 » uint32_t ix; | 47 unsigned n; |
48 » unsigned n; | |
49 | 48 |
50 » GET_HIGH_WORD(ix, x); | 49 GET_HIGH_WORD(ix, x); |
51 » ix &= 0x7fffffff; | 50 ix &= 0x7fffffff; |
52 | 51 |
53 » /* |x| ~< pi/4 */ | 52 /* |x| ~< pi/4 */ |
54 » if (ix <= 0x3fe921fb) { | 53 if (ix <= 0x3fe921fb) { |
55 » » if (ix < 0x3e400000) { /* |x| < 2**-27 */ | 54 if (ix < 0x3e400000) { /* |x| < 2**-27 */ |
56 » » » /* raise inexact if x!=0 and underflow if subnormal */ | 55 /* raise inexact if x!=0 and underflow if subnormal */ |
57 » » » FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f); | 56 FORCE_EVAL(ix < 0x00100000 ? x / 0x1p120f : x + 0x1p120f); |
58 » » » return x; | 57 return x; |
59 » » } | 58 } |
60 » » return __tan(x, 0.0, 0); | 59 return __tan(x, 0.0, 0); |
61 » } | 60 } |
62 | 61 |
63 » /* tan(Inf or NaN) is NaN */ | 62 /* tan(Inf or NaN) is NaN */ |
64 » if (ix >= 0x7ff00000) | 63 if (ix >= 0x7ff00000) |
65 » » return x - x; | 64 return x - x; |
66 | 65 |
67 » /* argument reduction */ | 66 /* argument reduction */ |
68 » n = __rem_pio2(x, y); | 67 n = __rem_pio2(x, y); |
69 » return __tan(y[0], y[1], n&1); | 68 return __tan(y[0], y[1], n & 1); |
70 } | 69 } |
OLD | NEW |