• Home
  • Raw
  • Download

Lines Matching +full:- +full:x

23 static const double ln2 = 6.93147180559945286227E-01;
27 static const double two_pow_m28 = 3.7252902984619141E-09; /* 2**-28 */
35 /* acosh(x)
38 * acosh(x) = log [ x + sqrt(x*x-1) ]
40 * acosh(x) := log(x)+ln2, if x is large; else
41 * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
42 * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
45 * acosh(x) is NaN with signal if x<1.
50 _Py_acosh(double x) in _Py_acosh() argument
52 if (Py_IS_NAN(x)) { in _Py_acosh()
53 return x+x; in _Py_acosh()
55 if (x < 1.) { /* x < 1; return a signaling NaN */ in _Py_acosh()
60 return (x-x)/(x-x); in _Py_acosh()
63 else if (x >= two_pow_p28) { /* x > 2**28 */ in _Py_acosh()
64 if (Py_IS_INFINITY(x)) { in _Py_acosh()
65 return x+x; in _Py_acosh()
68 return log(x) + ln2; /* acosh(huge)=log(2x) */ in _Py_acosh()
71 else if (x == 1.) { in _Py_acosh()
74 else if (x > 2.) { /* 2 < x < 2**28 */ in _Py_acosh()
75 double t = x * x; in _Py_acosh()
76 return log(2.0 * x - 1.0 / (x + sqrt(t - 1.0))); in _Py_acosh()
78 else { /* 1 < x <= 2 */ in _Py_acosh()
79 double t = x - 1.0; in _Py_acosh()
87 /* asinh(x)
90 * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ]
92 * asinh(x) := x if 1+x*x=1,
93 * := sign(x)*(log(x)+ln2) for large |x|, else
94 * := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else
95 * := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
99 _Py_asinh(double x) in _Py_asinh() argument
102 double absx = fabs(x); in _Py_asinh()
104 if (Py_IS_NAN(x) || Py_IS_INFINITY(x)) { in _Py_asinh()
105 return x+x; in _Py_asinh()
107 if (absx < two_pow_m28) { /* |x| < 2**-28 */ in _Py_asinh()
108 return x; /* return x inexact except 0 */ in _Py_asinh()
110 if (absx > two_pow_p28) { /* |x| > 2**28 */ in _Py_asinh()
113 else if (absx > 2.0) { /* 2 < |x| < 2**28 */ in _Py_asinh()
114 w = log(2.0 * absx + 1.0 / (sqrt(x * x + 1.0) + absx)); in _Py_asinh()
116 else { /* 2**-28 <= |x| < 2= */ in _Py_asinh()
117 double t = x*x; in _Py_asinh()
120 return copysign(w, x); in _Py_asinh()
127 /* atanh(x)
129 * 1.Reduced x to positive by atanh(-x) = -atanh(x)
130 * 2.For x>=0.5
131 * 1 2x x
132 * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * -------)
133 * 2 1 - x 1 - x
135 * For x<0.5
136 * atanh(x) = 0.5*log1p(2x+2x*x/(1-x))
139 * atanh(x) is NaN if |x| >= 1 with signal;
145 _Py_atanh(double x) in _Py_atanh() argument
150 if (Py_IS_NAN(x)) { in _Py_atanh()
151 return x+x; in _Py_atanh()
153 absx = fabs(x); in _Py_atanh()
154 if (absx >= 1.) { /* |x| >= 1 */ in _Py_atanh()
159 return x / zero; in _Py_atanh()
162 if (absx < two_pow_m28) { /* |x| < 2**-28 */ in _Py_atanh()
163 return x; in _Py_atanh()
165 if (absx < 0.5) { /* |x| < 0.5 */ in _Py_atanh()
167 t = 0.5 * m_log1p(t + t*absx / (1.0 - absx)); in _Py_atanh()
169 else { /* 0.5 <= |x| <= 1.0 */ in _Py_atanh()
170 t = 0.5 * m_log1p((absx + absx) / (1.0 - absx)); in _Py_atanh()
172 return copysign(t, x); in _Py_atanh()
178 /* Mathematically, expm1(x) = exp(x) - 1. The expm1 function is designed
180 evaluation of the expression exp(x) - 1, for x near 0. */
183 _Py_expm1(double x) in _Py_expm1() argument
185 /* For abs(x) >= log(2), it's safe to evaluate exp(x) - 1 directly; this in _Py_expm1()
188 For smaller x, we can use a method due to Kahan that achieves close to in _Py_expm1()
192 if (fabs(x) < 0.7) { in _Py_expm1()
194 u = exp(x); in _Py_expm1()
196 return x; in _Py_expm1()
198 return (u - 1.0) * x / log(u); in _Py_expm1()
201 return exp(x) - 1.0; in _Py_expm1()
206 /* log1p(x) = log(1+x). The log1p function is designed to avoid the
207 significant loss of precision that arises from direct evaluation when x is
211 _Py_log1p(double x) in _Py_log1p() argument
215 zero: log1p(-0.0) gives 0.0 instead of the correct result of -0.0. in _Py_log1p()
220 if (x == 0.0) { in _Py_log1p()
221 return x; in _Py_log1p()
224 return log1p(x); in _Py_log1p()
227 /* For x small, we use the following approach. Let y be the nearest float in _Py_log1p()
228 to 1+x, then in _Py_log1p()
230 1+x = y * (1 - (y-1-x)/y) in _Py_log1p()
232 so log(1+x) = log(y) + log(1-(y-1-x)/y). Since (y-1-x)/y is tiny, the in _Py_log1p()
233 second term is well approximated by (y-1-x)/y. If abs(x) >= in _Py_log1p()
234 DBL_EPSILON/2 or the rounding-mode is some form of round-to-nearest in _Py_log1p()
235 then y-1-x will be exactly representable, and is computed exactly by in _Py_log1p()
236 (y-1)-x. in _Py_log1p()
238 If abs(x) < DBL_EPSILON/2 and the rounding mode is not known to be in _Py_log1p()
239 round-to-nearest then this method is slightly dangerous: 1+x could be in _Py_log1p()
241 y-1-x will not be exactly representable any more and the result can be in _Py_log1p()
242 off by many ulps. But this is easily fixed: for a floating-point in _Py_log1p()
243 number |x| < DBL_EPSILON/2., the closest floating-point number to in _Py_log1p()
244 log(1+x) is exactly x. in _Py_log1p()
248 if (fabs(x) < DBL_EPSILON / 2.) { in _Py_log1p()
249 return x; in _Py_log1p()
251 else if (-0.5 <= x && x <= 1.) { in _Py_log1p()
254 to the equivalent of "return log(1.+x)". If this in _Py_log1p()
256 for small x. */ in _Py_log1p()
257 y = 1.+x; in _Py_log1p()
258 return log(y) - ((y - 1.) - x) / y; in _Py_log1p()
262 return log(1.+x); in _Py_log1p()