summaryrefslogtreecommitdiff
path: root/mpfr-test.h
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2002-04-18 09:47:02 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2002-04-18 09:47:02 +0000
commitb72900d53312039e32aee00c7f9660966c7c2d4f (patch)
tree41b905959752cc2e1c80cb77fce2c48a1cd4cf3b /mpfr-test.h
parentaf9e26c91fc740a04c5cbb911a1aa4b9ab40fb0c (diff)
downloadmpfr-b72900d53312039e32aee00c7f9660966c7c2d4f.tar.gz
improved ulp() to deal with infinities
and fixed tadd/check2 to deal with infinities git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1894 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'mpfr-test.h')
-rw-r--r--mpfr-test.h16
1 files changed, 9 insertions, 7 deletions
diff --git a/mpfr-test.h b/mpfr-test.h
index 6b87c6e15..fc38baffa 100644
--- a/mpfr-test.h
+++ b/mpfr-test.h
@@ -140,16 +140,18 @@ Ulp (double x)
return (eps > y) ? 0.5 * eps : eps;
}
-/* returns the number of ulp's between a and b */
+/* returns the number of ulp's between a and b,
+ where a and b can be any floating-point number, except NaN
+ */
int
ulp (double a, double b)
{
- if (a==0.0) {
- if (b==0.0) return 0;
- else if (b<0.0) return 2147483647;
- else return -2147483647;
- }
- return (a-b)/Ulp(a);
+ if (a == b) return 0; /* also deals with a=b=inf or -inf */
+
+ if (a + a == a) /* a is +/-0.0 or +/-Inf */
+ return ((b < a) ? 2147483647 : -2147483647);
+
+ return (a - b) / Ulp (a);
}
/* return double m*2^e */