NaN

BlitzPlus Forums/BlitzPlus Programming/NaN

Cold Harbour(Posted 2004) [#1]
Hi, I’m working on a custom resize bar for my app that basically resizes a canvas with the mouse.

In debug mode everything is fine and the bar works perfectly.

With debug off, one of my variables suddenly goes NaN – which I think means ‘Not a Number’.

I did some hunting and found that this line causes the problem

 
mainheight=mainheight+(MouseY()-tempy)


mainheight goes NaN.

But if I do this

my=MouseY()
mainheight=mainheight+(my-tempy)

it works again.

Does anyone no why I can’t use mousey() in this way?

Thanks a lot.


Floyd(Posted 2004) [#2]
NaN is a special kind of floating point value which does indeed mean 'Not a Number'.
'mainheight+(MouseY()-tempy)' cannot possibly produce NaN unless mainheight or tempy is already NaN before the expression is evaluated.

The most common source of NaN is division by zero followed by further calculation.
Graphics 200, 200, 0, 2

zero# = 0.0

x# = 1/zero
Text 50, 70, "x = " + x

y# = x - x
Text 50, 90, "y = " + y

Flip : WaitKey : End

I suggest looking for code, prior to the mainheight expression, which might be doing a floating point division by zero.


Cold Harbour(Posted 2004) [#3]
Thanks for the reply Floyd. So NaN represents infinity or a complex number.

I just think it's odd that if I explicitly use mousey() in a line I get NaN but if I define it as an integer in the line before then I don't.

It's unexpected for Blitz+ to act like this.


Rottbott(Posted 2004) [#4]
I think if it was infinite it would say Infinity instead of NaN. NaN just means a number that doesn't make sense, such as the square root of -1.


pantsonhead.com(Posted 2004) [#5]
My guess is that when you store MouseY() in the variable "my" it casts MouseY() as an integer value.
So when the next line is evaluated the "float" issue is no longer present.

what happens if use use my# ?


Cold Harbour(Posted 2004) [#6]
Yes it was something like that. If I use int(mainheight) it fixes it.

Weird.

Anyway, thanks to all who commented. :)