aboutsummaryrefslogtreecommitdiff
path: root/math
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2012-07-04 09:55:26 +0000
committerJoseph Myers <joseph@codesourcery.com>2012-07-04 09:55:26 +0000
commitca61cf32d934eda9130c4d3c6911892877ad7b0d (patch)
tree46022718d233a6b0ca7f2ba1d2d99d0356430aae /math
parentca48a46a03da4b64e623ac300929dd137f41adc6 (diff)
downloadglibc-ca61cf32d934eda9130c4d3c6911892877ad7b0d.zip
glibc-ca61cf32d934eda9130c4d3c6911892877ad7b0d.tar.gz
glibc-ca61cf32d934eda9130c4d3c6911892877ad7b0d.tar.bz2
Fix ctan, ctanh of subnormals in round-upwards mode (bug 14328).
Diffstat (limited to 'math')
-rw-r--r--math/libm-test.inc272
-rw-r--r--math/s_ctan.c18
-rw-r--r--math/s_ctanf.c18
-rw-r--r--math/s_ctanh.c18
-rw-r--r--math/s_ctanhf.c18
-rw-r--r--math/s_ctanhl.c18
-rw-r--r--math/s_ctanl.c18
7 files changed, 362 insertions, 18 deletions
diff --git a/math/libm-test.inc b/math/libm-test.inc
index 3e33348..514ad06 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -3319,6 +3319,138 @@ ctan_test (void)
static void
+ctan_test_tonearest (void)
+{
+ int save_round_mode;
+ errno = 0;
+ FUNC(ctan) (BUILD_COMPLEX (0.7L, 1.2L));
+ if (errno == ENOSYS)
+ /* Function not implemented. */
+ return;
+
+ START (ctan_tonearest);
+
+ save_round_mode = fegetround ();
+
+ if (!fesetround (FE_TONEAREST))
+ {
+ TEST_c_c (ctan, 0x1.921fb6p+0, 0x1p-149, -2.287733242885645987394874673945769518150e7L, 7.334008549954377778731880988481078535821e-31L);
+
+#ifndef TEST_FLOAT
+ TEST_c_c (ctan, 0x1.921fb54442d18p+0, 0x1p-1074, 1.633123935319536975596773704152891653086e16L, 1.317719414943508315995636961402669067843e-291L);
+#endif
+
+#if defined TEST_LDOUBLE && LDBL_MIN_EXP <= -16381
+ TEST_c_c (ctan, 0x1.921fb54442d1846ap+0L, 0x1p-16445L, -3.986797629811710706723242948653362815645e19L, 5.793882568875674066286163141055208625180e-4912L);
+#endif
+ }
+
+ fesetround (save_round_mode);
+
+ END (ctan_tonearest, complex);
+}
+
+
+static void
+ctan_test_towardzero (void)
+{
+ int save_round_mode;
+ errno = 0;
+ FUNC(ctan) (BUILD_COMPLEX (0.7L, 1.2L));
+ if (errno == ENOSYS)
+ /* Function not implemented. */
+ return;
+
+ START (ctan_towardzero);
+
+ save_round_mode = fegetround ();
+
+ if (!fesetround (FE_TOWARDZERO))
+ {
+ TEST_c_c (ctan, 0x1.921fb6p+0, 0x1p-149, -2.287733242885645987394874673945769518150e7L, 7.334008549954377778731880988481078535821e-31L);
+
+#ifndef TEST_FLOAT
+ TEST_c_c (ctan, 0x1.921fb54442d18p+0, 0x1p-1074, 1.633123935319536975596773704152891653086e16L, 1.317719414943508315995636961402669067843e-291L);
+#endif
+
+#if defined TEST_LDOUBLE && LDBL_MIN_EXP <= -16381
+ TEST_c_c (ctan, 0x1.921fb54442d1846ap+0L, 0x1p-16445L, -3.986797629811710706723242948653362815645e19L, 5.793882568875674066286163141055208625180e-4912L);
+#endif
+ }
+
+ fesetround (save_round_mode);
+
+ END (ctan_towardzero, complex);
+}
+
+
+static void
+ctan_test_downward (void)
+{
+ int save_round_mode;
+ errno = 0;
+ FUNC(ctan) (BUILD_COMPLEX (0.7L, 1.2L));
+ if (errno == ENOSYS)
+ /* Function not implemented. */
+ return;
+
+ START (ctan_downward);
+
+ save_round_mode = fegetround ();
+
+ if (!fesetround (FE_DOWNWARD))
+ {
+ TEST_c_c (ctan, 0x1.921fb6p+0, 0x1p-149, -2.287733242885645987394874673945769518150e7L, 7.334008549954377778731880988481078535821e-31L);
+
+#ifndef TEST_FLOAT
+ TEST_c_c (ctan, 0x1.921fb54442d18p+0, 0x1p-1074, 1.633123935319536975596773704152891653086e16L, 1.317719414943508315995636961402669067843e-291L);
+#endif
+
+#if defined TEST_LDOUBLE && LDBL_MIN_EXP <= -16381
+ TEST_c_c (ctan, 0x1.921fb54442d1846ap+0L, 0x1p-16445L, -3.986797629811710706723242948653362815645e19L, 5.793882568875674066286163141055208625180e-4912L);
+#endif
+ }
+
+ fesetround (save_round_mode);
+
+ END (ctan_downward, complex);
+}
+
+
+static void
+ctan_test_upward (void)
+{
+ int save_round_mode;
+ errno = 0;
+ FUNC(ctan) (BUILD_COMPLEX (0.7L, 1.2L));
+ if (errno == ENOSYS)
+ /* Function not implemented. */
+ return;
+
+ START (ctan_upward);
+
+ save_round_mode = fegetround ();
+
+ if (!fesetround (FE_UPWARD))
+ {
+ TEST_c_c (ctan, 0x1.921fb6p+0, 0x1p-149, -2.287733242885645987394874673945769518150e7L, 7.334008549954377778731880988481078535821e-31L);
+
+#ifndef TEST_FLOAT
+ TEST_c_c (ctan, 0x1.921fb54442d18p+0, 0x1p-1074, 1.633123935319536975596773704152891653086e16L, 1.317719414943508315995636961402669067843e-291L);
+#endif
+
+#if defined TEST_LDOUBLE && LDBL_MIN_EXP <= -16381
+ TEST_c_c (ctan, 0x1.921fb54442d1846ap+0L, 0x1p-16445L, -3.986797629811710706723242948653362815645e19L, 5.793882568875674066286163141055208625180e-4912L);
+#endif
+ }
+
+ fesetround (save_round_mode);
+
+ END (ctan_upward, complex);
+}
+
+
+static void
ctanh_test (void)
{
errno = 0;
@@ -3408,6 +3540,138 @@ ctanh_test (void)
static void
+ctanh_test_tonearest (void)
+{
+ int save_round_mode;
+ errno = 0;
+ FUNC(ctanh) (BUILD_COMPLEX (0.7L, 1.2L));
+ if (errno == ENOSYS)
+ /* Function not implemented. */
+ return;
+
+ START (ctanh_tonearest);
+
+ save_round_mode = fegetround ();
+
+ if (!fesetround (FE_TONEAREST))
+ {
+ TEST_c_c (ctanh, 0x1p-149, 0x1.921fb6p+0, 7.334008549954377778731880988481078535821e-31L, -2.287733242885645987394874673945769518150e7L);
+
+#ifndef TEST_FLOAT
+ TEST_c_c (ctanh, 0x1p-1074, 0x1.921fb54442d18p+0, 1.317719414943508315995636961402669067843e-291L, 1.633123935319536975596773704152891653086e16L);
+#endif
+
+#if defined TEST_LDOUBLE && LDBL_MIN_EXP <= -16381
+ TEST_c_c (ctanh, 0x1p-16445L, 0x1.921fb54442d1846ap+0L, 5.793882568875674066286163141055208625180e-4912L, -3.986797629811710706723242948653362815645e19L);
+#endif
+ }
+
+ fesetround (save_round_mode);
+
+ END (ctanh_tonearest, complex);
+}
+
+
+static void
+ctanh_test_towardzero (void)
+{
+ int save_round_mode;
+ errno = 0;
+ FUNC(ctanh) (BUILD_COMPLEX (0.7L, 1.2L));
+ if (errno == ENOSYS)
+ /* Function not implemented. */
+ return;
+
+ START (ctanh_towardzero);
+
+ save_round_mode = fegetround ();
+
+ if (!fesetround (FE_TOWARDZERO))
+ {
+ TEST_c_c (ctanh, 0x1p-149, 0x1.921fb6p+0, 7.334008549954377778731880988481078535821e-31L, -2.287733242885645987394874673945769518150e7L);
+
+#ifndef TEST_FLOAT
+ TEST_c_c (ctanh, 0x1p-1074, 0x1.921fb54442d18p+0, 1.317719414943508315995636961402669067843e-291L, 1.633123935319536975596773704152891653086e16L);
+#endif
+
+#if defined TEST_LDOUBLE && LDBL_MIN_EXP <= -16381
+ TEST_c_c (ctanh, 0x1p-16445L, 0x1.921fb54442d1846ap+0L, 5.793882568875674066286163141055208625180e-4912L, -3.986797629811710706723242948653362815645e19L);
+#endif
+ }
+
+ fesetround (save_round_mode);
+
+ END (ctanh_towardzero, complex);
+}
+
+
+static void
+ctanh_test_downward (void)
+{
+ int save_round_mode;
+ errno = 0;
+ FUNC(ctanh) (BUILD_COMPLEX (0.7L, 1.2L));
+ if (errno == ENOSYS)
+ /* Function not implemented. */
+ return;
+
+ START (ctanh_downward);
+
+ save_round_mode = fegetround ();
+
+ if (!fesetround (FE_DOWNWARD))
+ {
+ TEST_c_c (ctanh, 0x1p-149, 0x1.921fb6p+0, 7.334008549954377778731880988481078535821e-31L, -2.287733242885645987394874673945769518150e7L);
+
+#ifndef TEST_FLOAT
+ TEST_c_c (ctanh, 0x1p-1074, 0x1.921fb54442d18p+0, 1.317719414943508315995636961402669067843e-291L, 1.633123935319536975596773704152891653086e16L);
+#endif
+
+#if defined TEST_LDOUBLE && LDBL_MIN_EXP <= -16381
+ TEST_c_c (ctanh, 0x1p-16445L, 0x1.921fb54442d1846ap+0L, 5.793882568875674066286163141055208625180e-4912L, -3.986797629811710706723242948653362815645e19L);
+#endif
+ }
+
+ fesetround (save_round_mode);
+
+ END (ctanh_downward, complex);
+}
+
+
+static void
+ctanh_test_upward (void)
+{
+ int save_round_mode;
+ errno = 0;
+ FUNC(ctanh) (BUILD_COMPLEX (0.7L, 1.2L));
+ if (errno == ENOSYS)
+ /* Function not implemented. */
+ return;
+
+ START (ctanh_upward);
+
+ save_round_mode = fegetround ();
+
+ if (!fesetround (FE_UPWARD))
+ {
+ TEST_c_c (ctanh, 0x1p-149, 0x1.921fb6p+0, 7.334008549954377778731880988481078535821e-31L, -2.287733242885645987394874673945769518150e7L);
+
+#ifndef TEST_FLOAT
+ TEST_c_c (ctanh, 0x1p-1074, 0x1.921fb54442d18p+0, 1.317719414943508315995636961402669067843e-291L, 1.633123935319536975596773704152891653086e16L);
+#endif
+
+#if defined TEST_LDOUBLE && LDBL_MIN_EXP <= -16381
+ TEST_c_c (ctanh, 0x1p-16445L, 0x1.921fb54442d1846ap+0L, 5.793882568875674066286163141055208625180e-4912L, -3.986797629811710706723242948653362815645e19L);
+#endif
+ }
+
+ fesetround (save_round_mode);
+
+ END (ctanh_upward, complex);
+}
+
+
+static void
erf_test (void)
{
errno = 0;
@@ -8909,7 +9173,15 @@ main (int argc, char **argv)
csinh_test ();
csqrt_test ();
ctan_test ();
+ ctan_test_tonearest ();
+ ctan_test_towardzero ();
+ ctan_test_downward ();
+ ctan_test_upward ();
ctanh_test ();
+ ctanh_test_tonearest ();
+ ctanh_test_towardzero ();
+ ctanh_test_downward ();
+ ctanh_test_upward ();
/* Bessel functions: */
j0_test ();
diff --git a/math/s_ctan.c b/math/s_ctan.c
index 78117b3..89c0fef 100644
--- a/math/s_ctan.c
+++ b/math/s_ctan.c
@@ -83,10 +83,22 @@ __ctan (__complex__ double x)
}
else
{
- double sinhix = __ieee754_sinh (__imag__ x);
- double coshix = __ieee754_cosh (__imag__ x);
+ double sinhix, coshix;
+ if (fabs (__imag__ x) > DBL_MIN)
+ {
+ sinhix = __ieee754_sinh (__imag__ x);
+ coshix = __ieee754_cosh (__imag__ x);
+ }
+ else
+ {
+ sinhix = __imag__ x;
+ coshix = 1.0;
+ }
- den = cosrx * cosrx + sinhix * sinhix;
+ if (fabs (sinhix) > fabs (cosrx) * DBL_EPSILON)
+ den = cosrx * cosrx + sinhix * sinhix;
+ else
+ den = cosrx * cosrx;
__real__ res = sinrx * cosrx / den;
__imag__ res = sinhix * coshix / den;
}
diff --git a/math/s_ctanf.c b/math/s_ctanf.c
index 4cba559..2559f83 100644
--- a/math/s_ctanf.c
+++ b/math/s_ctanf.c
@@ -83,10 +83,22 @@ __ctanf (__complex__ float x)
}
else
{
- float sinhix = __ieee754_sinhf (__imag__ x);
- float coshix = __ieee754_coshf (__imag__ x);
+ float sinhix, coshix;
+ if (fabsf (__imag__ x) > FLT_MIN)
+ {
+ sinhix = __ieee754_sinhf (__imag__ x);
+ coshix = __ieee754_coshf (__imag__ x);
+ }
+ else
+ {
+ sinhix = __imag__ x;
+ coshix = 1.0f;
+ }
- den = cosrx * cosrx + sinhix * sinhix;
+ if (fabsf (sinhix) > fabsf (cosrx) * FLT_EPSILON)
+ den = cosrx * cosrx + sinhix * sinhix;
+ else
+ den = cosrx * cosrx;
__real__ res = sinrx * cosrx / den;
__imag__ res = sinhix * coshix / den;
}
diff --git a/math/s_ctanh.c b/math/s_ctanh.c
index 201871e..d288b7d 100644
--- a/math/s_ctanh.c
+++ b/math/s_ctanh.c
@@ -83,10 +83,22 @@ __ctanh (__complex__ double x)
}
else
{
- double sinhrx = __ieee754_sinh (__real__ x);
- double coshrx = __ieee754_cosh (__real__ x);
+ double sinhrx, coshrx;
+ if (fabs (__real__ x) > DBL_MIN)
+ {
+ sinhrx = __ieee754_sinh (__real__ x);
+ coshrx = __ieee754_cosh (__real__ x);
+ }
+ else
+ {
+ sinhrx = __real__ x;
+ coshrx = 1.0;
+ }
- den = sinhrx * sinhrx + cosix * cosix;
+ if (fabs (sinhrx) > fabs (cosix) * DBL_EPSILON)
+ den = sinhrx * sinhrx + cosix * cosix;
+ else
+ den = cosix * cosix;
__real__ res = sinhrx * coshrx / den;
__imag__ res = sinix * cosix / den;
}
diff --git a/math/s_ctanhf.c b/math/s_ctanhf.c
index e505155..ca36a83 100644
--- a/math/s_ctanhf.c
+++ b/math/s_ctanhf.c
@@ -83,10 +83,22 @@ __ctanhf (__complex__ float x)
}
else
{
- float sinhrx = __ieee754_sinhf (__real__ x);
- float coshrx = __ieee754_coshf (__real__ x);
+ float sinhrx, coshrx;
+ if (fabsf (__real__ x) > FLT_MIN)
+ {
+ sinhrx = __ieee754_sinhf (__real__ x);
+ coshrx = __ieee754_coshf (__real__ x);
+ }
+ else
+ {
+ sinhrx = __real__ x;
+ coshrx = 1.0f;
+ }
- den = sinhrx * sinhrx + cosix * cosix;
+ if (fabsf (sinhrx) > fabsf (cosix) * FLT_EPSILON)
+ den = sinhrx * sinhrx + cosix * cosix;
+ else
+ den = cosix * cosix;
__real__ res = sinhrx * coshrx / den;
__imag__ res = sinix * cosix / den;
}
diff --git a/math/s_ctanhl.c b/math/s_ctanhl.c
index e5d6779..dbf1612 100644
--- a/math/s_ctanhl.c
+++ b/math/s_ctanhl.c
@@ -83,10 +83,22 @@ __ctanhl (__complex__ long double x)
}
else
{
- long double sinhrx = __ieee754_sinhl (__real__ x);
- long double coshrx = __ieee754_coshl (__real__ x);
+ long double sinhrx, coshrx;
+ if (fabsl (__real__ x) > LDBL_MIN)
+ {
+ sinhrx = __ieee754_sinhl (__real__ x);
+ coshrx = __ieee754_coshl (__real__ x);
+ }
+ else
+ {
+ sinhrx = __real__ x;
+ coshrx = 1.0L;
+ }
- den = sinhrx * sinhrx + cosix * cosix;
+ if (fabsl (sinhrx) > fabsl (cosix) * LDBL_EPSILON)
+ den = sinhrx * sinhrx + cosix * cosix;
+ else
+ den = cosix * cosix;
__real__ res = sinhrx * coshrx / den;
__imag__ res = sinix * cosix / den;
}
diff --git a/math/s_ctanl.c b/math/s_ctanl.c
index 12d700c..4fe2611 100644
--- a/math/s_ctanl.c
+++ b/math/s_ctanl.c
@@ -83,10 +83,22 @@ __ctanl (__complex__ long double x)
}
else
{
- long double sinhix = __ieee754_sinhl (__imag__ x);
- long double coshix = __ieee754_coshl (__imag__ x);
+ long double sinhix, coshix;
+ if (fabsl (__imag__ x) > LDBL_MIN)
+ {
+ sinhix = __ieee754_sinhl (__imag__ x);
+ coshix = __ieee754_coshl (__imag__ x);
+ }
+ else
+ {
+ sinhix = __imag__ x;
+ coshix = 1.0L;
+ }
- den = cosrx * cosrx + sinhix * sinhix;
+ if (fabsl (sinhix) > fabsl (cosrx) * LDBL_EPSILON)
+ den = cosrx * cosrx + sinhix * sinhix;
+ else
+ den = cosrx * cosrx;
__real__ res = sinrx * cosrx / den;
__imag__ res = sinhix * coshix / den;
}