Raymond Toy pushed to branch issue-425-correctly-rounded-math-functions-single-float at cmucl / cmucl Commits: d2210864 by Raymond Toy at 2026-02-16T14:31:08-08:00 Fix #473: Signal underflow with cr_exp Explicitly signal underflow (if enabled) when calling `kernel:%exp` with an arg that would cause exp to underflow. The constant used is taken from the source code for core-math exp.c. Update the in fdlibm to use `with-float-traps-enabled` instead of the weird way we were doing it. - - - - - c84c6c27 by Raymond Toy at 2026-02-16T18:52:48-08:00 Make core-math exp silently return NaN when given NaN This makes exp match what many other core-math routines do with NaN, like log, sin, tan, and sinh, which silently return NaN. This also makes it match what fdlibm does, as mentioned in the comments in e_exp.c. - - - - - 72096452 by Raymond Toy at 2026-02-17T10:51:19-08:00 Merge branch 'master' into issue-473-make-cr-exp-signal-underflow - - - - - 7fa0f3c1 by Raymond Toy at 2026-02-17T19:59:33-08:00 Merge branch 'issue-473-make-cr-exp-signal-underflow' into issue-425-correctly-rounded-math-functions-single-float - - - - - 2 changed files: - src/lisp/irrat.c - tests/fdlibm.lisp Changes: ===================================== src/lisp/irrat.c ===================================== @@ -62,7 +62,7 @@ extern void cr_sincosf(float, float *, float *); */ #define MAYBE_SIGNAL_INVALID(test, val) \ - if ((test)) { \ + if ((test)) { \ return fdlibm_setexception(val, FDLIBM_INVALID); \ } @@ -221,6 +221,27 @@ double lisp_exp(double x) { #ifdef FEATURE_CORE_MATH + /* + * For consistency, silently return NaN when x is NaN. Do not + * signal an invalid operation, even if invalid operation trap is + * enabled. This is what fdlibm does, and also what many of the + * other core-math routines do. + */ + + if (isnan(x)) { + return x; + } + + /* + * Can't depend on cr_exp to signal underflow. It seems the + * underflow has been constant-folded to zero. Hence, check for + * underflow here and explicitly signal an underflow. The + * constant here is from core-math exp.c. + */ + if (x <= -0x1.74910d52d3052p+9) { + return fdlibm_setexception(0.0, FDLIBM_UNDERFLOW); + } + return cr_exp(x); #else return __ieee754_exp(x); ===================================== tests/fdlibm.lisp ===================================== @@ -420,13 +420,9 @@ (ext:with-float-traps-masked (:overflow) (assert-equal ext:double-float-positive-infinity (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))) + (ext:with-float-traps-enabled (:underflow) + (assert-error 'floating-point-underflow + (kernel:%exp -1000d0))) (let ((x (scale-float 1d0 -29)) (x0 0d0)) ;; exp(x) = x, |x| < 2^-28, with inexact exception unlees x = 0 View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/6f4d5ebb83aba92d1cc3b7b... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/6f4d5ebb83aba92d1cc3b7b... You're receiving this email because of your account on gitlab.common-lisp.net.