| OLD | NEW |
| 1 /* origin: FreeBSD /usr/src/lib/msun/src/s_sin.c */ | 1 /* origin: FreeBSD /usr/src/lib/msun/src/s_sin.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 24 matching lines...) Expand all Loading... |
| 35 * Let trig be any of sin, cos, or tan. | 35 * Let trig be any of sin, cos, or tan. |
| 36 * trig(+-INF) is NaN, with signals; | 36 * trig(+-INF) is NaN, with signals; |
| 37 * trig(NaN) is that NaN; | 37 * trig(NaN) is that NaN; |
| 38 * | 38 * |
| 39 * Accuracy: | 39 * Accuracy: |
| 40 * TRIG(x) returns trig(x) nearly rounded | 40 * TRIG(x) returns trig(x) nearly rounded |
| 41 */ | 41 */ |
| 42 | 42 |
| 43 #include "libm.h" | 43 #include "libm.h" |
| 44 | 44 |
| 45 double sin(double x) | 45 double sin(double x) { |
| 46 { | 46 double y[2]; |
| 47 » double y[2]; | 47 uint32_t ix; |
| 48 » uint32_t ix; | 48 unsigned n; |
| 49 » unsigned n; | |
| 50 | 49 |
| 51 » /* High word of x. */ | 50 /* High word of x. */ |
| 52 » GET_HIGH_WORD(ix, x); | 51 GET_HIGH_WORD(ix, x); |
| 53 » ix &= 0x7fffffff; | 52 ix &= 0x7fffffff; |
| 54 | 53 |
| 55 » /* |x| ~< pi/4 */ | 54 /* |x| ~< pi/4 */ |
| 56 » if (ix <= 0x3fe921fb) { | 55 if (ix <= 0x3fe921fb) { |
| 57 » » if (ix < 0x3e500000) { /* |x| < 2**-26 */ | 56 if (ix < 0x3e500000) { /* |x| < 2**-26 */ |
| 58 » » » /* raise inexact if x != 0 and underflow if subnormal*/ | 57 /* raise inexact if x != 0 and underflow if subnormal*/ |
| 59 » » » FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f); | 58 FORCE_EVAL(ix < 0x00100000 ? x / 0x1p120f : x + 0x1p120f); |
| 60 » » » return x; | 59 return x; |
| 61 » » } | 60 } |
| 62 » » return __sin(x, 0.0, 0); | 61 return __sin(x, 0.0, 0); |
| 63 » } | 62 } |
| 64 | 63 |
| 65 » /* sin(Inf or NaN) is NaN */ | 64 /* sin(Inf or NaN) is NaN */ |
| 66 » if (ix >= 0x7ff00000) | 65 if (ix >= 0x7ff00000) |
| 67 » » return x - x; | 66 return x - x; |
| 68 | 67 |
| 69 » /* argument reduction needed */ | 68 /* argument reduction needed */ |
| 70 » n = __rem_pio2(x, y); | 69 n = __rem_pio2(x, y); |
| 71 » switch (n&3) { | 70 switch (n & 3) { |
| 72 » case 0: return __sin(y[0], y[1], 1); | 71 case 0: |
| 73 » case 1: return __cos(y[0], y[1]); | 72 return __sin(y[0], y[1], 1); |
| 74 » case 2: return -__sin(y[0], y[1], 1); | 73 case 1: |
| 75 » default: | 74 return __cos(y[0], y[1]); |
| 76 » » return -__cos(y[0], y[1]); | 75 case 2: |
| 77 » } | 76 return -__sin(y[0], y[1], 1); |
| 77 default: |
| 78 return -__cos(y[0], y[1]); |
| 79 } |
| 78 } | 80 } |
| OLD | NEW |