Raymond Toy pushed to branch issue-468-core-math-signals at cmucl / cmucl Commits: 1751d2c9 by Raymond Toy at 2026-02-02T20:51:58-08:00 Check for infinite arg for sin, cos, tan fdlibm signals overflow for infinite args for sin, cos, and tan. Do the same for core-math. Also add test that NaN is silently returned from sin, cos, and tan are given a quiet NaN. That's what fdlibm does. - - - - - 13291eab by Raymond Toy at 2026-02-02T20:58:39-08:00 Enable underflow test for exp(-1000d0) This tests passes with core-math, so enable it. - - - - - 2 changed files: - src/lisp/irrat.c - tests/fdlibm.lisp Changes: ===================================== src/lisp/irrat.c ===================================== @@ -43,6 +43,11 @@ double lisp_sin(double x) { #ifdef FEATURE_CORE_MATH + /* Signals invalid if x is infinite */ + if (isinf(x)) { + return fdlibm_setexception(x, FDLIBM_INVALID); + } + return cr_sin(x); #else return fdlibm_sin(x); @@ -53,6 +58,11 @@ double lisp_cos(double x) { #ifdef FEATURE_CORE_MATH + /* Signals invalid if x is infinite */ + if (isinf(x)) { + return fdlibm_setexception(x, FDLIBM_INVALID); + } + return cr_cos(x); #else return fdlibm_cos(x); @@ -63,6 +73,11 @@ double lisp_tan(double x) { #ifdef FEATURE_CORE_MATH + /* Signals invalid if x is infinite */ + if (isinf(x)) { + return fdlibm_setexception(x, FDLIBM_INVALID); + } + return cr_tan(x); #else return fdlibm_tan(x); ===================================== tests/fdlibm.lisp ===================================== @@ -214,7 +214,6 @@ (ext:with-float-traps-masked (:overflow) (assert-equal ext:double-float-positive-infinity (kernel:%exp 710d0))) - #-core-math (let ((modes (ext:get-floating-point-modes))) (unwind-protect (progn @@ -671,6 +670,14 @@ (define-test %cos.exceptions (:tag :fdlibm) + ;; cos(inf) signals invalid operation + (assert-error 'floating-point-invalid-operation + (kernel:%cos ext:double-float-positive-infinity)) + (assert-error 'floating-point-invalid-operation + (kernel:%cos ext:double-float-negative-infinity)) + ;; cos(nan) is NaN + (assert-true (ext:float-nan-p (kernel:%cos *qnan*))) + ;; cos(x) = 1 for |x| < 2^-27. Signal inexact unless x = 0 (let ((x (scale-float 1d0 -28)) (x0 0d0)) @@ -686,6 +693,14 @@ (define-test %sin.exceptions (:tag :fdlibm) + ;; sin(inf) signals invalid operation + (assert-error 'floating-point-invalid-operation + (kernel:%sin ext:double-float-positive-infinity)) + (assert-error 'floating-point-invalid-operation + (kernel:%sin ext:double-float-negative-infinity)) + ;; sin(nan) is NaN + (assert-true (ext:float-nan-p (kernel:%sin *qnan*))) + ;; sin(x) = x for |x| < 2^-27. Signal inexact unless x = 0 (let ((x (scale-float 1d0 -28)) (x0 0d0)) @@ -701,6 +716,14 @@ (define-test %tan.exceptions (:tag :fdlibm) + ;; tan(inf) signals invalid operation + (assert-error 'floating-point-invalid-operation + (kernel:%tan ext:double-float-positive-infinity)) + (assert-error 'floating-point-invalid-operation + (kernel:%tan ext:double-float-negative-infinity)) + ;; tan(nan) is NaN + (assert-true (ext:float-nan-p (kernel:%sin *qnan*))) + ;; tan(x) = x for |x| < 2^-28. Signal inexact unless x = 0 (let ((x (scale-float 1d0 -29)) (x0 0d0)) View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/5de13d334adb9a01c393af6... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/5de13d334adb9a01c393af6... You're receiving this email because of your account on gitlab.common-lisp.net.
participants (1)
-
Raymond Toy (@rtoy)