RE: Uninitialized Variables
- Posted by Chris Bensler <bensler at mail.com> Mar 23, 2002
- 464 views
Andy Serpa wrote: > > > > > I tried to use NAN as well, but everything is equal to NAN!? > > > > NAN=1 > > > > NAN=-NAN > > > > NAN=INF > > > > NAN=-5039487 > > > > > > > > Is that proper behaviour? > > > > > > I just ran into this problem yesterday -- how do you test for a nan? It > > registers equal to everything if you use '=' but not equal(). The > behavior also changes if you compile to C, and is different with every > compiler. This always works: > > x = <nan> > > if x and compare(x/x,1) then > ... > > (a nan passes the first test, which is neccessary to avoid div by zero > for non-nans -- it also passes the second test, which for any real > number will compare() to 0) > > It also occured to be that the representation of a nan might be > consistent if you atom_to_float() it, but I haven't tried that yet. > Either way seems expensive -- is there a good way to test if something > is a nan? > Apparently NAN is (silly me) Not A Number! :P using equal() compares NAN properly and consistently Here is my revised uninitialized values for variables: integer = -INF atom = INF sequence = NAN object = -NAN Chris