Raymond Toy pushed to branch issue-293-restart-on-reader-fp-overflow at cmucl / cmucl Commits: 142252fc by Raymond Toy at 2024-03-29T14:08:12-07:00 Add tests for the FP overflow restarts from the reader Verify that the two new restarts produce the correct values when selecting the "infinity" and "largest-float" restarts. - - - - - 9fe47ce1 by Raymond Toy at 2024-03-29T14:09:20-07:00 Update cmucl.pot for the new messages - - - - - 2 changed files: - src/i18n/locale/cmucl.pot - tests/float.lisp Changes: ===================================== src/i18n/locale/cmucl.pot ===================================== @@ -8728,13 +8728,21 @@ msgid "Internal error in floating point reader." msgstr "" #: src/code/reader.lisp -msgid "Number not representable as a ~S: ~S" +msgid "~S overflow reading ~S" msgstr "" #: src/code/reader.lisp msgid "Underflow" msgstr "" +#: src/code/reader.lisp +msgid "Floating point underflow when reading ~S" +msgstr "" + +#: src/code/reader.lisp +msgid "Number not representable as a ~S: ~S" +msgstr "" + #: src/code/reader.lisp msgid "Invalid ratio: ~S/~S" msgstr "" ===================================== tests/float.lisp ===================================== @@ -212,3 +212,50 @@ ;; most-positive-double-float. And a really big single-float. (assert-error 'reader-error (read-from-string "1.8d308")) (assert-error 'reader-error (read-from-string "1d999999999"))) + +(define-test fp-overflow-restarts.infinity + (:tag :issues) + ;; Test that the "infinity" restart from reader on floating-point + ;; overflow returns an infinity of the correct type and sign. + (dolist (item (list (list "4e38" ext:single-float-positive-infinity) + (list "-4e38" ext:single-float-negative-infinity) + (list "2d308" ext:double-float-positive-infinity) + (list "-2d308" ext:double-float-negative-infinity) + ;; These test the short-cut case in the reader for + ;; very large numbers. + (list "4e999" ext:single-float-positive-infinity) + (list "-4e999" ext:single-float-negative-infinity) + (list "1d999" ext:double-float-positive-infinity) + (list "-1d999" ext:double-float-negative-infinity))) + (destructuring-bind (string expected-result) + item + (assert-equal expected-result + (values (handler-bind ((reader-error + (lambda (c) + (declare (ignore c)) + (invoke-restart 'lisp::infinity)))) + (read-from-string string))))))) + +(define-test fp-overflow-restarts.huge + (:tag :issues) + ;; Test that the "largest-float" restart from reader on + ;; floating-point overflow returns the largest float of the correct + ;; type and sign. + (dolist (item (list (list "4e38" most-positive-single-float) + (list "-4e38" most-negative-single-float) + (list "2d308" most-positive-double-float) + (list "-2d308" most-negative-double-float) + ;; These test the short-cut case in the reader for + ;; very large numbers. + (list "4e999" most-positive-single-float) + (list "-4e999" most-negative-single-float) + (list "1d999" most-positive-double-float) + (list "-1d999" most-negative-double-float))) + (destructuring-bind (string expected-result) + item + (assert-equal expected-result + (handler-bind ((reader-error + (lambda (c) + (declare (ignore c)) + (values (invoke-restart 'lisp::largest-float))))) + (read-from-string string)))))) View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/1a7b3a7ce614be51152e369... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/1a7b3a7ce614be51152e369... You're receiving this email because of your account on gitlab.common-lisp.net.