From 80df05a11cc138d18d989a5f8f690627026e3069 Mon Sep 17 00:00:00 2001 From: Raymond Toy <toy.raymond@gmail.com> Date: Fri, 15 Aug 2014 22:41:26 -0700 Subject: [PATCH] Make cosh signal overflow when it should overflow. * lisp/e_cosh.c: * The compiler replaced the code huge*huge with infinity instead of doing the operation. Change it so it does fabs(x)*huge, which forces the compiler to do the multiplication. * Change huge from 1e300 to 1e307 so that fabs(x)*huge will actually overflow when |x| > overflowthreshold. * tests/trig.lisp: * Add tests for sinh and cosh signaling overflow appropriately. * general-info/release-20f.txt: * Update. --- src/general-info/release-20f.txt | 2 ++ src/lisp/e_cosh.c | 6 +++--- tests/trig.lisp | 10 ++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/general-info/release-20f.txt b/src/general-info/release-20f.txt index 92df6faa0..7179f1f07 100644 --- a/src/general-info/release-20f.txt +++ b/src/general-info/release-20f.txt @@ -62,6 +62,8 @@ New in this release: DEFINE-CONDITION. (From Helmut Eller.) * The lisp executable is now compiled to use SSE2 on x86 machines; CMUCL will not run on chips without SSE2 anymore. + * (cosh 1000d0) signals an overflow error as it + should. Previously, it just incorrectly returned infinity. * ANSI compliance fixes: * The values on the branch cuts for the inverse trig and diff --git a/src/lisp/e_cosh.c b/src/lisp/e_cosh.c index 28b6c3c4f..1d2ac3078 100644 --- a/src/lisp/e_cosh.c +++ b/src/lisp/e_cosh.c @@ -35,9 +35,9 @@ #include "fdlibm.h" #ifdef __STDC__ -static const double one = 1.0, half=0.5, huge = 1.0e300; +static const double one = 1.0, half=0.5, huge = 1.0e307; #else -static double one = 1.0, half=0.5, huge = 1.0e300; +static double one = 1.0, half=0.5, huge = 1.0e307; #endif #ifdef __STDC__ @@ -91,5 +91,5 @@ static double one = 1.0, half=0.5, huge = 1.0e300; } /* |x| > overflowthresold, cosh(x) overflow */ - return huge*huge; + return fabs(x)*huge; } diff --git a/tests/trig.lisp b/tests/trig.lisp index 695c50de0..4f1584869 100644 --- a/tests/trig.lisp +++ b/tests/trig.lisp @@ -791,3 +791,13 @@ (get-signs (atanh-def #c(2d0 +1d-20))) (assert-true (check-signs #'atanh #c(2d0 0d0) tr ti)) (assert-true (check-signs #'atanh #c(2w0 0w0) tr ti)))) + +(define-test cosh.overflow + (:tag :cosh) + (assert-error 'floating-point-overflow + (cosh 1000d0))) + +(define-test sinh.overflow + (:tag :sinh) + (assert-error 'floating-point-overflow + (sinh 1000d0))) \ No newline at end of file -- GitLab