RE: Uninitialized Variables
- Posted by Andy Serpa <renegade at earthling.net> Mar 23, 2002
- 443 views
No difference on my system. It might also be you are being tripped up by an optimization: atom x,y,nan,inf inf = 1e300 * 1e300 nan = inf / inf x = nan Now equal(x,nan) will be TRUE, probably because Euphoria doesn't actually even compare them, since they both will share the same internal pointer at this point. Now do: y = x + 5 <= y is now also a nan (actually -nan) ? equal(y,nan) -- This is FALSE. Once again, we can't determine a nan this way. ? x ? y -nan -nan Chris Bensler wrote: > You need to use equal(), instead of = > > ? not equal(324876,NAN) > > > Chris > > Andy Serpa wrote: > > > > > > > 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 > > > > > > > So how do I test if something is a nan? The "official" way is to use > > x!=x, but that is usually optimized away by most compilers (& Euphoria, > > apparently.) Using something like if x=1 and x=2 will work in the > > interpreter, but not translated to C, even with Watcom. (In fact, it is > > > > > > different depending on the compiler). > > > > Am I stuck with "if x and compare(x/x,1)"? > > > > For my genetic programming system this is a very real problem, as it > > comes up with random mathmatical expressions that sometimes are nan's. > > If you then take a predicted value (which is a nan) as output for a > > function that it has created and compare it with a target value, it will > > > > > > show as being equal (& therefore error = 0). So functions with nan's as > > > > > > output get the highest fitness, which is a disaster... > > > >