Raymond Toy pushed to branch issue-293-restart-on-reader-fp-overflow at cmucl / cmucl

Commits:

3 changed files:

Changes:

  • src/code/reader.lisp
    ... ... @@ -1929,8 +1929,8 @@ the end of the stream."
    1929 1929
           ;; 0.
    
    1930 1930
           (let ((zero (coerce 0 float-format)))
    
    1931 1931
             (restart-case
    
    1932
    -            (%reader-error stream _"Floating point underflow when reading ~S"
    
    1933
    -                           (read-buffer-to-string))
    
    1932
    +            (%reader-error stream _"Floating point underflow when reading ~S: ~S"
    
    1933
    +                           float-format (read-buffer-to-string))
    
    1934 1934
               (continue ()
    
    1935 1935
                 :report (lambda (stream)
    
    1936 1936
                           (format stream "Return ~A" zero))
    

  • src/i18n/locale/cmucl.pot
    ... ... @@ -8736,7 +8736,7 @@ msgid "Underflow"
    8736 8736
     msgstr ""
    
    8737 8737
     
    
    8738 8738
     #: src/code/reader.lisp
    
    8739
    -msgid "Floating point underflow when reading ~S"
    
    8739
    +msgid "Floating point underflow when reading ~S: ~S"
    
    8740 8740
     msgstr ""
    
    8741 8741
     
    
    8742 8742
     #: src/code/reader.lisp
    

  • tests/float.lisp
    ... ... @@ -213,6 +213,39 @@
    213 213
       (assert-error 'reader-error (read-from-string "1.8d308"))
    
    214 214
       (assert-error 'reader-error (read-from-string "1d999999999")))
    
    215 215
     
    
    216
    +(define-test reader.float-underflow
    
    217
    +    (:tag :issues)
    
    218
    +  (lisp::with-float-traps-enabled (:underflow)
    
    219
    +    ;; A denormal
    
    220
    +    (assert-error 'reader-error
    
    221
    +                  (read-from-string "1e-40"))
    
    222
    +    (assert-error 'reader-error
    
    223
    +                  (read-from-string (format nil "~A" least-positive-single-float)))
    
    224
    +    ;; The same for double-floats
    
    225
    +    (assert-error 'reader-error
    
    226
    +                  (read-from-string "1d-308"))
    
    227
    +    (assert-error 'reader-error
    
    228
    +                  (read-from-string (format nil "~A" least-positive-double-float)))))
    
    229
    +
    
    230
    +(define-test reader.float-underflow
    
    231
    +    (:tag :issues)
    
    232
    +  (lisp::with-float-traps-enabled (:underflow)
    
    233
    +    ;; The expected string comes from make-float-aux.
    
    234
    +    (let ((expected "Floating point underflow when reading ~S"))
    
    235
    +      (flet ((test-reader-underflow (string)
    
    236
    +               ;; Test that the we got a reader-error when a number
    
    237
    +               ;; would underflow and that the message says we got an
    
    238
    +               ;; underflow.
    
    239
    +               (let ((condition (nth-value 1 (ignore-errors (read-from-string string)))))
    
    240
    +                 (assert-equal 'reader-error (type-of condition))
    
    241
    +                 (assert-equal expected (lisp::reader-error-format-control condition)))))
    
    242
    +        ;; Underflow single-floats
    
    243
    +        (test-reader-underflow "1e-40")
    
    244
    +        (test-reader-underflow (format nil "~A" least-positive-single-float))
    
    245
    +        ;; Underflow double-floats
    
    246
    +        (test-reader-underflow "1d-308")
    
    247
    +        (test-reader-underflow (format nil "~A" least-positive-double-float))))))
    
    248
    +
    
    216 249
     (define-test fp-overflow-restarts.infinity
    
    217 250
         (:tag :issues)
    
    218 251
       ;; Test that the "infinity" restart from reader on floating-point