RE: Uninitialized Variables
- Posted by Rod Jackson <rodjackson_x at hotmail.com> Mar 24, 2002
- 456 views
Andy Serpa wrote: <snip> > 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... Andy, If you don't mind me asking, what sorts of expressions are your genes coming up with that yield NAN? Are you using INF on occasion? Or square root of negative numbers? I'm asking because, while this needs to be addressed (and so far the discussion is very revealing,) it might save you time if a workaround can be found. Rod