Raymond Toy pushed to branch issue-425-correctly-rounded-math-functions-single-float at cmucl / cmucl Commits: 696befd2 by Raymond Toy at 2026-02-17T17:36:10-08:00 Add tests for %expf based on %exp Basic conversion of the tests for %exp. Just needed to adjust some of the limits. And for whatever reason, cr_expf does signal underflow, unlike cr_exp - - - - - 089707d3 by Raymond Toy at 2026-02-17T17:38:51-08:00 Add tests for %logf based on %log Basic conversion of the tests for %exp; nothing special needed. - - - - - 6f4d5ebb by Raymond Toy at 2026-02-17T17:50:41-08:00 Add tests for %acosf, %asinf, %atanf, %log10f Basic translation of existing tests. Nothing special needed. - - - - - 1 changed file: - tests/fdlibm.lisp Changes: ===================================== tests/fdlibm.lisp ===================================== @@ -440,6 +440,39 @@ (assert-error 'floating-point-inexact (kernel:%exp x))))) +(define-test %expf.exceptions + (:tag :fdlibm) + (assert-error 'floating-point-overflow + (kernel:%expf 89f0)) + (assert-true (ext:float-nan-p (kernel:%expf *qnan-single-float*))) + (assert-error 'floating-point-invalid-operation + (kernel:%expf *snan-single-float*)) + (assert-equal ext:single-float-positive-infinity + (kernel:%expf ext:single-float-positive-infinity)) + (assert-equal 0f0 + (kernel:%expf -200f0)) + (ext:with-float-traps-masked (:overflow) + (assert-equal ext:single-float-positive-infinity + (kernel:%expf 89f0))) + (ext:with-float-traps-enabled (:underflow) + (assert-error 'floating-point-underflow + (kernel:%expf -200f0))) + + (let ((x (scale-float 1f0 -13)) + (x0 0f0)) + ;; exp(x) = 1 + x, |x| < 2^-12, with inexact exception unlees x = + ;; 0. The actual threshold is closer to sqrt(2*eps) or about + ;; 2.44e-4, about 2^-12 + (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 1f0 (kernel:%expf 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:%expf x))))) + (define-test %log.exception (:tag :fdlibm) (assert-error 'division-by-zero @@ -460,6 +493,26 @@ (assert-true (ext:float-nan-p (kernel:%log -1d0))) (assert-true (ext:float-nan-p (kernel:%log *snan*))))) +(define-test %logf.exception + (:tag :fdlibm) + (assert-error 'division-by-zero + (kernel:%logf 0f0)) + (assert-error 'division-by-zero + (kernel:%logf -0f0)) + (assert-error 'floating-point-invalid-operation + (kernel:%logf -1f0)) + (assert-error 'floating-point-invalid-operation + (kernel:%logf *snan-single-float*)) + (assert-true (ext:float-nan-p (kernel:%logf *qnan-single-float*))) + (ext:with-float-traps-masked (:divide-by-zero) + (assert-equal ext:single-float-negative-infinity + (kernel:%logf 0f0)) + (assert-equal ext:single-float-negative-infinity + (kernel:%logf -0f0))) + (ext:with-float-traps-masked (:invalid) + (assert-true (ext:float-nan-p (kernel:%logf -1f0))) + (assert-true (ext:float-nan-p (kernel:%logf *snan-single-float*))))) + (define-test %acos.exceptions (:tag :fdlibm) (assert-error 'floating-point-invalid-operation @@ -470,6 +523,16 @@ (assert-true (ext:float-nan-p (kernel:%acos 2d0))) (assert-true (ext:float-nan-p (kernel:%acos -2d0))))) +(define-test %acosf.exceptions + (:tag :fdlibm) + (assert-error 'floating-point-invalid-operation + (kernel:%acosf 2f0)) + (assert-error 'floating-point-invalid-operation + (kernel:%acosf -2f0)) + (ext:with-float-traps-masked (:invalid) + (assert-true (ext:float-nan-p (kernel:%acosf 2f0))) + (assert-true (ext:float-nan-p (kernel:%acosf -2f0))))) + (define-test %asin.exceptions (:tag :fdlibm) (assert-error 'floating-point-invalid-operation @@ -480,6 +543,16 @@ (assert-true (ext:float-nan-p (kernel:%asin 2d0))) (assert-true (ext:float-nan-p (kernel:%asin -2d0))))) +(define-test %asinf.exceptions + (:tag :fdlibm) + (assert-error 'floating-point-invalid-operation + (kernel:%asinf 2f0)) + (assert-error 'floating-point-invalid-operation + (kernel:%asinf -2f0)) + (ext:with-float-traps-masked (:invalid) + (assert-true (ext:float-nan-p (kernel:%asinf 2f0))) + (assert-true (ext:float-nan-p (kernel:%asinf -2f0))))) + (define-test %atan.exceptions (:tag :fdlibm) (assert-error 'floating-point-invalid-operation @@ -500,6 +573,26 @@ (assert-error 'floating-point-inexact (kernel:%atan x))))) +(define-test %atanf.exceptions + (:tag :fdlibm) + (assert-error 'floating-point-invalid-operation + (kernel:%atanf *snan-single-float*)) + (assert-true (ext:float-nan-p (kernel:%atanf *qnan-single-float*))) + (ext:with-float-traps-masked (:invalid) + (assert-true (ext:float-nan-p (kernel:%atanf *snan-single-float*)))) + ;; atan(x) = x for small x, signaling inexact except when x = 0. + (let ((x (scale-float 1f0 -30)) + (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:%atanf 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:%atanf x))))) + (define-test %log10.exceptions (:tag :fdlibm) ;; %log10(2^k) = k @@ -521,6 +614,27 @@ (ext:with-float-traps-masked (:invalid) (assert-true (ext:float-nan-p (kernel:%log10 -1d0))))) +(define-test %log10f.exceptions + (:tag :fdlibm) + ;; %log10(2^k) = k + (dotimes (k 23) + (assert-equalp k + (kernel:%log10f (float (expt 10 k) 1f0)))) + (assert-error 'division-by-zero + (kernel:%log10f 0f0)) + (assert-error 'floating-point-invalid-operation + (kernel:%log10f -1f0)) + (assert-true (ext:float-nan-p (kernel:%log10f *qnan-single-float*))) + (assert-equal ext:single-float-positive-infinity + (kernel:%log10f ext:single-float-positive-infinity)) + (ext:with-float-traps-masked (:divide-by-zero) + (assert-equal ext:single-float-negative-infinity + (kernel:%log10f 0f0)) + (assert-equal ext:single-float-negative-infinity + (kernel:%log10f -0f0))) + (ext:with-float-traps-masked (:invalid) + (assert-true (ext:float-nan-p (kernel:%log10f -1f0))))) + (define-test %scalbn.exceptions (:tag :fdlibm) (let ((modes (ext:get-floating-point-modes))) View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/2ab4931b78072be1ba69976... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/2ab4931b78072be1ba69976... You're receiving this email because of your account on gitlab.common-lisp.net.
participants (1)
-
Raymond Toy (@rtoy)