From df548f6e69bc4fa0aec3825d10074135c9e4ac03 Mon Sep 17 00:00:00 2001 From: Raymond Toy <toy.raymond@gmail.com> Date: Tue, 26 Aug 2014 19:07:54 -0700 Subject: [PATCH] Oops. Fix mistake in handling underflow for %exp. * src/lisp/e_exp.c: * Signal underflow instead of returning the arg. * tests/trig.lisp: * Add tests for %exp when exp underflows. --- src/lisp/e_exp.c | 5 ++++- tests/trig.lisp | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/lisp/e_exp.c b/src/lisp/e_exp.c index 034c59050..93b638e66 100644 --- a/src/lisp/e_exp.c +++ b/src/lisp/e_exp.c @@ -142,7 +142,10 @@ P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */ return fdlibm_setexception(x, FDLIBM_OVERFLOW); } - if(x < u_threshold) return x; /* underflow */ + if(x < u_threshold) { + /* underflow */ + return fdlibm_setexception(0.0, FDLIBM_UNDERFLOW); + } } /* argument reduction */ diff --git a/tests/trig.lisp b/tests/trig.lisp index 724fabe7d..cfd7ea288 100644 --- a/tests/trig.lisp +++ b/tests/trig.lisp @@ -945,9 +945,18 @@ (kernel:%exp *snan*)) (assert-equal ext:double-float-positive-infinity (kernel:%exp ext:double-float-positive-infinity)) + (assert-equal 0d0 + (kernel:%exp -1000d0)) (kernel::with-float-traps-masked (:overflow) (assert-equal ext:double-float-positive-infinity - (kernel:%exp 710d0)))) + (kernel:%exp 710d0))) + (let ((modes (ext:get-floating-point-modes))) + (unwind-protect + (progn + (ext:set-floating-point-modes :traps '(:underflow)) + (assert-error 'floating-point-underflow + (kernel:%exp -1000d0))) + (apply #'ext:set-floating-point-modes modes)))) (define-test %log.exception (:tag :fdlibm) -- GitLab