RE: Uninitialized Variables
- Posted by Andy Serpa <renegade at earthling.net> Mar 23, 2002
- 443 views
If this message comes through twice, I'm sorry -- the web interface is very slow today: Ok, here's the test so we don't get tricked by the optimizer: equal(anything,copy of anything) will always be true -- you have to make a nan that isn't just a copy of your definition. ------------------- atom x,y,nan,inf, z, unknown inf = 1e300 * 1e300 nan = -(inf / inf) -- ( inf / inf = -nan ) x = 10 -- not a nan y = -tan(inf) -- a nan z = nan -- a different nan ---------------------------- Now, assume you don't know what x,y, & z are. Show me a way to identify the nans & non-nans, AND continues to work when translated to C (except with Borland -- all of these big number things crash Borland). THIS works in all cases I know of: ------------------------------------ unknown = x if unknown and compare(unknown/unknown,1) then puts(1,"NAN!\n") else puts(1,"non-NAN!\n") end if unknown = y if unknown and compare(unknown/unknown,1) then puts(1,"NAN!\n") else puts(1,"non-NAN!\n") end if unknown = z if unknown and compare(unknown/unknown,1) then puts(1,"NAN!\n") else puts(1,"non-NAN!\n") end if --------------- This works in the interpreter, but not when compiled: unknown = x if unknown = 1 and unknown = 2 then puts(1,"NAN!\n") else puts(1,"non-NAN!\n") end if ----------------- As I said, using atom_to_float32() also would work it seems, but you have to account for nan & -nan. So one way involves two comparisons & a division; the other involves converting to a sequence & then up to two comparisions. Isn't there a cheaper way?