| OLD | NEW |
| 1 /* origin: FreeBSD /usr/src/lib/msun/src/s_ccoshf.c */ | 1 /* origin: FreeBSD /usr/src/lib/msun/src/s_ccoshf.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 cosine of a complex argument. See s_ccosh.c for details. | 28 * Hyperbolic cosine of a complex argument. See s_ccosh.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 ccoshf(float complex z) | 35 float complex ccoshf(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(coshf(x), x * y); | 50 return CMPLXF(coshf(x), x * y); |
| 52 » » if (ix < 0x41100000) /* small x: normal case */ | 51 if (ix < 0x41100000) /* small x: normal case */ |
| 53 » » » return CMPLXF(coshf(x) * cosf(y), sinhf(x) * sinf(y)); | 52 return CMPLXF(coshf(x) * cosf(y), sinhf(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(h * cosf(y), copysignf(h, x) * sinf(y)); | 58 return CMPLXF(h * cosf(y), copysignf(h, x) * 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), cimagf(z) * copysignf(1, x)); | 62 return CMPLXF(crealf(z), cimagf(z) * copysignf(1, x)); |
| 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 * h * cosf(y), h * sinf(y)); | 66 return CMPLXF(h * h * cosf(y), h * sinf(y)); |
| 68 » » } | 67 } |
| 69 » } | 68 } |
| 70 | 69 |
| 71 » if (ix == 0 && iy >= 0x7f800000) | 70 if (ix == 0 && iy >= 0x7f800000) |
| 72 » » return CMPLXF(y - y, copysignf(0, x * (y - y))); | 71 return CMPLXF(y - y, copysignf(0, x * (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 * x, copysignf(0, x) * y); | 75 return CMPLXF(x * x, copysignf(0, x) * y); |
| 77 » » return CMPLXF(x * x, copysignf(0, (x + x) * y)); | 76 return CMPLXF(x * x, copysignf(0, (x + x) * 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 * x) * cosf(y), x * sinf(y)); | 85 return CMPLXF((x * x) * cosf(y), x * 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 |