Is there a good method of declaring a float variable to be positive or negative INFINITY?
The generally accepted C++ method
#include
const float blah = std::numeric_limits::infinity();
produces an error message in device code because the infinity() function is not a device function.
Christian
Ailleur
2
I dont know… float a = 1.0f/0.0f?
jack
3
From the math_constants.h file:
#define CUDART_INF_F __int_as_float(0x7f800000)
So, I guess you can just define your own constants that way if you’re using the driver, with:
0x7f800000 = infinity
0xff800000 = -infinity
1 Like
These conform to the ieee floating point specification. You can use the values:
0x7ff0000000000000 = infinity
0xfff0000000000000 = -infinity
for doubles
You can use the C INFINITY
macro
#include <cmath>
const float blah = INFINITY;
2 Likes