Print this page
11210 libm should be cstyle(1ONBLD) clean

*** 20,37 **** */ /* * Copyright 2011 Nexenta Systems, Inc. All rights reserved. */ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma weak __cacos = cacos ! /* INDENT OFF */ /* * dcomplex cacos(dcomplex z); * * Alogrithm * (based on T.E.Hull, Thomas F. Fairgrieve and Ping Tak Peter Tang's --- 20,38 ---- */ /* * Copyright 2011 Nexenta Systems, Inc. All rights reserved. */ + /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma weak __cacos = cacos ! /* * dcomplex cacos(dcomplex z); * * Alogrithm * (based on T.E.Hull, Thomas F. Fairgrieve and Ping Tak Peter Tang's
*** 188,205 **** * = 0.5*log(1+2y(y+sqrt(1+y^2))); * = 0.5*log1p(2y(y+A)); * * cacos(z) = acos(B) - i sign(y) log (A + sqrt(A*A-1)), */ - /* INDENT ON */ #include "libm.h" #include "complex_wrapper.h" ! /* INDENT OFF */ ! static const double ! zero = 0.0, one = 1.0, E = 1.11022302462515654042e-16, /* 2**-53 */ ln2 = 6.93147180559945286227e-01, pi = 3.1415926535897931159979634685, pi_l = 1.224646799147353177e-16, --- 189,203 ---- * = 0.5*log(1+2y(y+sqrt(1+y^2))); * = 0.5*log1p(2y(y+A)); * * cacos(z) = acos(B) - i sign(y) log (A + sqrt(A*A-1)), */ #include "libm.h" #include "complex_wrapper.h" ! static const double zero = 0.0, one = 1.0, E = 1.11022302462515654042e-16, /* 2**-53 */ ln2 = 6.93147180559945286227e-01, pi = 3.1415926535897931159979634685, pi_l = 1.224646799147353177e-16,
*** 211,224 **** pi3_4_l = 9.184850993605148829195e-17, Foursqrtu = 5.96667258496016539463e-154, /* 2**(-509) */ Acrossover = 1.5, Bcrossover = 0.6417, half = 0.5; ! /* INDENT ON */ dcomplex ! cacos(dcomplex z) { double x, y, t, R, S, A, Am1, B, y2, xm1, xp1, Apx; int ix, iy, hx, hy; unsigned lx, ly; dcomplex ans; --- 209,223 ---- pi3_4_l = 9.184850993605148829195e-17, Foursqrtu = 5.96667258496016539463e-154, /* 2**(-509) */ Acrossover = 1.5, Bcrossover = 0.6417, half = 0.5; ! dcomplex ! cacos(dcomplex z) ! { double x, y, t, R, S, A, Am1, B, y2, xm1, xp1, Apx; int ix, iy, hx, hy; unsigned lx, ly; dcomplex ans;
*** 242,251 **** --- 241,251 ---- /* |y| is inf or NaN */ if (iy >= 0x7ff00000) { if (ISINF(iy, ly)) { /* cacos(x + i inf) = pi/2 - i inf */ D_IM(ans) = -y; + if (ix < 0x7ff00000) { D_RE(ans) = pi_2 + pi_2_l; } else if (ISINF(ix, lx)) { if (hx >= 0) D_RE(ans) = pi_4 + pi_4_l;
*** 254,334 **** } else { D_RE(ans) = x; } } else { /* cacos(x + i NaN) = NaN + i NaN */ D_RE(ans) = y + x; if (ISINF(ix, lx)) D_IM(ans) = -fabs(x); else D_IM(ans) = y; } return (ans); } x = fabs(x); y = fabs(y); /* x is inf or NaN */ if (ix >= 0x7ff00000) { /* x is inf or NaN */ if (ISINF(ix, lx)) { /* x is INF */ D_IM(ans) = -x; if (iy >= 0x7ff00000) { if (ISINF(iy, ly)) { ! /* INDENT OFF */ ! /* cacos(inf + i inf) = pi/4 - i inf */ ! /* cacos(-inf+ i inf) =3pi/4 - i inf */ ! /* INDENT ON */ if (hx >= 0) D_RE(ans) = pi_4 + pi_4_l; else D_RE(ans) = pi3_4 + pi3_4_l; ! } else ! /* INDENT OFF */ ! /* cacos(inf + i NaN) = NaN - i inf */ ! /* INDENT ON */ D_RE(ans) = y + y; } else ! /* INDENT OFF */ ! /* cacos(inf + iy ) = 0 - i inf */ ! /* cacos(-inf+ iy ) = pi - i inf */ ! /* INDENT ON */ ! if (hx >= 0) D_RE(ans) = zero; ! else D_RE(ans) = pi + pi_l; } else { /* x is NaN */ ! /* INDENT OFF */ /* * cacos(NaN + i inf) = NaN - i inf * cacos(NaN + i y ) = NaN + i NaN * cacos(NaN + i NaN) = NaN + i NaN */ - /* INDENT ON */ D_RE(ans) = x + y; ! if (iy >= 0x7ff00000) { D_IM(ans) = -y; ! } else { D_IM(ans) = x; } ! } if (hy < 0) D_IM(ans) = -D_IM(ans); return (ans); } if ((iy | ly) == 0) { /* region 1: y=0 */ if (ix < 0x3ff00000) { /* |x| < 1 */ D_RE(ans) = acos(x); D_IM(ans) = zero; } else { D_RE(ans) = zero; ! if (ix >= 0x43500000) /* |x| >= 2**54 */ D_IM(ans) = ln2 + log(x); ! else if (ix >= 0x3ff80000) /* x > Acrossover */ D_IM(ans) = log(x + sqrt((x - one) * (x + one))); ! else { xm1 = x - one; D_IM(ans) = log1p(xm1 + sqrt(xm1 * (x + one))); } } } else if (y <= E * fabs(x - one)) { /* region 2: y < tiny*|x-1| */ --- 254,341 ---- } else { D_RE(ans) = x; } } else { /* cacos(x + i NaN) = NaN + i NaN */ D_RE(ans) = y + x; + if (ISINF(ix, lx)) D_IM(ans) = -fabs(x); else D_IM(ans) = y; } + return (ans); } x = fabs(x); y = fabs(y); /* x is inf or NaN */ if (ix >= 0x7ff00000) { /* x is inf or NaN */ if (ISINF(ix, lx)) { /* x is INF */ D_IM(ans) = -x; + if (iy >= 0x7ff00000) { if (ISINF(iy, ly)) { ! /* ! * cacos(inf + i inf) = pi/4 - i inf ! * cacos(-inf+ i inf) =3pi/4 - i inf ! */ if (hx >= 0) D_RE(ans) = pi_4 + pi_4_l; else D_RE(ans) = pi3_4 + pi3_4_l; ! } else { ! /* ! * cacos(inf + i NaN) = NaN - i inf ! */ D_RE(ans) = y + y; + } } else ! /* ! * cacos(inf + iy ) = 0 - i inf ! * cacos(-inf+ iy ) = pi - i inf ! */ ! if (hx >= 0) { D_RE(ans) = zero; ! } else { D_RE(ans) = pi + pi_l; + } } else { /* x is NaN */ ! /* * cacos(NaN + i inf) = NaN - i inf * cacos(NaN + i y ) = NaN + i NaN * cacos(NaN + i NaN) = NaN + i NaN */ D_RE(ans) = x + y; ! ! if (iy >= 0x7ff00000) D_IM(ans) = -y; ! else D_IM(ans) = x; } ! if (hy < 0) D_IM(ans) = -D_IM(ans); + return (ans); } if ((iy | ly) == 0) { /* region 1: y=0 */ if (ix < 0x3ff00000) { /* |x| < 1 */ D_RE(ans) = acos(x); D_IM(ans) = zero; } else { D_RE(ans) = zero; ! ! if (ix >= 0x43500000) { /* |x| >= 2**54 */ D_IM(ans) = ln2 + log(x); ! } else if (ix >= 0x3ff80000) { /* x > Acrossover */ D_IM(ans) = log(x + sqrt((x - one) * (x + one))); ! } else { xm1 = x - one; D_IM(ans) = log1p(xm1 + sqrt(xm1 * (x + one))); } } } else if (y <= E * fabs(x - one)) { /* region 2: y < tiny*|x-1| */
*** 339,348 **** --- 346,356 ---- D_RE(ans) = y / x; D_IM(ans) = ln2 + log(x); } else { t = sqrt((x - one) * (x + one)); D_RE(ans) = y / t; + if (ix >= 0x3ff80000) /* x > Acrossover */ D_IM(ans) = log(x + t); else D_IM(ans) = log1p((x - one) + t); }
*** 360,369 **** --- 368,378 ---- D_IM(ans) = ln2 + log(y) + half * log1p(t * t); } else if (x < Foursqrtu) { /* region 6: x is very small, < 4sqrt(min) */ D_RE(ans) = pi_2; A = sqrt(one + y * y); + if (iy >= 0x3ff80000) /* if y > Acrossover */ D_IM(ans) = log(y + A); else D_IM(ans) = half * log1p((y + y) * (y + A)); } else { /* safe region */
*** 372,404 **** xm1 = x - one; R = sqrt(xp1 * xp1 + y2); S = sqrt(xm1 * xm1 + y2); A = half * (R + S); B = x / A; ! if (B <= Bcrossover) D_RE(ans) = acos(B); ! else { /* use atan and an accurate approx to a-x */ Apx = A + x; if (x <= one) D_RE(ans) = atan(sqrt(half * Apx * (y2 / (R + xp1) + (S - xm1))) / x); else D_RE(ans) = atan((y * sqrt(half * (Apx / (R + xp1) + Apx / (S + xm1)))) / x); } if (A <= Acrossover) { /* use log1p and an accurate approx to A-1 */ if (x < one) Am1 = half * (y2 / (R + xp1) + y2 / (S - xm1)); else Am1 = half * (y2 / (R + xp1) + (S + xm1)); D_IM(ans) = log1p(Am1 + sqrt(Am1 * (A + one))); } else { D_IM(ans) = log(A + sqrt(A * A - one)); } } if (hx < 0) D_RE(ans) = pi - D_RE(ans); if (hy >= 0) D_IM(ans) = -D_IM(ans); return (ans); } --- 381,420 ---- xm1 = x - one; R = sqrt(xp1 * xp1 + y2); S = sqrt(xm1 * xm1 + y2); A = half * (R + S); B = x / A; ! ! if (B <= Bcrossover) { D_RE(ans) = acos(B); ! } else { /* use atan and an accurate approx to a-x */ Apx = A + x; + if (x <= one) D_RE(ans) = atan(sqrt(half * Apx * (y2 / (R + xp1) + (S - xm1))) / x); else D_RE(ans) = atan((y * sqrt(half * (Apx / (R + xp1) + Apx / (S + xm1)))) / x); } + if (A <= Acrossover) { /* use log1p and an accurate approx to A-1 */ if (x < one) Am1 = half * (y2 / (R + xp1) + y2 / (S - xm1)); else Am1 = half * (y2 / (R + xp1) + (S + xm1)); + D_IM(ans) = log1p(Am1 + sqrt(Am1 * (A + one))); } else { D_IM(ans) = log(A + sqrt(A * A - one)); } } + if (hx < 0) D_RE(ans) = pi - D_RE(ans); + if (hy >= 0) D_IM(ans) = -D_IM(ans); + return (ans); }