Float bug toolkit: what the hash is this?

David N. Smith dnsmith at watson.ibm.com
Mon Feb 16 16:17:50 UTC 1998


Hi:

Floats only have a maximum exponent of about 308 when expressed in decimal.
It looks like Squeak is failing to detect exponent overflow.

(10.0 raisedToInteger: 307) hex  '7FAC7B1F3CAC7437'
(10.0 raisedToInteger: 308) hex  '7FE1CCF385EBC8A3'
(10.0 raisedToInteger: 309) hex  '7FF0000000000000'

--------------

"[1]" (10 raisedToInteger: 600) = (10.0 raisedToInteger: 800)  "alt-p"

These are equal since both expressions end up answering a float with a
special value indicating positive infinity. Positive infinities are always
equal.

(10 raisedToInteger: 600) asFloat hex '7FF0000000000000'
(10.0 raisedToInteger: 800) hex '7FF0000000000000'


--------------

"[2]" (1 to: 1000) select: [:one | ((10 raisedToInteger: one) = (10.0
raisedToInteger: one)) not] "alt-p"

Several things are happening with these results; first, not all integers
with the value 10^n are equal to a float with the value 10.0^n (for the
same n). This test violates a basic principle of floating point arithmetic:
never compare for equality.

Here is the test for values (1 to: 100):


(1 to: 100) select: [:one | ((10 raisedToInteger: one) = (10.0
raisedToInteger: one)) not] "alt-p"
 (25 29 33 37 39 45 46 49 55 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
74 75 76 77 78 79 80 81 82 83 88 89 90 92 93 94 95 96 98 99 100 )


Using the missing 25 as an example, here are the results of the two
computations:

(10 raisedToInteger: 25) 10000000000000000000000000
(10.0 raisedToInteger: 25)   9.99999999999995e24

Subtracting the two gives 2.14748364799999e9 which is certainly not zero!

(10 raisedToInteger: 25) asFloat - (10.0 raisedToInteger: 25)
  2.14748364799999e9

--------------

In any of the examples, an attempt to print an infinity seems to cause
Squeak to run amuck. It's the printing that is causing the low memory
condition.


Squeak needs to properly support IEEE floating point. As a start it should
at least add tests for Infinity+, infinity-, NAN, and maybe gradual
underflow.

Dave






At 16:23 -0500 2/14/98, sqrmax at cvtci.com.ar wrote:
>Hi.
>
>Evaluate the following expressions:
>
>"[1]" (10 raisedToInteger: 600) = (10.0 raisedToInteger: 800) "alt-p"
>
>"[2]" (1 to: 1000) select: [:one | ((10 raisedToInteger: one) = (10.0
>raisedToInteger: one)) not] "alt-p"
>
>"[3]" bFloat := 10.0 raisedToInteger: 977. bFloat inspect. bFloat
>printString. bFloat log "alt-p"
>
>In Squeak 1.23 and 1.30, [1] evaluates to true, [2] gives out
>
>(25 29 33 37 39 45 46 49 55 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
>75 76 77 78 79 80 81 82 83 88 89 90 92 93 94 95 96 98 99 100 101 102 103 104
>105 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
>125 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
>145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
>164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
>182 183
>184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
>203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
>222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
>241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
>259 260
>261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
>280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
>299 300 301 302 303 304 305 306 307 308 )
>
>and [3] eats all available memory (any of #inspect, #log or #printString).
>Note that #log can be alt-done, but cannot be alt-printed.
>
>I think that some overflow check should be done somewhere. I also think
>that 1 = 1.0 should evaluate to false because of [2]. In fact, I think
>that #=
>aNumber in Integer should first ensure that aNumber isKindOf: Integer or
>something of the sort, and then proceed with the current #=. Maybe a
>#isEquivalentTo: aNumber method should be added with the behaviour of the
>current #=
>message. Maybe a binary selector like #=! or whatever would be nicer.
>
>Taking [2] in consideration, I don't think that a special hash is needed
>because the #= selector only works as espected in quite a few cases.
>
>Andres.


_______________________________
David N. Smith
IBM T J Watson Research Center
Hawthorne, NY
_______________________________
Any opinions or recommendations
herein are those of the author
and not of his employer.





More information about the Squeak-dev mailing list