Raymond Toy pushed to branch issue-293-restart-on-reader-fp-overflow at cmucl / cmucl
Commits: f3e5a7e6 by Raymond Toy at 2024-03-23T12:13:54-07:00 Fix #287: Clean up make-float-aux
We don't need to try to round small numbers to least positive float here. When #277 was fixed, this was taken care of. Hence we can remove all the code for that and just throw a reader-error immediately if the result is 0 but the number is not zero.
- - - - - 9d01b5ca by Raymond Toy at 2024-03-23T12:38:44-07:00 Oops. Need handler-case to catch errors from large numbers.
For large numbers that weren't caught the with the rough check, the conversion of the large ratio to a float signals a `simple-type-error` from `coerce`. We need to catch that and signal a `reader-error`.
- - - - - 01857e1c by Raymond Toy at 2024-03-23T14:39:01-07:00 Fix #275: Signal underflow for denormals
If the floating-point underflow trap is enabled, signal an underflow error when the number would underflow to a denormal. We still signal a reader-error if the number would not fit in a float.
- - - - - 45532060 by Raymond Toy at 2024-03-23T14:56:58-07:00 Add tests for float underflows in the reader
- - - - - 23f449e4 by Raymond Toy at 2024-03-26T07:46:47-07:00 Merge branch 'master' into issue-275b-signal-float-underflow
- - - - - 488cbe98 by Raymond Toy at 2024-03-26T07:47:46-07:00 Add a comment about continuing with 0
- - - - - bb8eb44c by Raymond Toy at 2024-03-26T08:25:46-07:00 Fix bad merge
Actually need to remove `with-float-traps-masked`. Duh!
- - - - - ba400bf5 by Raymond Toy at 2024-03-29T07:11:07-07:00 Signal reader-error on underflow instead of FP underflow.
The error message makes it clear we have a FP underflow like so: ``` * 1d-308
Reader error on #<Two-Way Stream, Input = #<Synonym Stream to SYSTEM:*STDIN*>, Output = #<Synonym Stream to SYSTEM:*STDOUT*>>: Underflow when reading "1d-308" [Condition of type READER-ERROR]
Restarts: 0: [CONTINUE] Return 0.0d0 1: [ABORT ] Return to Top-Level.
```
- - - - - f3d64ced by Raymond Toy at 2024-03-29T07:16:02-07:00 Change message to mention floating point
Instead of just saying "Underflow when reading...", say "Floating point underflow when reading..." to make it a bit clearer what happened.
- - - - - 4ba5145d by Raymond Toy at 2024-03-29T07:20:32-07:00 Undo some space changes and correct a comment.
Undo some tab vs space changes at the end of make-float-aux.
The comment about double-float exponent range was in the wrong place so put it in the right place.
- - - - - e1a35617 by Raymond Toy at 2024-03-29T07:55:55-07:00 Test FP underflow signals reader-error
We now signal a `reader-error` on a FP underflow. Thus, test that we get a reader error. Also test that the message says we got an underflow. This is to verify that we tell the user that it's an underflow and not some other reader error.
- - - - - 031b5ce0 by Raymond Toy at 2024-03-29T07:58:47-07:00 Update pot file for updated message string.
- - - - - 047a0f08 by Raymond Toy at 2024-03-29T08:00:08-07:00 Add comment on where the expected string comes from.
- - - - - ca07a140 by Raymond Toy at 2024-03-29T15:45:54-07:00 Merge branch 'master' into issue-275b-signal-float-underflow
- - - - - 2eda1257 by Raymond Toy at 2024-04-07T10:50:22-07:00 Change underflow message to be a bit clearer
Update the pot file due to the change in the message string.
- - - - - d9a89936 by Raymond Toy at 2024-04-07T11:03:13-07:00 Merge branch 'issue-275b-signal-float-underflow' into issue-293-restart-on-reader-fp-overflow
- - - - -
3 changed files:
- src/code/reader.lisp - src/i18n/locale/cmucl.pot - tests/float.lisp
Changes:
===================================== src/code/reader.lisp ===================================== @@ -1929,8 +1929,8 @@ the end of the stream." ;; 0. (let ((zero (coerce 0 float-format))) (restart-case - (%reader-error stream _"Floating point underflow when reading ~S" - (read-buffer-to-string)) + (%reader-error stream _"Floating point underflow when reading ~S: ~S" + float-format (read-buffer-to-string)) (continue () :report (lambda (stream) (format stream "Return ~A" zero))
===================================== src/i18n/locale/cmucl.pot ===================================== @@ -8736,7 +8736,7 @@ msgid "Underflow" msgstr ""
#: src/code/reader.lisp -msgid "Floating point underflow when reading ~S" +msgid "Floating point underflow when reading ~S: ~S" msgstr ""
#: src/code/reader.lisp
===================================== tests/float.lisp ===================================== @@ -213,6 +213,39 @@ (assert-error 'reader-error (read-from-string "1.8d308")) (assert-error 'reader-error (read-from-string "1d999999999")))
+(define-test reader.float-underflow + (:tag :issues) + (lisp::with-float-traps-enabled (:underflow) + ;; A denormal + (assert-error 'reader-error + (read-from-string "1e-40")) + (assert-error 'reader-error + (read-from-string (format nil "~A" least-positive-single-float))) + ;; The same for double-floats + (assert-error 'reader-error + (read-from-string "1d-308")) + (assert-error 'reader-error + (read-from-string (format nil "~A" least-positive-double-float))))) + +(define-test reader.float-underflow + (:tag :issues) + (lisp::with-float-traps-enabled (:underflow) + ;; The expected string comes from make-float-aux. + (let ((expected "Floating point underflow when reading ~S")) + (flet ((test-reader-underflow (string) + ;; Test that the we got a reader-error when a number + ;; would underflow and that the message says we got an + ;; underflow. + (let ((condition (nth-value 1 (ignore-errors (read-from-string string))))) + (assert-equal 'reader-error (type-of condition)) + (assert-equal expected (lisp::reader-error-format-control condition))))) + ;; Underflow single-floats + (test-reader-underflow "1e-40") + (test-reader-underflow (format nil "~A" least-positive-single-float)) + ;; Underflow double-floats + (test-reader-underflow "1d-308") + (test-reader-underflow (format nil "~A" least-positive-double-float)))))) + (define-test fp-overflow-restarts.infinity (:tag :issues) ;; Test that the "infinity" restart from reader on floating-point
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/deb940458edf3da11564476...