Raymond Toy pushed to branch master at cmucl / cmucl
Commits:
-
9bf28346
by Raymond Toy at 2026-02-18T07:18:07-08:00
-
b26718dd
by Raymond Toy at 2026-02-18T07:18:07-08:00
2 changed files:
Changes:
| ... | ... | @@ -40,7 +40,7 @@ extern void cr_sincos(double, double *, double *); |
| 40 | 40 | */
|
| 41 | 41 | |
| 42 | 42 | #define MAYBE_SIGNAL_INVALID(test, val) \
|
| 43 | - if ((test)) { \
|
|
| 43 | + if ((test)) { \
|
|
| 44 | 44 | return fdlibm_setexception(val, FDLIBM_INVALID); \
|
| 45 | 45 | }
|
| 46 | 46 | |
| ... | ... | @@ -197,6 +197,27 @@ double |
| 197 | 197 | lisp_exp(double x)
|
| 198 | 198 | {
|
| 199 | 199 | #ifdef FEATURE_CORE_MATH
|
| 200 | + /*
|
|
| 201 | + * For consistency, silently return NaN when x is NaN. Do not
|
|
| 202 | + * signal an invalid operation, even if invalid operation trap is
|
|
| 203 | + * enabled. This is what fdlibm does, and also what many of the
|
|
| 204 | + * other core-math routines do.
|
|
| 205 | + */
|
|
| 206 | + |
|
| 207 | + if (isnan(x)) {
|
|
| 208 | + return x;
|
|
| 209 | + }
|
|
| 210 | +
|
|
| 211 | + /*
|
|
| 212 | + * Can't depend on cr_exp to signal underflow. It seems the
|
|
| 213 | + * underflow has been constant-folded to zero. Hence, check for
|
|
| 214 | + * underflow here and explicitly signal an underflow. The
|
|
| 215 | + * constant here is from core-math exp.c.
|
|
| 216 | + */
|
|
| 217 | + if (x <= -0x1.74910d52d3052p+9) {
|
|
| 218 | + return fdlibm_setexception(0.0, FDLIBM_UNDERFLOW);
|
|
| 219 | + }
|
|
| 220 | + |
|
| 200 | 221 | return cr_exp(x);
|
| 201 | 222 | #else
|
| 202 | 223 | return __ieee754_exp(x);
|
| ... | ... | @@ -210,13 +210,9 @@ |
| 210 | 210 | (ext:with-float-traps-masked (:overflow)
|
| 211 | 211 | (assert-equal ext:double-float-positive-infinity
|
| 212 | 212 | (kernel:%exp 710d0)))
|
| 213 | - (let ((modes (ext:get-floating-point-modes)))
|
|
| 214 | - (unwind-protect
|
|
| 215 | - (progn
|
|
| 216 | - (ext:set-floating-point-modes :traps '(:underflow))
|
|
| 217 | - (assert-error 'floating-point-underflow
|
|
| 218 | - (kernel:%exp -1000d0)))
|
|
| 219 | - (apply #'ext:set-floating-point-modes modes)))
|
|
| 213 | + (ext:with-float-traps-enabled (:underflow)
|
|
| 214 | + (assert-error 'floating-point-underflow
|
|
| 215 | + (kernel:%exp -1000d0)))
|
|
| 220 | 216 | (let ((x (scale-float 1d0 -29))
|
| 221 | 217 | (x0 0d0))
|
| 222 | 218 | ;; exp(x) = x, |x| < 2^-28, with inexact exception unlees x = 0
|