RE: Uninitialized Variables

new topic     » goto parent     » topic index » view thread      » older message » newer message

Yeah, I tried it, and is definitely *NOT* what I get -- maybe it is a 
CPU thing.  I have an AMDK6-2/450.

For this version I get:

x is not a number
y is not a number
1
0
1
0
1
0
-nan
inf

Now I checked atom_to_float32()/float32_to_atom() and that works 
consistently -- note that (nan) & (-nan) are different though.

Derek Parnell wrote:
> > > 
> > > This seems to work:
> > > --------------
> > > atom x,nan,inf
> > > inf = 1e300 * 1e300
> > > nan = inf / inf
> > > 
> > > x = nan
> > > 
> > > if x = nan then
> > >     puts(1, "x is not a number\n")
> > > end if
> > > ? x = nan
> > > ? x != nan
> > > 
> > 
> > Actually, it doesn't.  Because
> > 
> > (10 = nan)
> > (2.3 = nan)
> > 
> > will also evaluate as true and
> > 
> > (10 != nan)
> > 
> > will evaluate as false.
> > 
> > You need to be able to tell a non-nan from a nan...
> > 
> 
> Umm, did you actually try it, Andy. Here is an expanded version:
> 
> ------------------
> 
> atom x,y,nan,inf
> inf = 1e300 * 1e300
> nan = inf / inf
> 
> x = nan
> y = 10
> if x = nan then
>     puts(1, "x is not a number\n")
> else
>     puts(1, "x is a number\n")
> end if
> if y = nan then
>     puts(1, "y is not a number\n")
> else
>     puts(1, "y is a number\n")
> end if
> ? x = nan
> ? x != nan
> ? y = nan
> ? y != nan
> ? 10 = nan
> ? 10 != nan
> 
> ? nan
> ? inf
> ------------------
> 
> I get the following output:
> 
> x is not a number
> y is a number
> 1
> 0
> 0
> 1
> 0
> 1
> -nan
> inf
> 
> -------------
> which seems just what I'd expect.
> 
> ----------
> Derek.
> 
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu