Tarta
Tarta

Reputation: 2063

How to check if a value is 1.#INF0000?

I have, in short, this code:

vec3 contribX1 = Sample(O, D, 0);
if (std::isinf(contribX1.x)){
    ..do something..
}

According to my debug I have sometimes an infinite value that is returned by the Sample method and I have to solve it. But before doing it, I need the tools to debug properly. So I have been looking around and I found this std::isinf() that should return me a bool. Unfortunately it seems I never enter that IF condition, even if right after I am able to check the contribX1.x and it actually is 1.#INF0000. What am I doing wrong?

EDIT: The compiler is cl.exe.. I am using Visual Studio 2013

Upvotes: 2

Views: 743

Answers (1)

EdChum
EdChum

Reputation: 394209

You can use isfinite to test whether the value is a valid and non-continuous (i.e. inifinite) value:

if (!std::isfinite(contribX1.x)){

should work for you, I think the issue here is that there are various values used to represent positive and negative infinite values along with NaN, in your situation I think using this test should be fine.

I don't know your platform but for Windows this related question is what helped me: std::isfinite on MSVC

Upvotes: 3

Related Questions