RE: Uninitialized Variables
- Posted by Chris Bensler <bensler at mail.com> Mar 23, 2002
- 472 views
Derek Parnell wrote: > ----- Original Message ----- > From: "Andy Serpa" <renegade at earthling.net> > To: "EUforum" <EUforum at topica.com> > Sent: Sunday, March 24, 2002 10:18 AM > Subject: RE: Uninitialized Variables > > > > > 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... > > > > 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 > > ? nan > ? inf > ------------ > > Derek, try this. ? x=nan ? x=inf ? x=10 btw: nan = -(inf/inf) Chris