Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

How can I declare a nan literal?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!