RE: Uninitialized Variables
- Posted by Chris Bensler <bensler at mail.com> Mar 23, 2002
- 463 views
Derek Parnell wrote: > ----- Original Message ----- > From: "Chris Bensler" <bensler at mail.com> > To: "EUforum" <EUforum at topica.com> > Sent: Sunday, March 24, 2002 10:58 AM > Subject: RE: Uninitialized Variables > > > > 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 > > > > > Okay, I did those changes and now I get this: > > x is not a number > y is a number > 1 > 0 > 0 > 1 > 0 > 1 > 1 > 0 > 0 > nan > inf <snip> it's not a CPU thing. This works for me... ------------------- atom x,y,nan,inf inf = 1e300 * 1e300 nan = -(inf / inf) -- ( inf / inf = -nan ) ? equal(10,nan) ? not equal(10,nan) ? equal(nan,nan) ------------------- my results are: 0 1 1 Chris