s_ccosh.c (226599) | s_ccosh.c (275819) |
---|---|
1/*- 2 * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 21 unchanged lines hidden (view full) --- 30 * cosh(z) = cosh(x+iy) 31 * = cosh(x) cos(y) + i sinh(x) sin(y). 32 * 33 * Exceptional values are noted in the comments within the source code. 34 * These values and the return value were taken from n1124.pdf. 35 */ 36 37#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 21 unchanged lines hidden (view full) --- 30 * cosh(z) = cosh(x+iy) 31 * = cosh(x) cos(y) + i sinh(x) sin(y). 32 * 33 * Exceptional values are noted in the comments within the source code. 34 * These values and the return value were taken from n1124.pdf. 35 */ 36 37#include <sys/cdefs.h> |
38__FBSDID("$FreeBSD: head/lib/msun/src/s_ccosh.c 226599 2011-10-21 06:29:32Z das $"); | 38__FBSDID("$FreeBSD: head/lib/msun/src/s_ccosh.c 275819 2014-12-16 09:21:56Z ed $"); |
39 40#include <complex.h> 41#include <math.h> 42 43#include "math_private.h" 44 45static const double huge = 0x1p1023; 46 --- 10 unchanged lines hidden (view full) --- 57 EXTRACT_WORDS(hy, ly, y); 58 59 ix = 0x7fffffff & hx; 60 iy = 0x7fffffff & hy; 61 62 /* Handle the nearly-non-exceptional cases where x and y are finite. */ 63 if (ix < 0x7ff00000 && iy < 0x7ff00000) { 64 if ((iy | ly) == 0) | 39 40#include <complex.h> 41#include <math.h> 42 43#include "math_private.h" 44 45static const double huge = 0x1p1023; 46 --- 10 unchanged lines hidden (view full) --- 57 EXTRACT_WORDS(hy, ly, y); 58 59 ix = 0x7fffffff & hx; 60 iy = 0x7fffffff & hy; 61 62 /* Handle the nearly-non-exceptional cases where x and y are finite. */ 63 if (ix < 0x7ff00000 && iy < 0x7ff00000) { 64 if ((iy | ly) == 0) |
65 return (cpack(cosh(x), x * y)); | 65 return (CMPLX(cosh(x), x * y)); |
66 if (ix < 0x40360000) /* small x: normal case */ | 66 if (ix < 0x40360000) /* small x: normal case */ |
67 return (cpack(cosh(x) * cos(y), sinh(x) * sin(y))); | 67 return (CMPLX(cosh(x) * cos(y), sinh(x) * sin(y))); |
68 69 /* |x| >= 22, so cosh(x) ~= exp(|x|) */ 70 if (ix < 0x40862e42) { 71 /* x < 710: exp(|x|) won't overflow */ 72 h = exp(fabs(x)) * 0.5; | 68 69 /* |x| >= 22, so cosh(x) ~= exp(|x|) */ 70 if (ix < 0x40862e42) { 71 /* x < 710: exp(|x|) won't overflow */ 72 h = exp(fabs(x)) * 0.5; |
73 return (cpack(h * cos(y), copysign(h, x) * sin(y))); | 73 return (CMPLX(h * cos(y), copysign(h, x) * sin(y))); |
74 } else if (ix < 0x4096bbaa) { 75 /* x < 1455: scale to avoid overflow */ | 74 } else if (ix < 0x4096bbaa) { 75 /* x < 1455: scale to avoid overflow */ |
76 z = __ldexp_cexp(cpack(fabs(x), y), -1); 77 return (cpack(creal(z), cimag(z) * copysign(1, x))); | 76 z = __ldexp_cexp(CMPLX(fabs(x), y), -1); 77 return (CMPLX(creal(z), cimag(z) * copysign(1, x))); |
78 } else { 79 /* x >= 1455: the result always overflows */ 80 h = huge * x; | 78 } else { 79 /* x >= 1455: the result always overflows */ 80 h = huge * x; |
81 return (cpack(h * h * cos(y), h * sin(y))); | 81 return (CMPLX(h * h * cos(y), h * sin(y))); |
82 } 83 } 84 85 /* 86 * cosh(+-0 +- I Inf) = dNaN + I sign(d(+-0, dNaN))0. 87 * The sign of 0 in the result is unspecified. Choice = normally 88 * the same as dNaN. Raise the invalid floating-point exception. 89 * 90 * cosh(+-0 +- I NaN) = d(NaN) + I sign(d(+-0, NaN))0. 91 * The sign of 0 in the result is unspecified. Choice = normally 92 * the same as d(NaN). 93 */ 94 if ((ix | lx) == 0 && iy >= 0x7ff00000) | 82 } 83 } 84 85 /* 86 * cosh(+-0 +- I Inf) = dNaN + I sign(d(+-0, dNaN))0. 87 * The sign of 0 in the result is unspecified. Choice = normally 88 * the same as dNaN. Raise the invalid floating-point exception. 89 * 90 * cosh(+-0 +- I NaN) = d(NaN) + I sign(d(+-0, NaN))0. 91 * The sign of 0 in the result is unspecified. Choice = normally 92 * the same as d(NaN). 93 */ 94 if ((ix | lx) == 0 && iy >= 0x7ff00000) |
95 return (cpack(y - y, copysign(0, x * (y - y)))); | 95 return (CMPLX(y - y, copysign(0, x * (y - y)))); |
96 97 /* 98 * cosh(+-Inf +- I 0) = +Inf + I (+-)(+-)0. 99 * 100 * cosh(NaN +- I 0) = d(NaN) + I sign(d(NaN, +-0))0. 101 * The sign of 0 in the result is unspecified. 102 */ 103 if ((iy | ly) == 0 && ix >= 0x7ff00000) { 104 if (((hx & 0xfffff) | lx) == 0) | 96 97 /* 98 * cosh(+-Inf +- I 0) = +Inf + I (+-)(+-)0. 99 * 100 * cosh(NaN +- I 0) = d(NaN) + I sign(d(NaN, +-0))0. 101 * The sign of 0 in the result is unspecified. 102 */ 103 if ((iy | ly) == 0 && ix >= 0x7ff00000) { 104 if (((hx & 0xfffff) | lx) == 0) |
105 return (cpack(x * x, copysign(0, x) * y)); 106 return (cpack(x * x, copysign(0, (x + x) * y))); | 105 return (CMPLX(x * x, copysign(0, x) * y)); 106 return (CMPLX(x * x, copysign(0, (x + x) * y))); |
107 } 108 109 /* 110 * cosh(x +- I Inf) = dNaN + I dNaN. 111 * Raise the invalid floating-point exception for finite nonzero x. 112 * 113 * cosh(x + I NaN) = d(NaN) + I d(NaN). 114 * Optionally raises the invalid floating-point exception for finite 115 * nonzero x. Choice = don't raise (except for signaling NaNs). 116 */ 117 if (ix < 0x7ff00000 && iy >= 0x7ff00000) | 107 } 108 109 /* 110 * cosh(x +- I Inf) = dNaN + I dNaN. 111 * Raise the invalid floating-point exception for finite nonzero x. 112 * 113 * cosh(x + I NaN) = d(NaN) + I d(NaN). 114 * Optionally raises the invalid floating-point exception for finite 115 * nonzero x. Choice = don't raise (except for signaling NaNs). 116 */ 117 if (ix < 0x7ff00000 && iy >= 0x7ff00000) |
118 return (cpack(y - y, x * (y - y))); | 118 return (CMPLX(y - y, x * (y - y))); |
119 120 /* 121 * cosh(+-Inf + I NaN) = +Inf + I d(NaN). 122 * 123 * cosh(+-Inf +- I Inf) = +Inf + I dNaN. 124 * The sign of Inf in the result is unspecified. Choice = always +. 125 * Raise the invalid floating-point exception. 126 * 127 * cosh(+-Inf + I y) = +Inf cos(y) +- I Inf sin(y) 128 */ 129 if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) { 130 if (iy >= 0x7ff00000) | 119 120 /* 121 * cosh(+-Inf + I NaN) = +Inf + I d(NaN). 122 * 123 * cosh(+-Inf +- I Inf) = +Inf + I dNaN. 124 * The sign of Inf in the result is unspecified. Choice = always +. 125 * Raise the invalid floating-point exception. 126 * 127 * cosh(+-Inf + I y) = +Inf cos(y) +- I Inf sin(y) 128 */ 129 if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) { 130 if (iy >= 0x7ff00000) |
131 return (cpack(x * x, x * (y - y))); 132 return (cpack((x * x) * cos(y), x * sin(y))); | 131 return (CMPLX(x * x, x * (y - y))); 132 return (CMPLX((x * x) * cos(y), x * sin(y))); |
133 } 134 135 /* 136 * cosh(NaN + I NaN) = d(NaN) + I d(NaN). 137 * 138 * cosh(NaN +- I Inf) = d(NaN) + I d(NaN). 139 * Optionally raises the invalid floating-point exception. 140 * Choice = raise. 141 * 142 * cosh(NaN + I y) = d(NaN) + I d(NaN). 143 * Optionally raises the invalid floating-point exception for finite 144 * nonzero y. Choice = don't raise (except for signaling NaNs). 145 */ | 133 } 134 135 /* 136 * cosh(NaN + I NaN) = d(NaN) + I d(NaN). 137 * 138 * cosh(NaN +- I Inf) = d(NaN) + I d(NaN). 139 * Optionally raises the invalid floating-point exception. 140 * Choice = raise. 141 * 142 * cosh(NaN + I y) = d(NaN) + I d(NaN). 143 * Optionally raises the invalid floating-point exception for finite 144 * nonzero y. Choice = don't raise (except for signaling NaNs). 145 */ |
146 return (cpack((x * x) * (y - y), (x + x) * (y - y))); | 146 return (CMPLX((x * x) * (y - y), (x + x) * (y - y))); |
147} 148 149double complex 150ccos(double complex z) 151{ 152 153 /* ccos(z) = ccosh(I * z) */ | 147} 148 149double complex 150ccos(double complex z) 151{ 152 153 /* ccos(z) = ccosh(I * z) */ |
154 return (ccosh(cpack(-cimag(z), creal(z)))); | 154 return (ccosh(CMPLX(-cimag(z), creal(z)))); |
155} | 155} |