nan function - tagp argument

Hi,

Can anyone tell me what the argument tagp should be specified as in:

device ​ double nan ( const char* tagp )
Returns “Not a Number” value.
Returns
nan(tagp) returns NaN.
Description
Return a representation of a quiet NaN. Argument tagp selects one of the possible representations.

I cannot see documentation of the argument tagp in https://docs.nvidia.com/cuda/cuda-math-api/group__CUDA__MATH__DOUBLE.html#group__CUDA__MATH__DOUBLE_1g6df5511321a5ac0dfe22389b728a8a9f

Thank you

On other programming platforms the documentation for this function (introduced with C99) is more explicit:

This function is used infrequently, and therefore unlikely to be fast. In CUDA, however, the single-precision version is fast: there is only one canonical NaN supported for single precision (there is no NaN payload; this is IEEE Std 754-2008 compliant), so that canonical QNaN will be returned no matter what the input.

One typically uses nan() to specify a NaN payload in the form of a small integer, which allows one to track the origin of NaNs to some degree. I do not know any software currently in use on any platform that actually uses that feature. Historically, Apple’s SANE (Standard Apple Numerical Environment) used it.

Example usage:

nan ("9876");  // decimal
nan ("0765");  // octal
nan ("0xFEC"); // hexadecimal

I don’t know why the C standard committee chose a string-based interface here, that strikes me as poor design. It requires a string parser to insert the payload into the QNaN.

You can look at the generated bit pattern (e.g. with __double2hiint(), __double2loint()) to see what CUDA actually produces based on the passed integer. Be aware that the bit pattern may or may not match what the host toolchain produces. The C standard (and the C++ standard who simply inherited this) gives complete freedom to an implementation.

This may be of interest:
https://stackoverflow.com/questions/15514286/way-to-get-floating-point-special-values-in-cuda

The argument you are referring to is a const char string which should be used similarly to the c99/c++11 usage of the same-named function:

https://devdocs.io/c/numeric/math/nan.2