Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / object position = #qnan

Author
Message
Ben_UK78
16
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 11th Feb 2011 03:12
Hi All,

I have a little bug somewhere in my program.

Very occasionally one of my objects simply disappears as I try to move it. The X, Y, and Z object positions all report #QNAN

All I am using is something along these lines:




I do not seem to be doing anything special, or unusual.

Does anyone know what #QNAN means? Has it been passed a number outside of the range or a number that is incompatible the the float? Or something else strange.

Fuller code is along these lines, though they are in different functions:

Ben_UK78
16
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 11th Feb 2011 10:45
It did it again so i took a note of the figures. They are a little
It did it again so i took a note of the figures. They are a little different to what I gave above

Parameters give:

object angle x = 0
object angle y = 1.#QNAN
object angle z = -1.#IND

object position x = 1.#QNAN
object position y = 1.#QNAN
object position z = 1.#QNAN

Does anybody have any idea. I'm not doing anything special (I don't think). Just moving objects using the move object command by floats of around 0.5?

I've obviously got something going on somewhere. It seems pretty random as to when it will do it.

DB Pro V 1.076
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Feb 2011 13:22
Not sure but I think NAN means "Not A Number" which probably means that the bit pattern doesn't correspond to a valid float. There may be a simpler explanation, but it sounds to me as if your code is somehow accessing the wrong memory locations. Such errors can be hard to track down.

I tried to get your errors by increasing floats out of range but got something else instead, i.e. 1.#INF or 1.#J (I hadn't seen that second one before ).

Is it possible that an array reference is out of bounds and isn't being caught?
Ben_UK78
16
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 12th Feb 2011 04:39
Maybe...

I'll have to go through things and see if I can catch all the variables surrounding it happening. Like you say, it may be a little hard to track down.

I'll sort it out with a little patience.

Thanks for the Not A Number tip, that will help.
CodemanV
20
Years of Service
User Offline
Joined: 25th Aug 2005
Location: South Wales Valleys, UK
Posted: 12th Feb 2011 07:26 Edited at: 12th Feb 2011 07:30
Hello

I had a similar issue years ago when experimenting with 2d lines and slope values. IanM pointed me in the right direction.

NAN's are just invalid floating point values which can't be stored in the number of bits allocated to the variables storing them.

There are variations on NAN, QNAN "Quiet Not A Number", SNAN "Signalling Not A Number", something to do with NAN significant bits being set or not set. But they are all NAN. Google has loads on this topic!

Anyway, here's a snippet showing how to represent NAN and INF in DBPro (I still owe IanM a virtual pint for these! )



Regarding your snippets, what values are used for acceleration and deceleration?

It would seem that the "PROP_thrust_acceleration" are setting "PROP_thrust_speed" to values which are out of floating point range. I would guess that the acceleration values are problematic, particularly the deceleration ones. Try changing those.

Additionally, maybe implement minimum/maximam ranges on acceleration/deceleration values. They can then be checked if they go too high or too low and contained with valid ranges.

Alternatively, if you need the finer resolution, try changing the "ship_details().PROP_" variables to Double Floats instead. It's more of a hack than a fix as you can still get NAN or INF with Double Floats but might improve things a little.

All the best.
Hodgey
16
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 12th Feb 2011 09:56 Edited at: 12th Feb 2011 10:04
Hi, I think -1.#IND occurs when you enter the realm of imaginary numbers so you might want to check your algorithm for your 'object z angle'.

Small example


Hope this helps

Just thought of this, if you use a value greater than 1 or less than -1 in asin or acos, it will return -1.#IND.

A clever person solves a problem, a wise person avoids it - Albert Einstein
Ben_UK78
16
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 12th Feb 2011 22:31
OK, thanks.

I've definitely got a feeling i'm passing something strange to my move function. I'll have a look later I think. There's a few places to check.

Thanks very much for the help

Login to post a reply

Server time is: 2026-07-16 01:43:19
Your offset time is: 2026-07-16 01:43:19