Raymond Toy pushed to branch issue-425-correctly-rounded-math-functions-single-float at cmucl / cmucl Commits: 18826ba4 by Raymond Toy at 2026-02-17T14:39:50-08:00 Add tests for %sinhf, based on %sinh - - - - - 11aada66 by Raymond Toy at 2026-02-17T14:45:19-08:00 Add tests for %sinhf based on %sinh Didn't need to do anything really special except the test for inexact can have a larger value since we only have single-float precision. - - - - - c916a9f7 by Raymond Toy at 2026-02-17T14:59:29-08:00 Add tests for %tanhf based on tanh Didn't need to do anything really special except the test for inexact can have a smaller value since we only have single-float precision. - - - - - 1 changed file: - tests/fdlibm.lisp Changes: ===================================== tests/fdlibm.lisp ===================================== @@ -115,6 +115,45 @@ (assert-error 'floating-point-inexact (kernel:%sinh x))))) +(define-test %sinhf.exceptions + (:tag :fdlibm) + (assert-error 'floating-point-overflow + (kernel:%sinhf 100f0)) + (assert-error 'floating-point-overflow + (kernel:%sinhf -100f0)) + (assert-error 'floating-point-invalid-operation + (kernel:%sinhf *snan-single-float*)) + (assert-true (ext:float-nan-p (kernel:%sinhf *qnan-single-float*))) + + ;; Same, but with overflow's masked + (ext:with-float-traps-masked (:overflow) + (assert-equal ext:single-float-positive-infinity + (kernel:%sinhf 100f0)) + (assert-equal ext:single-float-negative-infinity + (kernel:%sinhf -100f0)) + (assert-equal ext:single-float-positive-infinity + (kernel:%sinhf ext:single-float-positive-infinity)) + (assert-equal ext:single-float-negative-infinity + (kernel:%sinhf ext:single-float-negative-infinity))) + ;; Test NaN + (ext:with-float-traps-masked (:invalid) + (assert-true (ext:float-nan-p (kernel:%sinhf *qnan-single-float*)))) + ;; sinh(x) = x + x^3/6 + o(x^3). Thus, if |x| < 2^-17, sinh(x) = x, + ;; but we should signal inexact except if x is 0. We're not trying + ;; to get the exact value where sinh(x) = x. Just something + ;; obviously small enough. + (let ((x (scale-float 1f0 -29)) + (x0 0f0)) + (ext:with-float-traps-enabled (:inexact) + ;; This must not throw an inexact exception because the result + ;; is exact when the arg is 0. + (assert-eql 0f0 (kernel:%sinhf x0))) + (ext:with-float-traps-enabled (:inexact) + ;; This must throw an inexact exception for non-zero x even + ;; though the result is exactly x. + (assert-error 'floating-point-inexact + (kernel:%sinhf x))))) + (define-test %tanh.exceptions (:tag :fdlibm) (assert-true (ext:float-nan-p (kernel:%tanh *qnan*))) @@ -130,6 +169,23 @@ (assert-error 'floating-point-inexact (kernel:%tanh x))))) +(define-test %tanhf.exceptions + (:tag :fdlibm) + (assert-true (ext:float-nan-p (kernel:%tanhf *qnan-single-float*))) + (assert-error 'floating-point-invalid-operation + (kernel:%tanhf *snan-single-float*)) + (ext:with-float-traps-masked (:invalid) + (assert-true (ext:float-nan-p (kernel:%tanhf *snan-single-float*)))) + ;; tanhf(x) = +/- 1 for |x| > 9.1, raising inexact, always. The + ;; exact value from cr_tanhf appears to be 0x41102cb3u. That is + ;; 9.010913. + (let ((x 9.1f0)) + (ext:with-float-traps-enabled (:inexact) + ;; This must throw an inexact exception for non-zero x even + ;; though the result is exactly x. + (assert-error 'floating-point-inexact + (kernel:%tanhf x))))) + (define-test %acosh.exceptions (:tag :fdlibm) (assert-error 'floating-point-overflow View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/3e89a81cdee2de0d0f444d6... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/3e89a81cdee2de0d0f444d6... You're receiving this email because of your account on gitlab.common-lisp.net.