diff options
author | Joseph Myers <joseph@codesourcery.com> | 2013-01-04 13:25:17 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2013-01-04 13:25:17 +0000 |
commit | cdc1c96fbafce8c16ee0e75d466f4358e6a860db (patch) | |
tree | e6f6446e5081847ac19a5236c891d39e64c0a360 /math | |
parent | 6420d207bb10d966163c52e4e607a1e48e6bb13f (diff) | |
download | glibc-cdc1c96fbafce8c16ee0e75d466f4358e6a860db.tar.gz glibc-cdc1c96fbafce8c16ee0e75d466f4358e6a860db.tar.xz glibc-cdc1c96fbafce8c16ee0e75d466f4358e6a860db.zip |
Fix casinh, casin inaccuracy from cancellation (bug 14994).
Diffstat (limited to 'math')
-rw-r--r-- | math/libm-test.inc | 58 | ||||
-rw-r--r-- | math/s_casinh.c | 16 | ||||
-rw-r--r-- | math/s_casinhf.c | 16 | ||||
-rw-r--r-- | math/s_casinhl.c | 16 |
4 files changed, 88 insertions, 18 deletions
diff --git a/math/libm-test.inc b/math/libm-test.inc index 533fce847e..a586f7ee78 100644 --- a/math/libm-test.inc +++ b/math/libm-test.inc @@ -1698,6 +1698,35 @@ casin_test (void) TEST_c_c (casin, 1.5L, plus_zero, M_PI_2l, 0.9624236501192068949955178268487368462704L); TEST_c_c (casin, 1.5L, minus_zero, M_PI_2l, -0.9624236501192068949955178268487368462704L); + TEST_c_c (casin, 0x1p50L, 1.0L, 1.570796326794895731052901991514519103193L, 3.535050620855721078027883819436720218708e1L); + TEST_c_c (casin, 0x1p50L, -1.0L, 1.570796326794895731052901991514519103193L, -3.535050620855721078027883819436720218708e1L); + TEST_c_c (casin, -0x1p50L, 1.0L, -1.570796326794895731052901991514519103193L, 3.535050620855721078027883819436720218708e1L); + TEST_c_c (casin, -0x1p50L, -1.0L, -1.570796326794895731052901991514519103193L, -3.535050620855721078027883819436720218708e1L); + TEST_c_c (casin, 1.0L, 0x1p50L, 8.881784197001252323389053344720723756399e-16L, 3.535050620855721078027883819436759661753e1L); + TEST_c_c (casin, -1.0L, 0x1p50L, -8.881784197001252323389053344720723756399e-16L, 3.535050620855721078027883819436759661753e1L); + TEST_c_c (casin, 1.0L, -0x1p50L, 8.881784197001252323389053344720723756399e-16L, -3.535050620855721078027883819436759661753e1L); + TEST_c_c (casin, -1.0L, -0x1p50L, -8.881784197001252323389053344720723756399e-16L, -3.535050620855721078027883819436759661753e1L); +#ifndef TEST_FLOAT + TEST_c_c (casin, 0x1p500L, 1.0L, 1.570796326794896619231321691639751442099L, 3.472667374605326000180332928505464606058e2L); + TEST_c_c (casin, 0x1p500L, -1.0L, 1.570796326794896619231321691639751442099L, -3.472667374605326000180332928505464606058e2L); + TEST_c_c (casin, -0x1p500L, 1.0L, -1.570796326794896619231321691639751442099L, 3.472667374605326000180332928505464606058e2L); + TEST_c_c (casin, -0x1p500L, -1.0L, -1.570796326794896619231321691639751442099L, -3.472667374605326000180332928505464606058e2L); + TEST_c_c (casin, 1.0L, 0x1p500L, 3.054936363499604682051979393213617699789e-151L, 3.472667374605326000180332928505464606058e2L); + TEST_c_c (casin, -1.0L, 0x1p500L, -3.054936363499604682051979393213617699789e-151L, 3.472667374605326000180332928505464606058e2L); + TEST_c_c (casin, 1.0L, -0x1p500L, 3.054936363499604682051979393213617699789e-151L, -3.472667374605326000180332928505464606058e2L); + TEST_c_c (casin, -1.0L, -0x1p500L, -3.054936363499604682051979393213617699789e-151L, -3.472667374605326000180332928505464606058e2L); +#endif +#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384 + TEST_c_c (casin, 0x1p5000L, 1.0L, 1.570796326794896619231321691639751442099L, 3.466429049980286492395577839412341016946e3L); + TEST_c_c (casin, 0x1p5000L, -1.0L, 1.570796326794896619231321691639751442099L, -3.466429049980286492395577839412341016946e3L); + TEST_c_c (casin, -0x1p5000L, 1.0L, -1.570796326794896619231321691639751442099L, 3.466429049980286492395577839412341016946e3L); + TEST_c_c (casin, -0x1p5000L, -1.0L, -1.570796326794896619231321691639751442099L, -3.466429049980286492395577839412341016946e3L); + TEST_c_c (casin, 1.0L, 0x1p5000L, 7.079811261048172892385615158694057552948e-1506L, 3.466429049980286492395577839412341016946e3L); + TEST_c_c (casin, -1.0L, 0x1p5000L, -7.079811261048172892385615158694057552948e-1506L, 3.466429049980286492395577839412341016946e3L); + TEST_c_c (casin, 1.0L, -0x1p5000L, 7.079811261048172892385615158694057552948e-1506L, -3.466429049980286492395577839412341016946e3L); + TEST_c_c (casin, -1.0L, -0x1p5000L, -7.079811261048172892385615158694057552948e-1506L, -3.466429049980286492395577839412341016946e3L); +#endif + TEST_c_c (casin, 0.75L, 1.25L, 0.453276177638793913448921196101971749L, 1.13239363160530819522266333696834467L); TEST_c_c (casin, -2, -3, -0.57065278432109940071028387968566963L, -1.9833870299165354323470769028940395L); @@ -1788,6 +1817,35 @@ casinh_test (void) TEST_c_c (casinh, 1.5L, plus_zero, 1.194763217287109304111930828519090523536L, plus_zero); TEST_c_c (casinh, 1.5L, minus_zero, 1.194763217287109304111930828519090523536L, minus_zero); + TEST_c_c (casinh, 0x1p50L, 1.0L, 3.535050620855721078027883819436759661753e1L, 8.881784197001252323389053344720723756399e-16L); + TEST_c_c (casinh, 0x1p50L, -1.0L, 3.535050620855721078027883819436759661753e1L, -8.881784197001252323389053344720723756399e-16L); + TEST_c_c (casinh, -0x1p50L, 1.0L, -3.535050620855721078027883819436759661753e1L, 8.881784197001252323389053344720723756399e-16L); + TEST_c_c (casinh, -0x1p50L, -1.0L, -3.535050620855721078027883819436759661753e1L, -8.881784197001252323389053344720723756399e-16L); + TEST_c_c (casinh, 1.0L, 0x1p50L, 3.535050620855721078027883819436720218708e1L, 1.570796326794895731052901991514519103193L); + TEST_c_c (casinh, -1.0L, 0x1p50L, -3.535050620855721078027883819436720218708e1L, 1.570796326794895731052901991514519103193L); + TEST_c_c (casinh, 1.0L, -0x1p50L, 3.535050620855721078027883819436720218708e1L, -1.570796326794895731052901991514519103193L); + TEST_c_c (casinh, -1.0L, -0x1p50L, -3.535050620855721078027883819436720218708e1L, -1.570796326794895731052901991514519103193L); +#ifndef TEST_FLOAT + TEST_c_c (casinh, 0x1p500L, 1.0L, 3.472667374605326000180332928505464606058e2L, 3.054936363499604682051979393213617699789e-151L); + TEST_c_c (casinh, 0x1p500L, -1.0L, 3.472667374605326000180332928505464606058e2L, -3.054936363499604682051979393213617699789e-151L); + TEST_c_c (casinh, -0x1p500L, 1.0L, -3.472667374605326000180332928505464606058e2L, 3.054936363499604682051979393213617699789e-151L); + TEST_c_c (casinh, -0x1p500L, -1.0L, -3.472667374605326000180332928505464606058e2L, -3.054936363499604682051979393213617699789e-151L); + TEST_c_c (casinh, 1.0L, 0x1p500L, 3.472667374605326000180332928505464606058e2L, 1.570796326794896619231321691639751442099L); + TEST_c_c (casinh, -1.0L, 0x1p500L, -3.472667374605326000180332928505464606058e2L, 1.570796326794896619231321691639751442099L); + TEST_c_c (casinh, 1.0L, -0x1p500L, 3.472667374605326000180332928505464606058e2L, -1.570796326794896619231321691639751442099L); + TEST_c_c (casinh, -1.0L, -0x1p500L, -3.472667374605326000180332928505464606058e2L, -1.570796326794896619231321691639751442099L); +#endif +#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384 + TEST_c_c (casinh, 0x1p5000L, 1.0L, 3.466429049980286492395577839412341016946e3L, 7.079811261048172892385615158694057552948e-1506L); + TEST_c_c (casinh, 0x1p5000L, -1.0L, 3.466429049980286492395577839412341016946e3L, -7.079811261048172892385615158694057552948e-1506L); + TEST_c_c (casinh, -0x1p5000L, 1.0L, -3.466429049980286492395577839412341016946e3L, 7.079811261048172892385615158694057552948e-1506L); + TEST_c_c (casinh, -0x1p5000L, -1.0L, -3.466429049980286492395577839412341016946e3L, -7.079811261048172892385615158694057552948e-1506L); + TEST_c_c (casinh, 1.0L, 0x1p5000L, 3.466429049980286492395577839412341016946e3L, 1.570796326794896619231321691639751442099L); + TEST_c_c (casinh, -1.0L, 0x1p5000L, -3.466429049980286492395577839412341016946e3L, 1.570796326794896619231321691639751442099L); + TEST_c_c (casinh, 1.0L, -0x1p5000L, 3.466429049980286492395577839412341016946e3L, -1.570796326794896619231321691639751442099L); + TEST_c_c (casinh, -1.0L, -0x1p5000L, -3.466429049980286492395577839412341016946e3L, -1.570796326794896619231321691639751442099L); +#endif + TEST_c_c (casinh, 0.75L, 1.25L, 1.03171853444778027336364058631006594L, 0.911738290968487636358489564316731207L); TEST_c_c (casinh, -2, -3, -1.9686379257930962917886650952454982L, -0.96465850440760279204541105949953237L); diff --git a/math/s_casinh.c b/math/s_casinh.c index 8c4aa19f63..acdf1a1e5a 100644 --- a/math/s_casinh.c +++ b/math/s_casinh.c @@ -62,20 +62,24 @@ __casinh (__complex__ double x) } else { + double rx, ix; __complex__ double y; - __real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) + 1.0; - __imag__ y = 2.0 * __real__ x * __imag__ x; + /* Avoid cancellation by reducing to the first quadrant. */ + rx = fabs (__real__ x); + ix = fabs (__imag__ x); + + __real__ y = (rx - ix) * (rx + ix) + 1.0; + __imag__ y = 2.0 * rx * ix; y = __csqrt (y); - __real__ y += __real__ x; - __imag__ y += __imag__ x; + __real__ y += rx; + __imag__ y += ix; res = __clog (y); - /* Ensure zeros have correct sign and results are correct if - very close to branch cuts. */ + /* Give results the correct sign for the original argument. */ __real__ res = __copysign (__real__ res, __real__ x); __imag__ res = __copysign (__imag__ res, __imag__ x); } diff --git a/math/s_casinhf.c b/math/s_casinhf.c index e3a92f5113..8f4315cbf9 100644 --- a/math/s_casinhf.c +++ b/math/s_casinhf.c @@ -62,20 +62,24 @@ __casinhf (__complex__ float x) } else { + float rx, ix; __complex__ float y; - __real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) + 1.0; - __imag__ y = 2.0 * __real__ x * __imag__ x; + /* Avoid cancellation by reducing to the first quadrant. */ + rx = fabsf (__real__ x); + ix = fabsf (__imag__ x); + + __real__ y = (rx - ix) * (rx + ix) + 1.0; + __imag__ y = 2.0 * rx * ix; y = __csqrtf (y); - __real__ y += __real__ x; - __imag__ y += __imag__ x; + __real__ y += rx; + __imag__ y += ix; res = __clogf (y); - /* Ensure zeros have correct sign and results are correct if - very close to branch cuts. */ + /* Give results the correct sign for the original argument. */ __real__ res = __copysignf (__real__ res, __real__ x); __imag__ res = __copysignf (__imag__ res, __imag__ x); } diff --git a/math/s_casinhl.c b/math/s_casinhl.c index 676a65b8a2..83f8d1885d 100644 --- a/math/s_casinhl.c +++ b/math/s_casinhl.c @@ -62,20 +62,24 @@ __casinhl (__complex__ long double x) } else { + long double rx, ix; __complex__ long double y; - __real__ y = (__real__ x - __imag__ x) * (__real__ x + __imag__ x) + 1.0; - __imag__ y = 2.0 * __real__ x * __imag__ x; + /* Avoid cancellation by reducing to the first quadrant. */ + rx = fabsl (__real__ x); + ix = fabsl (__imag__ x); + + __real__ y = (rx - ix) * (rx + ix) + 1.0; + __imag__ y = 2.0 * rx * ix; y = __csqrtl (y); - __real__ y += __real__ x; - __imag__ y += __imag__ x; + __real__ y += rx; + __imag__ y += ix; res = __clogl (y); - /* Ensure zeros have correct sign and results are correct if - very close to branch cuts. */ + /* Give results the correct sign for the original argument. */ __real__ res = __copysignl (__real__ res, __real__ x); __imag__ res = __copysignl (__imag__ res, __imag__ x); } |