summaryrefslogtreecommitdiff
path: root/tests/mpfr-test.h
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2017-09-15 11:51:18 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2017-09-15 11:51:18 +0000
commitf96e3b4fa7037fa401aa1b648443df5efd48e5af (patch)
tree625e8e18642a689141732ee5da77c27407b8d954 /tests/mpfr-test.h
parent6c017f6f1cbbf9843a5412249bf345a61d235de6 (diff)
downloadmpfr-f96e3b4fa7037fa401aa1b648443df5efd48e5af.tar.gz
[tests] Solve issues with the incorrect use of mpfr_sgn, and make sure
that this cannot happen again without being detected: on zero, +1 or -1 was sometimes expected to check the sign of zero, but mpfr_sgn actually returned 0, so that the check always succeeded whatever the sign of the null result. * mpfr-test.h: define a new mpfr_sgn macro that fails when used on NaN or zero (whose sign is not +1 or -1), except when MPFR_TESTS_TSGN is defined. * tacos.c, tasin.c, tasinh.c, tatanh.c, tcbrt.c, tdim.c, terf.c, texp.c, texp10.c, texp2.c, texpm1.c, tset.c, tset_str.c: replaced the incorrect use of mpfr_sgn; some other related improvements. Note: in tset.c, a "mpfr_sgn (x) < 0" test had to be replaced by "MPFR_IS_POS (x)" since we really want to test whether the sign is positive (not negative). * tdiv.c, tmul.c, tui_div.c: simplified some tests, in particular to avoid a failure with the new mpfr_sgn macro for the tests; here, the use of mpfr_sgn was correct, but one could do simpler. * tgmpop.c: replaced "mpfr_sgn (z)" by "(mpfr_sgn) (z)" to avoid the new mpfr_sgn macro (here, we really want the mathematical sign). * tsgn.c: define MPFR_TESTS_TSGN as the goal of this program is to test mpfr_sgn itself (both the function and the macro in mpfr.h). git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@11755 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/mpfr-test.h')
-rw-r--r--tests/mpfr-test.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/mpfr-test.h b/tests/mpfr-test.h
index f4d452f39..7bcc15f37 100644
--- a/tests/mpfr-test.h
+++ b/tests/mpfr-test.h
@@ -85,6 +85,25 @@ extern "C" {
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define ABS(x) (((x)>0) ? (x) : -(x))
+/* In the tests, mpfr_sgn was sometimes used incorrectly, for instance:
+ *
+ * if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) < 0)
+ *
+ * to check that y is +0. This does not make sense since on 0, mpfr_sgn
+ * yields 0, so that -0 would not be detected as an error. To make sure
+ * that mpfr_sgn is not used incorrectly, we choose to fail when this
+ * macro is used on a datum whose mathematical sign is not +1 or -1.
+ * This feature is disabled when MPFR_TESTS_TSGN is defined, typically
+ * in tsgn (to test mpfr_sgn itself).
+ */
+#ifndef MPFR_TESTS_TSGN
+# undef mpfr_sgn
+# define mpfr_sgn(x) \
+ (MPFR_ASSERTN (! MPFR_IS_NAN (x)), \
+ MPFR_ASSERTN (! MPFR_IS_ZERO (x)), \
+ MPFR_SIGN (x))
+#endif
+
#define FLIST mpfr_ptr, mpfr_srcptr, mpfr_rnd_t
int test_version (void);