Archived

This topic is now archived and is closed to further replies.

avoiding the dredded 1.#INF0

This topic is 5016 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

Hello!! Im sure you have seen this before... y = (ax + cz + d) / b; When the b component is zero, we get into trouble. Is there a way of testing for 1.#INF0... like a function that goes "if y is infinite" in C++? Or are we just stuck to testing for 0 every time we go to divide? Cheeers

Share this post


Link to post
Share on other sites
Would it not be possible to check to see if b is zero BEFORE you put the variables into the equation, for it b is zero the outcome will be 1.#INFO??

It seems like the best solution to me, if it is fesible.

- Ratterbox

Share this post


Link to post
Share on other sites
Dreaded? *chuckle* NaNs are much worse

#include <limits>
if(result==std::numeric_limits<float>::infinity())
or
if(result==std::numeric_limits<double>::infinity())



“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan

Share this post


Link to post
Share on other sites
by the way, I think you are trying to work on planes, and you chose z and y as the parameters.
The best would be to choose the equation that does not involve singularities. since you can choose the x(y,z) and z(x,y) parameters instead, just pick the equation that works.
You can use templates to automatically formulate those equations.
Maybe I''m completely mistaken about your goal here, in which case please ignore this post.

Share this post


Link to post
Share on other sites