From ac831b362ad6ecd49643625481ec700a9812e52f Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Wed, 24 Jun 2015 16:20:48 +0000 Subject: Fix csin, csinh overflow in directed rounding modes (bug 18593). csin and csinh can produce bad results when overflowing in directed rounding modes, because a multiplication that can overflow is followed by a possible negation. This patch fixes this by negating one of the arguments of the multiplication before the multiplication instead of negating the result. The new tests for this issue are added to auto-libm-test-in, starting use of that file for csin and csinh. The issue was found in the course of moving existing tests for csin and csinh (existing tests, by being enabled in more cases than previously, showed the issue for float and double but not for long double); that move will now be done separately. Tested for x86_64 and x86 and ulps updated accordingly. [BZ #18593] * math/s_csin.c (__csin): Negate before rather than after possibly overflowing multiplication. * math/s_csinf.c (__csinf): Likewise. * math/s_csinh.c (__csinh): Likewise. * math/s_csinhf.c (__csinhf): Likewise. * math/s_csinhl.c (__csinhl): Likewise. * math/s_csinl.c (__csinl): Likewise. * math/auto-libm-test-in: Add some tests of csin and csinh. * math/auto-libm-test-out: Regenerated. * math/libm-test.inc (csin_test_data): Use AUTO_TESTS_c_c. (csinh_test_data): Likewise. * sysdeps/x86_64/fpu/libm-test-ulps: Update. --- math/s_csinf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'math/s_csinf.c') diff --git a/math/s_csinf.c b/math/s_csinf.c index 6c681898c1..daca6896b4 100644 --- a/math/s_csinf.c +++ b/math/s_csinf.c @@ -52,6 +52,9 @@ __csinf (__complex__ float x) cosix = 1.0f; } + if (negate) + sinix = -sinix; + if (fabsf (__imag__ x) > t) { float exp_t = __ieee754_expf (t); @@ -86,9 +89,6 @@ __csinf (__complex__ float x) __imag__ retval = __ieee754_sinhf (__imag__ x) * cosix; } - if (negate) - __real__ retval = -__real__ retval; - if (fabsf (__real__ retval) < FLT_MIN) { volatile float force_underflow -- cgit 1.4.1