cacos.c revision ddc0e0b53c661f6e439e3b7072b3ef353eadb4af
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * CDDL HEADER START
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * The contents of this file are subject to the terms of the
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Common Development and Distribution License (the "License").
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * You may not use this file except in compliance with the License.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * or http://www.opensolaris.org/os/licensing.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * See the License for the specific language governing permissions
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * and limitations under the License.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * When distributing Covered Code, include this CDDL HEADER in each
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * If applicable, add the following below this CDDL HEADER, with the
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * fields enclosed by brackets "[]" replaced with your own identifying
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * information: Portions Copyright [yyyy] [name of copyright owner]
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * CDDL HEADER END
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Use is subject to license terms.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis/* INDENT OFF */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * dcomplex cacos(dcomplex z);
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * (based on T.E.Hull, Thomas F. Fairgrieve and Ping Tak Peter Tang's
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * paper "Implementing the Complex Arcsine and Arccosine Functins Using
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Exception Handling", ACM TOMS, Vol 23, pp 299-335)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * The principal value of complex inverse cosine function cacos(z),
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * where z = x+iy, can be defined by
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos(z) = acos(B) - i sign(y) log (A + sqrt(A*A-1)),
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * where the log function is the natural log, and
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * ____________ ____________
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * 1 / 2 2 1 / 2 2
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * A = --- / (x+1) + y + --- / (x-1) + y
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * ____________ ____________
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * 1 / 2 2 1 / 2 2
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * B = --- / (x+1) + y - --- / (x-1) + y .
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * The Branch cuts are on the real line from -inf to -1 and from 1 to inf.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * The real and imaginary parts are based on Abramowitz and Stegun
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * [Handbook of Mathematic Functions, 1972]. The sign of the imaginary
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * part is chosen to be the generally considered the principal value of
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * this function.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Notes:1. A is the average of the distances from z to the points (1,0)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * and (-1,0) in the complex z-plane, and in particular A>=1.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * 2. B is in [-1,1], and A*B = x
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Basic relations
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos(conj(z)) = conj(cacos(z))
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos(-z) = pi - cacos(z)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos( z) = pi/2 - casin(z)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Special cases (conform to ISO/IEC 9899:1999(E)):
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos(+-0 + i y ) = pi/2 - i y for y is +-0, +-inf, NaN
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos( x + i inf) = pi/2 - i inf for all x
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos( x + i NaN) = NaN + i NaN with invalid for non-zero finite x
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos(-inf + i y ) = pi - i inf for finite +y
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos( inf + i y ) = 0 - i inf for finite +y
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos(-inf + i inf) = 3pi/4- i inf
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos( inf + i inf) = pi/4 - i inf
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos(+-inf+ i NaN) = NaN - i inf (sign of imaginary is unspecified)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos(NaN + i y ) = NaN + i NaN with invalid for finite y
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos(NaN + i inf) = NaN - i inf
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos(NaN + i NaN) = NaN + i NaN
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Special Regions (better formula for accuracy and for avoiding spurious
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * overflow or underflow) (all x and y are assumed nonnegative):
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * case 1: y = 0
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * case 2: tiny y relative to x-1: y <= ulp(0.5)*|x-1|
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * case 3: tiny y: y < 4 sqrt(u), where u = minimum normal number
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * case 4: huge y relative to x+1: y >= (1+x)/ulp(0.5)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * case 5: huge x and y: x and y >= sqrt(M)/8, where M = maximum normal number
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * case 6: tiny x: x < 4 sqrt(u)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * case 1 & 2. y=0 or y/|x-1| is tiny. We have
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * ____________ _____________
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * / (x+-1) + y = |x+-1| / 1 + (------)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * \/ \/ |x+-1|
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * ~ |x+-1| ( 1 + --- (------) )
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * = |x+-1| + --------.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Consequently, it is not difficult to see that
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * [ 1 + ------------ , if x < 1,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * [ 2(1+x)(1-x)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * [ x, if x = 1 (y = 0),
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * [ x + ------------ ~ x, if x > 1
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * [ 2(x+1)(x-1)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * A + \/ A - 1 ~ 1 + ---------------- + -----------, if x < 1,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * sqrt((x+1)(1-x)) 2(x+1)(1-x)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * ~ x + sqrt((x-1)*(x+1)), if x >= 1.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * [ x(1 - -----------) ~ x, if x < 1,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * [ 2(1+x)(1-x)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * [ 1, if x = 1,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * [ 1 - ------------ , if x > 1,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * [ 2(x+1)(x-1)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * [ acos(x) - i y/sqrt((x-1)*(x+1)), if x < 1,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos(x+i*y)~ [ 0 - i 0, if x = 1,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * [ y/sqrt(x*x-1) - i log(x+sqrt(x*x-1)), if x > 1.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Note: y/sqrt(x*x-1) ~ y/x when x >= 2**26.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * case 3. y < 4 sqrt(u), where u = minimum normal x.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * After case 1 and 2, this will only occurs when x=1. When x=1, we have
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * A = (sqrt(4+y*y)+y)/2 ~ 1 + y/2 + y^2/8 + ...
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * B = 1/A = 1 - y/2 + y^2/8 + ...
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cos(sqrt(y)) ~ 1 - y/2 + ...
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * we have, for the real part,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * acos(B) ~ acos(1 - y/2) ~ sqrt(y)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * For the imaginary part,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * log(A+sqrt(A*A-1)) ~ log(1+y/2+sqrt(2*y/2))
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * = log(1+y/2+sqrt(y))
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * = (y/2+sqrt(y)) - (y/2+sqrt(y))^2/2 + ...
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * ~ sqrt(y) - y*(sqrt(y)+y/2)/2
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * case 4. y >= (x+1)/ulp(0.5). In this case, A ~ y and B ~ x/y. Thus
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * real part = acos(B) ~ pi/2
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * imag part = log(y+sqrt(y*y-one))
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * case 5. Both x and y are large: x and y > sqrt(M)/8, where M = maximum x
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * In this case,
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * A ~ sqrt(x*x+y*y)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * B ~ x/sqrt(x*x+y*y).
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * real part = acos(B) = atan(y/x),
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * imag part = log(A+sqrt(A*A-1)) ~ log(2A)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * = log(2) + 0.5*log(x*x+y*y)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * = log(2) + log(y) + 0.5*log(1+(x/y)^2)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * case 6. x < 4 sqrt(u). In this case, we have
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * A ~ sqrt(1+y*y), B = x/sqrt(1+y*y).
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Since B is tiny, we have
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * real part = acos(B) ~ pi/2
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * imag part = log(A+sqrt(A*A-1)) = log (A+sqrt(y*y))
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * = log(y+sqrt(1+y*y))
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * = 0.5*log(y^2+2ysqrt(1+y^2)+1+y^2)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * = 0.5*log(1+2y(y+sqrt(1+y^2)));
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * = 0.5*log1p(2y(y+A));
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos(z) = acos(B) - i sign(y) log (A + sqrt(A*A-1)),
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis/* INDENT ON */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis/* INDENT OFF */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtisstatic const double
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis E = 1.11022302462515654042e-16, /* 2**-53 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis Foursqrtu = 5.96667258496016539463e-154, /* 2**(-509) */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis/* INDENT ON */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis double x, y, t, R, S, A, Am1, B, y2, xm1, xp1, Apx;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if (((iy | ly) == 0) || (iy >= 0x7ff00000)) {
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* |y| is inf or NaN */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if (ISINF(iy, ly)) { /* cacos(x + i inf) = pi/2 - i inf */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis } else { /* cacos(x + i NaN) = NaN + i NaN */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* x is inf or NaN */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if (ix >= 0x7ff00000) { /* x is inf or NaN */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* INDENT OFF */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* cacos(inf + i inf) = pi/4 - i inf */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* cacos(-inf+ i inf) =3pi/4 - i inf */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* INDENT ON */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* INDENT OFF */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* cacos(inf + i NaN) = NaN - i inf */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* INDENT ON */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* INDENT OFF */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* cacos(inf + iy ) = 0 - i inf */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* cacos(-inf+ iy ) = pi - i inf */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* INDENT ON */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis } else { /* x is NaN */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* INDENT OFF */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos(NaN + i inf) = NaN - i inf
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos(NaN + i y ) = NaN + i NaN
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * cacos(NaN + i NaN) = NaN + i NaN
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* INDENT ON */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis else if (ix >= 0x3ff80000) /* x > Acrossover */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis D_IM(ans) = log1p(xm1 + sqrt(xm1 * (x + one)));
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis } else if (y <= E * fabs(x - one)) { /* region 2: y < tiny*|x-1| */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis D_IM(ans) = y / sqrt((one + x) * (one - x));
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis } else if (ix >= 0x43500000) { /* |x| >= 2**54 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if (ix >= 0x3ff80000) /* x > Acrossover */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis } else if (y < Foursqrtu) { /* region 3 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis } else if (E * y - one >= x) { /* region 4 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis } else if (ix >= 0x5fc00000 || iy >= 0x5fc00000) { /* x,y>2**509 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* region 5: x+1 or y is very large (>= sqrt(max)/8) */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis D_IM(ans) = ln2 + log(y) + half * log1p(t * t);
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis } else if (x < Foursqrtu) {
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* region 6: x is very small, < 4sqrt(min) */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis if (iy >= 0x3ff80000) /* if y > Acrossover */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis D_IM(ans) = half * log1p((y + y) * (y + A));
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis } else { /* safe region */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis A = half * (R + S);
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis else { /* use atan and an accurate approx to a-x */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis D_RE(ans) = atan(sqrt(half * Apx * (y2 / (R +
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis D_RE(ans) = atan((y * sqrt(half * (Apx / (R +
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* use log1p and an accurate approx to A-1 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis Am1 = half * (y2 / (R + xp1) + y2 / (S - xm1));
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis Am1 = half * (y2 / (R + xp1) + (S + xm1));
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis D_IM(ans) = log1p(Am1 + sqrt(Am1 * (A + one)));