Raymond Toy pushed to branch issue-277-float-ratio-float-least-positive-float at cmucl / cmucl
Commits: 6aec95c6 by Raymond Toy at 2024-02-11T11:33:57-08:00 Disable FP underflow before running tests
These small numbers are new the least floats, which would signal an underflow. Make sure we disable the FP underflow trap.
- - - - -
1 changed file:
- tests/float.lisp
Changes:
===================================== tests/float.lisp ===================================== @@ -142,20 +142,22 @@ ;; some rationals from 7/10*10^-45 to 1.41*10^-45 to make sure they ;; return 0 or least-positive-single-float (let ((expo (expt 10 -45))) - ;; 7/10*10^-45 is just under halfway between 0 and least-positive, - ;; so the answer is 0. - (assert-equal 0f0 (kernel::float-ratio-float (* 7/10 expo) 'single-float)) - - ;; These are all more than half way to - ;; least-positive-single-float, so they should return that. - (assert-equal least-positive-single-float - (kernel::float-ratio-float (* 8/10 expo) 'single-float)) - (assert-equal least-positive-single-float - (kernel::float-ratio-float (* 1 expo) 'single-float)) - (assert-equal least-positive-single-float - (kernel::float-ratio-float (* 14/10 expo) 'single-float)) - (assert-equal least-positive-single-float - (kernel::float-ratio-float (* 2 expo) 'single-float)))) + ;; Need to make sure underflows are masked. + (kernel::with-float-traps-masked (:underflow) + ;; 7/10*10^-45 is just under halfway between 0 and least-positive, + ;; so the answer is 0. + (assert-equal 0f0 (kernel::float-ratio-float (* 7/10 expo) 'single-float)) + + ;; These are all more than half way to + ;; least-positive-single-float, so they should return that. + (assert-equal least-positive-single-float + (kernel::float-ratio-float (* 8/10 expo) 'single-float)) + (assert-equal least-positive-single-float + (kernel::float-ratio-float (* 1 expo) 'single-float)) + (assert-equal least-positive-single-float + (kernel::float-ratio-float (* 14/10 expo) 'single-float)) + (assert-equal least-positive-single-float + (kernel::float-ratio-float (* 2 expo) 'single-float)))))
(define-test float-ratio.double (:tag :issues) @@ -163,18 +165,20 @@ ;; test with some rationals from about 2*10^-324 to 4.94*10^-324 to make ;; sure they return 0 or least-positive-double-float (let ((expo (expt 10 -324))) - ;; 247/100*10^-45 is just under halfway between 0 and least-positive, - ;; so the answer is 0. - (assert-equal 0d0 (kernel::float-ratio-float (* 247/100 expo) 'double-float)) - - ;; These are all more than half way to - ;; least-positive-double-float, so they should return that. - (assert-equal least-positive-double-float - (kernel::float-ratio-float (* 248/100 expo) 'double-float)) - (assert-equal least-positive-double-float - (kernel::float-ratio-float (* 4 expo) 'double-float)) - (assert-equal least-positive-double-float - (kernel::float-ratio-float (* 494/100 expo) 'double-float)) - (assert-equal least-positive-double-float - (kernel::float-ratio-float (* 988/100 expo) 'double-float)))) + ;; Need to make sure underflows are masked. + (kernel::with-float-traps-masked (:underflow) + ;; 247/100*10^-324 is just under halfway between 0 and least-positive, + ;; so the answer is 0. + (assert-equal 0d0 (kernel::float-ratio-float (* 247/100 expo) 'double-float)) + + ;; These are all more than half way to + ;; least-positive-double-float, so they should return that. + (assert-equal least-positive-double-float + (kernel::float-ratio-float (* 248/100 expo) 'double-float)) + (assert-equal least-positive-double-float + (kernel::float-ratio-float (* 4 expo) 'double-float)) + (assert-equal least-positive-double-float + (kernel::float-ratio-float (* 494/100 expo) 'double-float)) + (assert-equal least-positive-double-float + (kernel::float-ratio-float (* 988/100 expo) 'double-float)))))
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/6aec95c6d40e6e83bfcb1b2c...