Raymond Toy pushed to branch issue-277-float-ratio-float-least-positive-float at cmucl / cmucl

Commits:

1 changed file:

Changes:

  • tests/float.lisp
    ... ... @@ -142,20 +142,22 @@
    142 142
       ;; some rationals from 7/10*10^-45 to 1.41*10^-45 to make sure they
    
    143 143
       ;; return 0 or least-positive-single-float
    
    144 144
       (let ((expo (expt 10 -45)))
    
    145
    -    ;; 7/10*10^-45 is just under halfway between 0 and least-positive,
    
    146
    -    ;; so the answer is 0.
    
    147
    -    (assert-equal 0f0 (kernel::float-ratio-float (* 7/10 expo) 'single-float))
    
    148
    -
    
    149
    -    ;; These are all more than half way to
    
    150
    -    ;; least-positive-single-float, so they should return that.
    
    151
    -    (assert-equal least-positive-single-float
    
    152
    -                  (kernel::float-ratio-float (* 8/10 expo) 'single-float))
    
    153
    -    (assert-equal least-positive-single-float
    
    154
    -                  (kernel::float-ratio-float (* 1 expo) 'single-float))
    
    155
    -    (assert-equal least-positive-single-float
    
    156
    -                  (kernel::float-ratio-float (* 14/10 expo) 'single-float))
    
    157
    -    (assert-equal least-positive-single-float
    
    158
    -                  (kernel::float-ratio-float (* 2 expo) 'single-float))))
    
    145
    +    ;; Need to make sure underflows are masked.
    
    146
    +    (kernel::with-float-traps-masked (:underflow)
    
    147
    +      ;; 7/10*10^-45 is just under halfway between 0 and least-positive,
    
    148
    +      ;; so the answer is 0.
    
    149
    +      (assert-equal 0f0 (kernel::float-ratio-float (* 7/10 expo) 'single-float))
    
    150
    +
    
    151
    +      ;; These are all more than half way to
    
    152
    +      ;; least-positive-single-float, so they should return that.
    
    153
    +      (assert-equal least-positive-single-float
    
    154
    +                    (kernel::float-ratio-float (* 8/10 expo) 'single-float))
    
    155
    +      (assert-equal least-positive-single-float
    
    156
    +                    (kernel::float-ratio-float (* 1 expo) 'single-float))
    
    157
    +      (assert-equal least-positive-single-float
    
    158
    +                    (kernel::float-ratio-float (* 14/10 expo) 'single-float))
    
    159
    +      (assert-equal least-positive-single-float
    
    160
    +                    (kernel::float-ratio-float (* 2 expo) 'single-float)))))
    
    159 161
     
    
    160 162
     (define-test float-ratio.double
    
    161 163
         (:tag :issues)
    
    ... ... @@ -163,18 +165,20 @@
    163 165
       ;; test with some rationals from about 2*10^-324 to 4.94*10^-324 to make
    
    164 166
       ;; sure they return 0 or least-positive-double-float
    
    165 167
       (let ((expo (expt 10 -324)))
    
    166
    -    ;; 247/100*10^-45 is just under halfway between 0 and least-positive,
    
    167
    -    ;; so the answer is 0.
    
    168
    -    (assert-equal 0d0 (kernel::float-ratio-float (* 247/100 expo) 'double-float))
    
    169
    -
    
    170
    -    ;; These are all more than half way to
    
    171
    -    ;; least-positive-double-float, so they should return that.
    
    172
    -    (assert-equal least-positive-double-float
    
    173
    -                  (kernel::float-ratio-float (* 248/100 expo) 'double-float))
    
    174
    -    (assert-equal least-positive-double-float
    
    175
    -                  (kernel::float-ratio-float (* 4 expo) 'double-float))
    
    176
    -    (assert-equal least-positive-double-float
    
    177
    -                  (kernel::float-ratio-float (* 494/100 expo) 'double-float))
    
    178
    -    (assert-equal least-positive-double-float
    
    179
    -                  (kernel::float-ratio-float (* 988/100 expo) 'double-float))))
    
    168
    +    ;; Need to make sure underflows are masked.
    
    169
    +    (kernel::with-float-traps-masked (:underflow)
    
    170
    +      ;; 247/100*10^-324 is just under halfway between 0 and least-positive,
    
    171
    +      ;; so the answer is 0.
    
    172
    +      (assert-equal 0d0 (kernel::float-ratio-float (* 247/100 expo) 'double-float))
    
    173
    +
    
    174
    +      ;; These are all more than half way to
    
    175
    +      ;; least-positive-double-float, so they should return that.
    
    176
    +      (assert-equal least-positive-double-float
    
    177
    +                    (kernel::float-ratio-float (* 248/100 expo) 'double-float))
    
    178
    +      (assert-equal least-positive-double-float
    
    179
    +                    (kernel::float-ratio-float (* 4 expo) 'double-float))
    
    180
    +      (assert-equal least-positive-double-float
    
    181
    +                    (kernel::float-ratio-float (* 494/100 expo) 'double-float))
    
    182
    +      (assert-equal least-positive-double-float
    
    183
    +                    (kernel::float-ratio-float (* 988/100 expo) 'double-float)))))
    
    180 184