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

Commits:

2 changed files:

Changes:

  • src/i18n/locale/cmucl.pot
    ... ... @@ -8728,13 +8728,21 @@ msgid "Internal error in floating point reader."
    8728 8728
     msgstr ""
    
    8729 8729
     
    
    8730 8730
     #: src/code/reader.lisp
    
    8731
    -msgid "Number not representable as a ~S: ~S"
    
    8731
    +msgid "~S overflow reading ~S"
    
    8732 8732
     msgstr ""
    
    8733 8733
     
    
    8734 8734
     #: src/code/reader.lisp
    
    8735 8735
     msgid "Underflow"
    
    8736 8736
     msgstr ""
    
    8737 8737
     
    
    8738
    +#: src/code/reader.lisp
    
    8739
    +msgid "Floating point underflow when reading ~S"
    
    8740
    +msgstr ""
    
    8741
    +
    
    8742
    +#: src/code/reader.lisp
    
    8743
    +msgid "Number not representable as a ~S: ~S"
    
    8744
    +msgstr ""
    
    8745
    +
    
    8738 8746
     #: src/code/reader.lisp
    
    8739 8747
     msgid "Invalid ratio: ~S/~S"
    
    8740 8748
     msgstr ""
    

  • tests/float.lisp
    ... ... @@ -212,3 +212,50 @@
    212 212
       ;; most-positive-double-float.  And a really big single-float.
    
    213 213
       (assert-error 'reader-error (read-from-string "1.8d308"))
    
    214 214
       (assert-error 'reader-error (read-from-string "1d999999999")))
    
    215
    +
    
    216
    +(define-test fp-overflow-restarts.infinity
    
    217
    +    (:tag :issues)
    
    218
    +  ;; Test that the "infinity" restart from reader on floating-point
    
    219
    +  ;; overflow returns an infinity of the correct type and sign.
    
    220
    +  (dolist (item (list (list "4e38" ext:single-float-positive-infinity)
    
    221
    +                      (list "-4e38" ext:single-float-negative-infinity)
    
    222
    +                      (list "2d308" ext:double-float-positive-infinity)
    
    223
    +                      (list "-2d308" ext:double-float-negative-infinity)
    
    224
    +                      ;; These test the short-cut case in the reader for
    
    225
    +                      ;; very large numbers.
    
    226
    +                      (list "4e999" ext:single-float-positive-infinity)
    
    227
    +                      (list "-4e999" ext:single-float-negative-infinity)
    
    228
    +                      (list "1d999" ext:double-float-positive-infinity)
    
    229
    +                      (list "-1d999" ext:double-float-negative-infinity)))
    
    230
    +    (destructuring-bind (string expected-result)
    
    231
    +        item
    
    232
    +      (assert-equal expected-result
    
    233
    +                    (values (handler-bind ((reader-error
    
    234
    +                                             (lambda (c)
    
    235
    +                                               (declare (ignore c))
    
    236
    +                                               (invoke-restart 'lisp::infinity))))
    
    237
    +                              (read-from-string string)))))))
    
    238
    +
    
    239
    +(define-test fp-overflow-restarts.huge
    
    240
    +    (:tag :issues)
    
    241
    +  ;; Test that the "largest-float" restart from reader on
    
    242
    +  ;; floating-point overflow returns the largest float of the correct
    
    243
    +  ;; type and sign.
    
    244
    +  (dolist (item (list (list "4e38" most-positive-single-float)
    
    245
    +                      (list "-4e38" most-negative-single-float)
    
    246
    +                      (list "2d308" most-positive-double-float)
    
    247
    +                      (list "-2d308" most-negative-double-float)
    
    248
    +                      ;; These test the short-cut case in the reader for
    
    249
    +                      ;; very large numbers.
    
    250
    +                      (list "4e999" most-positive-single-float)
    
    251
    +                      (list "-4e999" most-negative-single-float)
    
    252
    +                      (list "1d999" most-positive-double-float)
    
    253
    +                      (list "-1d999" most-negative-double-float)))
    
    254
    +    (destructuring-bind (string expected-result)
    
    255
    +        item
    
    256
    +      (assert-equal expected-result
    
    257
    +                    (handler-bind ((reader-error
    
    258
    +                                     (lambda (c)
    
    259
    +                                       (declare (ignore c))
    
    260
    +                                       (values (invoke-restart 'lisp::largest-float)))))
    
    261
    +                      (read-from-string string))))))