This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] math/libm-test.inc: Fix cos and sincos tests against zero.
- From: "Carlos O'Donell" <carlos at redhat dot com>
- To: Andreas Jaeger <aj at suse dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Thu, 11 Apr 2013 00:17:26 -0400
- Subject: Re: [PATCH] math/libm-test.inc: Fix cos and sincos tests against zero.
- References: <51645EBD dot 1090206 at redhat dot com> <47111363 dot 4Y1Og02VS0 at byrd>
On 04/10/2013 03:46 AM, Andreas Jaeger wrote:
> So, you need to fix this also for each long double variant as Andreas
> Schwab and you discussed elsewhere.
>
>> Is this the right way forward, even if it is logically the correct
>> answer? I would say yes. I would say the test suite as it is right
>> now is testing against the "naive" expected result. It works because
>> ulp(0) for the testsuite is a huge value that allows all sorts of
>> inaccurate zero values.
>>
>> Comments?
>
> Thanks a lot for digging into this, I agree with your analysis and think
> this is fine,
I think that's all the formats for all the targets.
* 32-bit float (flt-32) [*]
* 64-bit double (dbl-64) [*]
* 64-bit long double (some aliases) [hppa]
* 96-bit long double (ldbl-96) [m68k, ia64, x86, x86-64, x32]
* 128-bit IBM long double (ldbl-128ibm) [power]
* 128-bit long double (ldbl-128) [mips64, alpha, aarch64, s390, s390x, sparc32, sparc64]
v2
- Add support for double == long double.
- Add support for 128-bit IMB long double.
- Add support for IEEE 128-bit long double.
No regressions on x86-64 or i686, the others were added blindly
with the help of machine maintainers. Should be OK.
OK?
2013-04-09 Carlos O'Donell <carlos@redhat.com>
* math/libm-test.inc (cos_test): Fix PI/2 test.
(sincos_test): Likewise.
* sysdeps/x86_64/fpu/libm-test-ulps: Regenerate.
* sysdeps/i386/fpu/libm-test-ulps: Regenerate.
diff --git a/math/libm-test.inc b/math/libm-test.inc
index 78d2107..0049fcd 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -5330,7 +5330,31 @@ cos_test (void)
TEST_f_f (cos, M_PI_6l * 2.0, 0.5);
TEST_f_f (cos, M_PI_6l * 4.0, -0.5);
- TEST_f_f (cos, M_PI_2l, 0);
+
+ /* The value of M_PI_2l is never exactly PI/2, and therefore the
+ answer is never exactly zero. The answer is equal to the error
+ in rounding PI/2 for the type used. Thus the answer is unique
+ to each type. */
+#ifdef TEST_FLOAT
+ /* 32-bit float. */
+ TEST_f_f (cos, M_PI_2l, -4.371139000186241438857289400265215e-8L);
+#endif
+#if defined TEST_DOUBLE || (defined TEST_LDOUBLE && LDBL_MANT_DIG == 53)
+ /* 64-bit double or 64-bit long double. */
+ TEST_f_f (cos, M_PI_2l, 6.123233995736765886130329661375001e-17L);
+#endif
+#if defined TEST_LDOUBLE && LDBL_MANT_DIG == 64
+ /* 96-bit long double. */
+ TEST_f_f (cos, M_PI_2l, -2.50827880633416601177866354016537e-20L);
+#endif
+#if defined TEST_LDOUBLE && LDBL_MANT_DIG == 106
+ /* 128-bit IBM long double. */
+ TEST_f_f (cos, M_PI_2l, 1.082856673921913968223746169860580e-32L);
+#endif
+#if defined TEST_LDOUBLE && LDBL_MANT_DIG == 113
+ /* 128-bit long double. */
+ TEST_f_f (cos, M_PI_2l, 4.335905065061890512398522013021675e-35L);
+#endif
TEST_f_f (cos, 0.75L, 0.731688868873820886311838753000084544L);
@@ -12134,7 +12158,31 @@ sincos_test (void)
TEST_extra (sincos, minus_infty, qnan_value, qnan_value, INVALID_EXCEPTION);
TEST_extra (sincos, qnan_value, qnan_value, qnan_value);
- TEST_extra (sincos, M_PI_2l, 1, 0);
+ /* The value of M_PI_2l is never exactly PI/2, and therefore the
+ answer is never exactly zero. The answer is equal to the error
+ in rounding PI/2 for the type used. Thus the answer is unique
+ to each type. */
+#ifdef TEST_FLOAT
+ /* 32-bit float. */
+ TEST_extra (sincos, M_PI_2l, 1, -4.371139000186241438857289400265215e-8L);
+#endif
+#if defined TEST_DOUBLE || (defined TEST_LDOUBLE && LDBL_MANT_DIG == 53)
+ /* 64-bit double or 64-bit long double. */
+ TEST_extra (sincos, M_PI_2l, 1, 6.123233995736765886130329661375001e-17L);
+#endif
+#if defined TEST_LDOUBLE && LDBL_MANT_DIG == 64
+ /* 96-bit long double. */
+ TEST_extra (sincos, M_PI_2l, 1, -2.50827880633416601177866354016537e-20L);
+#endif
+#if defined TEST_LDOUBLE && LDBL_MANT_DIG == 106
+ /* 128-bit IBM long double. */
+ TEST_extra (sincos, M_PI_2l, 1, 1.082856673921913968223746169860580e-32L);
+#endif
+#if defined TEST_LDOUBLE && LDBL_MANT_DIG == 113
+ /* 128-bit long double. */
+ TEST_extra (sincos, M_PI_2l, 1, 4.335905065061890512398522013021675e-35L);
+#endif
+
TEST_extra (sincos, M_PI_6l, 0.5, 0.86602540378443864676372317075293616L);
TEST_extra (sincos, M_PI_6l*2.0, 0.86602540378443864676372317075293616L, 0.5);
TEST_extra (sincos, 0.75L, 0.681638760023334166733241952779893935L, 0.731688868873820886311838753000084544L);
diff --git a/sysdeps/i386/fpu/libm-test-ulps b/sysdeps/i386/fpu/libm-test-ulps
index 4de455c..fecaa94 100644
--- a/sysdeps/i386/fpu/libm-test-ulps
+++ b/sysdeps/i386/fpu/libm-test-ulps
@@ -4149,13 +4149,6 @@ idouble: 2
ifloat: 1
ildouble: 1
ldouble: 1
-Test "cos (pi/2) == 0":
-double: 1
-float: 1
-idouble: 1
-ifloat: 1
-ildouble: 1
-ldouble: 1
# cos_downward
Test "cos_downward (1) == 0.5403023058681397174009366074429766037323":
@@ -5513,13 +5506,6 @@ idouble: 1
ifloat: 1
ildouble: 1
ldouble: 1
-Test "sincos (pi/2, &sin_res, &cos_res) puts 0 in cos_res":
-double: 1
-float: 1
-idouble: 1
-ifloat: 1
-ildouble: 1
-ldouble: 1
# sinh
Test "sinh (0.75) == 0.822316731935829980703661634446913849":
diff --git a/sysdeps/x86_64/fpu/libm-test-ulps b/sysdeps/x86_64/fpu/libm-test-ulps
index 28f4bfc..9c9c473 100644
--- a/sysdeps/x86_64/fpu/libm-test-ulps
+++ b/sysdeps/x86_64/fpu/libm-test-ulps
@@ -4717,13 +4717,6 @@ idouble: 2
ifloat: 1
ildouble: 1
ldouble: 1
-Test "cos (pi/2) == 0":
-double: 1
-float: 1
-idouble: 1
-ifloat: 1
-ildouble: 1
-ldouble: 1
# cos_downward
Test "cos_downward (1) == 0.5403023058681397174009366074429766037323":
@@ -5984,13 +5977,6 @@ idouble: 1
ifloat: 1
ildouble: 1
ldouble: 1
-Test "sincos (pi/2, &sin_res, &cos_res) puts 0 in cos_res":
-double: 1
-float: 1
-idouble: 1
-ifloat: 1
-ildouble: 1
-ldouble: 1
Test "sincos (pi/6, &sin_res, &cos_res) puts 0.86602540378443864676372317075293616 in cos_res":
float: 1
ifloat: 1
---
Cheers,
Carlos.