Raymond Toy pushed to branch issue-275-signal-underflow-in-float-reader at cmucl / cmucl

Commits:

2 changed files:

Changes:

  • src/code/reader.lisp
    ... ... @@ -1824,50 +1824,27 @@ the end of the stream."
    1824 1824
     	  (t (error _"Internal error in floating point reader.")))))
    
    1825 1825
     
    
    1826 1826
     (defun make-float-aux (number divisor float-format stream)
    
    1827
    -  (let ((ratio (/ number divisor))
    
    1828
    -        result)
    
    1829
    -    (handler-case
    
    1830
    -        (progn
    
    1831
    -          (setf result (coerce ratio float-format))
    
    1832
    -          #+nil
    
    1833
    -          (when (and (zerop result) (not (zerop number)))
    
    1834
    -	    ;; The number we've read is so small that it gets
    
    1835
    -	    ;; converted to 0.0, but is not actually zero.  In this
    
    1836
    -	    ;; case, we want to round such small numbers to
    
    1837
    -	    ;; least-positive-foo-float.  If it's still too small, we
    
    1838
    -	    ;; want to signal an error saying that we can't really
    
    1839
    -	    ;; convert it because the exponent is too small.
    
    1840
    -	    ;; See CLHS 2.3.1.1.
    
    1841
    -	    (let ((float-limit (ecase float-format
    
    1842
    -			         ((short-float single-float)
    
    1843
    -			          least-positive-single-float)
    
    1844
    -			         (double-float
    
    1845
    -			          least-positive-double-float)
    
    1846
    -			         #+double-double
    
    1847
    -			         (double-double-float
    
    1848
    -			          ext:least-positive-double-double-float))))
    
    1849
    -	      (if (>= (* 2 ratio) float-limit)
    
    1850
    -	          (setf result float-limit)
    
    1851
    -	          (error _"Underflow"))))
    
    1852
    -          result)
    
    1853
    -      (floating-point-underflow (c)
    
    1854
    -        (describe c)
    
    1855
    -        ;; Got an underflow.  Resignal it with the same
    
    1856
    -        ;; operation/operands, but allowing a restart to set the value
    
    1857
    -        ;; to 0.
    
    1858
    -        (restart-case
    
    1859
    -            (error 'floating-point-underflow
    
    1860
    -                   :operation (arithmetic-error-operation c)
    
    1861
    -                   :operands (arithmetic-error-operands c))
    
    1862
    -          (return-zero  ()
    
    1863
    -            :report (lambda (stream)
    
    1864
    -                      (format stream _"Return ~A for ~A"
    
    1865
    -                              (coerce 0 float-format)
    
    1866
    -                              (read-buffer-to-string)))
    
    1867
    -            (setf result (coerce 0 float-format)))))
    
    1868
    -      (error ()
    
    1869
    -        (%reader-error stream _"Number not representable as a ~S: ~S"
    
    1870
    -		       float-format (read-buffer-to-string))))))
    
    1827
    +  (handler-case
    
    1828
    +      (let ((ratio (/ number divisor)))
    
    1829
    +        (coerce ratio float-format))
    
    1830
    +    (floating-point-underflow (c)
    
    1831
    +      (describe c)
    
    1832
    +      ;; Got an underflow.  Resignal it with the same
    
    1833
    +      ;; operation/operands, but allowing a restart to set the value
    
    1834
    +      ;; to 0.
    
    1835
    +      (restart-case
    
    1836
    +          (error 'floating-point-underflow
    
    1837
    +                 :operation (arithmetic-error-operation c)
    
    1838
    +                 :operands (arithmetic-error-operands c))
    
    1839
    +        (return-zero  ()
    
    1840
    +          :report (lambda (stream)
    
    1841
    +                    (format stream _"Return ~A for ~A"
    
    1842
    +                            (coerce 0 float-format)
    
    1843
    +                            (read-buffer-to-string)))
    
    1844
    +          (setf result (coerce 0 float-format)))))
    
    1845
    +    (error ()
    
    1846
    +      (%reader-error stream _"Number not representable as a ~S: ~S"
    
    1847
    +		     float-format (read-buffer-to-string))))))
    
    1871 1848
     
    
    1872 1849
     
    
    1873 1850
     (defun make-ratio (stream)
    

  • src/general-info/release-21f.md
    ... ... @@ -40,6 +40,8 @@ public domain.
    40 40
         * ~~#258~~ Remove `get-page-size` from linux-os.lisp
    
    41 41
         * ~~#269~~ Add function to get user's home directory
    
    42 42
         * ~~#266~~ Support "~user" in namestrings
    
    43
    +    * ~~#275~~ Handle floating point underflow in float reader
    
    44
    +      allowing user to flush the value to 0.
    
    43 45
       * Other changes:
    
    44 46
       * Improvements to the PCL implementation of CLOS:
    
    45 47
       * Changes to building procedure: