Way to get floating-point special values in CUDA?

cuda, floating-point, nan, nvidia

Solution

How about `CUDART_NAN` (double) and `CUDART_NAN_F` (float) defined in `/usr/local/cuda/include/math_constants.h` :

#define CUDART_NAN_F            __int_as_float(0x7fffffff)
#define CUDART_NAN              __longlong_as_double(0xfff8000000000000ULL)

and:

#define CUDART_INF_F            __int_as_float(0x7f800000)
#define CUDART_INF              __longlong_as_double(0x7ff0000000000000ULL)

Problem

Is there any device functions in CUDA to obtain IEEE 754 special values like inf, NaN? I mean the stable way, not by some maths ops that could be optimized-out by compilers. I only manage to find a device function called nan() that must take some unknown string argument.

Original source