Set float to NaN on device

How can I make a float variable take the value of NaN in device code? In host code, I can do the following:

float f = std::numeric_limits::quiet_NaN();

However, on the device, I get an error because I am unable to call host code from the device. I have tried to use “NAN” from math.h as well, but this value appears to be undefined. I know I could just copy the value into the constant memory space from the host, but that is ridiculous. I could also do the following, but again, this is an absurd solution:

int nan = 0xFFE00000;
float f = (reinterpret_cast<float>(&nan));

Does anyone know of an easier way to go about doing this? Thanks,


float f = __int_as_float(0xFFE00000);

You could set it up as a compile constant as well.