aboutsummaryrefslogtreecommitdiff
path: root/math
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2013-08-23 19:45:38 +0000
committerJoseph Myers <joseph@codesourcery.com>2013-08-23 19:45:38 +0000
commit8fe89494e6516048759425ec30d8878a6233e00f (patch)
treeb3f65b97d02bac4f183da5fe51e01cad8b8a3780 /math
parent936241e4b2ec90bbb97d1b37bc78726372ec966f (diff)
downloadglibc-8fe89494e6516048759425ec30d8878a6233e00f.tar
glibc-8fe89494e6516048759425ec30d8878a6233e00f.tar.gz
glibc-8fe89494e6516048759425ec30d8878a6233e00f.tar.bz2
glibc-8fe89494e6516048759425ec30d8878a6233e00f.zip
Fix cexp (NaN + i0) (bug 15532).
Diffstat (limited to 'math')
-rw-r--r--math/libm-test.inc3
-rw-r--r--math/s_cexp.c14
-rw-r--r--math/s_cexpf.c14
-rw-r--r--math/s_cexpl.c14
4 files changed, 32 insertions, 13 deletions
diff --git a/math/libm-test.inc b/math/libm-test.inc
index 43c4a8fd9c..e534fc0734 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -6198,7 +6198,8 @@ static const struct test_c_c_data cexp_test_data[] =
TEST_c_c (cexp, plus_infty, qnan_value, plus_infty, qnan_value),
- TEST_c_c (cexp, qnan_value, 0.0, qnan_value, qnan_value, INVALID_EXCEPTION_OK),
+ TEST_c_c (cexp, qnan_value, 0.0, qnan_value, 0.0),
+ TEST_c_c (cexp, qnan_value, minus_zero, qnan_value, minus_zero),
TEST_c_c (cexp, qnan_value, 1.0, qnan_value, qnan_value, INVALID_EXCEPTION_OK),
TEST_c_c (cexp, qnan_value, plus_infty, qnan_value, qnan_value, INVALID_EXCEPTION_OK),
diff --git a/math/s_cexp.c b/math/s_cexp.c
index 655e4e8dee..40e0e518d2 100644
--- a/math/s_cexp.c
+++ b/math/s_cexp.c
@@ -145,12 +145,18 @@ __cexp (__complex__ double x)
}
else
{
- /* If the real part is NaN the result is NaN + iNaN. */
+ /* If the real part is NaN the result is NaN + iNaN unless the
+ imaginary part is zero. */
__real__ retval = __nan ("");
- __imag__ retval = __nan ("");
+ if (icls == FP_ZERO)
+ __imag__ retval = __imag__ x;
+ else
+ {
+ __imag__ retval = __nan ("");
- if (rcls != FP_NAN || icls != FP_NAN)
- feraiseexcept (FE_INVALID);
+ if (rcls != FP_NAN || icls != FP_NAN)
+ feraiseexcept (FE_INVALID);
+ }
}
return retval;
diff --git a/math/s_cexpf.c b/math/s_cexpf.c
index fa942d34f7..7c42205164 100644
--- a/math/s_cexpf.c
+++ b/math/s_cexpf.c
@@ -145,12 +145,18 @@ __cexpf (__complex__ float x)
}
else
{
- /* If the real part is NaN the result is NaN + iNaN. */
+ /* If the real part is NaN the result is NaN + iNaN unless the
+ imaginary part is zero. */
__real__ retval = __nanf ("");
- __imag__ retval = __nanf ("");
+ if (icls == FP_ZERO)
+ __imag__ retval = __imag__ x;
+ else
+ {
+ __imag__ retval = __nanf ("");
- if (rcls != FP_NAN || icls != FP_NAN)
- feraiseexcept (FE_INVALID);
+ if (rcls != FP_NAN || icls != FP_NAN)
+ feraiseexcept (FE_INVALID);
+ }
}
return retval;
diff --git a/math/s_cexpl.c b/math/s_cexpl.c
index d827bc3de4..0c35603366 100644
--- a/math/s_cexpl.c
+++ b/math/s_cexpl.c
@@ -145,12 +145,18 @@ __cexpl (__complex__ long double x)
}
else
{
- /* If the real part is NaN the result is NaN + iNaN. */
+ /* If the real part is NaN the result is NaN + iNaN unless the
+ imaginary part is zero. */
__real__ retval = __nanl ("");
- __imag__ retval = __nanl ("");
+ if (icls == FP_ZERO)
+ __imag__ retval = __imag__ x;
+ else
+ {
+ __imag__ retval = __nanl ("");
- if (rcls != FP_NAN || icls != FP_NAN)
- feraiseexcept (FE_INVALID);
+ if (rcls != FP_NAN || icls != FP_NAN)
+ feraiseexcept (FE_INVALID);
+ }
}
return retval;