• 9
• 9
• 10
• 10
• 9

How can I declare a nan literal?

This topic is 900 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

My goal is to declare a nan literal so that when a position is not defined.

It will give it something like

D3DXVECTOR3(nan, nan, nan)

so I get some basic idea what is going on.

Are there any easy ways to achieve this?

Thanks

Jack

Share on other sites
Or some value beyond the size of your world perhaps

Share on other sites

float.max, float.min maybe?

Share on other sites

But worst sin of all; NaNs are incredibly useful for finding uninitialized variables. I often override all allocators (new, malloc, etc) and initialize all the range of memory I return to signaling NaNs. Then make sure the control word is set to signal exceptions on any NaN.

When an uninitialized value is used, bam! exception raised, problem found.

If you use NaNs explicitly around all of your codebase, this technique becomes useless since every time you initialize a float with a NaN you'll get a false positive.

Also NaNs can hit the performance. CPUs rarely operate at 100% speed when NaNs are involved.

A bit confused here, isn't using NaN's for finding uninitialized variables what he is trying to do?  Or does even assignment of signaling NaN's cause an exception (I was under the impression they were fine till you tried to do a calculation)?

Share on other sites

A bit confused here, isn't using NaN's for finding uninitialized variables what he is trying to do?

My interpretation is asked how to do:
float x = NaN;
doSomething( x );
Which is different from overriding the memory allocators so that all the memory chunks returned are initialized to the pattern 7fe00001.

Or does even assignment of signaling NaN's cause an exception (I was under the impression they were fine till you tried to do a calculation)?

That's usually the case however generated assembly out of C/C++ often does more than just a single fld/fst or movss thus triggering the exception anyway. Edited by Matias Goldberg