OLD | NEW |
1 /* origin: FreeBSD /usr/src/lib/msun/src/s_csinhf.c */ | 1 /* origin: FreeBSD /usr/src/lib/msun/src/s_csinhf.c */ |
2 /*- | 2 /*- |
3 * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl | 3 * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl |
4 * All rights reserved. | 4 * All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice unmodified, this list of conditions, and the following | 10 * notice unmodified, this list of conditions, and the following |
(...skipping 14 matching lines...) Expand all Loading... |
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 /* | 27 /* |
28 * Hyperbolic sine of a complex argument z. See s_csinh.c for details. | 28 * Hyperbolic sine of a complex argument z. See s_csinh.c for details. |
29 */ | 29 */ |
30 | 30 |
31 #include "libm.h" | 31 #include "libm.h" |
32 | 32 |
33 static const float huge = 0x1p127; | 33 static const float huge = 0x1p127; |
34 | 34 |
35 float complex csinhf(float complex z) | 35 float complex csinhf(float complex z) { |
36 { | 36 float x, y, h; |
37 » float x, y, h; | 37 int32_t hx, hy, ix, iy; |
38 » int32_t hx, hy, ix, iy; | |
39 | 38 |
40 » x = crealf(z); | 39 x = crealf(z); |
41 » y = cimagf(z); | 40 y = cimagf(z); |
42 | 41 |
43 » GET_FLOAT_WORD(hx, x); | 42 GET_FLOAT_WORD(hx, x); |
44 » GET_FLOAT_WORD(hy, y); | 43 GET_FLOAT_WORD(hy, y); |
45 | 44 |
46 » ix = 0x7fffffff & hx; | 45 ix = 0x7fffffff & hx; |
47 » iy = 0x7fffffff & hy; | 46 iy = 0x7fffffff & hy; |
48 | 47 |
49 » if (ix < 0x7f800000 && iy < 0x7f800000) { | 48 if (ix < 0x7f800000 && iy < 0x7f800000) { |
50 » » if (iy == 0) | 49 if (iy == 0) |
51 » » » return CMPLXF(sinhf(x), y); | 50 return CMPLXF(sinhf(x), y); |
52 » » if (ix < 0x41100000) /* small x: normal case */ | 51 if (ix < 0x41100000) /* small x: normal case */ |
53 » » » return CMPLXF(sinhf(x) * cosf(y), coshf(x) * sinf(y)); | 52 return CMPLXF(sinhf(x) * cosf(y), coshf(x) * sinf(y)); |
54 | 53 |
55 » » /* |x| >= 9, so cosh(x) ~= exp(|x|) */ | 54 /* |x| >= 9, so cosh(x) ~= exp(|x|) */ |
56 » » if (ix < 0x42b17218) { | 55 if (ix < 0x42b17218) { |
57 » » » /* x < 88.7: expf(|x|) won't overflow */ | 56 /* x < 88.7: expf(|x|) won't overflow */ |
58 » » » h = expf(fabsf(x)) * 0.5f; | 57 h = expf(fabsf(x)) * 0.5f; |
59 » » » return CMPLXF(copysignf(h, x) * cosf(y), h * sinf(y)); | 58 return CMPLXF(copysignf(h, x) * cosf(y), h * sinf(y)); |
60 » » } else if (ix < 0x4340b1e7) { | 59 } else if (ix < 0x4340b1e7) { |
61 » » » /* x < 192.7: scale to avoid overflow */ | 60 /* x < 192.7: scale to avoid overflow */ |
62 » » » z = __ldexp_cexpf(CMPLXF(fabsf(x), y), -1); | 61 z = __ldexp_cexpf(CMPLXF(fabsf(x), y), -1); |
63 » » » return CMPLXF(crealf(z) * copysignf(1, x), cimagf(z)); | 62 return CMPLXF(crealf(z) * copysignf(1, x), cimagf(z)); |
64 » » } else { | 63 } else { |
65 » » » /* x >= 192.7: the result always overflows */ | 64 /* x >= 192.7: the result always overflows */ |
66 » » » h = huge * x; | 65 h = huge * x; |
67 » » » return CMPLXF(h * cosf(y), h * h * sinf(y)); | 66 return CMPLXF(h * cosf(y), h * h * sinf(y)); |
68 » » } | 67 } |
69 » } | 68 } |
70 | 69 |
71 » if (ix == 0 && iy >= 0x7f800000) | 70 if (ix == 0 && iy >= 0x7f800000) |
72 » » return CMPLXF(copysignf(0, x * (y - y)), y - y); | 71 return CMPLXF(copysignf(0, x * (y - y)), y - y); |
73 | 72 |
74 » if (iy == 0 && ix >= 0x7f800000) { | 73 if (iy == 0 && ix >= 0x7f800000) { |
75 » » if ((hx & 0x7fffff) == 0) | 74 if ((hx & 0x7fffff) == 0) |
76 » » » return CMPLXF(x, y); | 75 return CMPLXF(x, y); |
77 » » return CMPLXF(x, copysignf(0, y)); | 76 return CMPLXF(x, copysignf(0, y)); |
78 » } | 77 } |
79 | 78 |
80 » if (ix < 0x7f800000 && iy >= 0x7f800000) | 79 if (ix < 0x7f800000 && iy >= 0x7f800000) |
81 » » return CMPLXF(y - y, x * (y - y)); | 80 return CMPLXF(y - y, x * (y - y)); |
82 | 81 |
83 » if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) { | 82 if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) { |
84 » » if (iy >= 0x7f800000) | 83 if (iy >= 0x7f800000) |
85 » » » return CMPLXF(x * x, x * (y - y)); | 84 return CMPLXF(x * x, x * (y - y)); |
86 » » return CMPLXF(x * cosf(y), INFINITY * sinf(y)); | 85 return CMPLXF(x * cosf(y), INFINITY * sinf(y)); |
87 » } | 86 } |
88 | 87 |
89 » return CMPLXF((x * x) * (y - y), (x + x) * (y - y)); | 88 return CMPLXF((x * x) * (y - y), (x + x) * (y - y)); |
90 } | 89 } |
OLD | NEW |