# nan function - tagp argument

**URL:** <https://forums.developer.nvidia.com/t/nan-function-tagp-argument/68266>\
**Category:** CUDA Programming and Performance\
**Created:** [December 7, 2018, 5:23pm UTC](https://forums.developer.nvidia.com/t/nan-function-tagp-argument/68266 "2018-12-07T17:23:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Smith\_Lon](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@John\_Smith\_Lon](https://forums.developer.nvidia.com/u/John_Smith_Lon)\
**Post date:** [December 7, 2018, 5:23pm UTC](https://forums.developer.nvidia.com/t/nan-function-tagp-argument/68266/1 "2018-12-07T17:23:26Z")

</div>

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](https://docs.nvidia.com/cuda/cuda-math-api/group __CUDA__ MATH __DOUBLE.html#group__ CUDA __MATH__ DOUBLE_1g6df5511321a5ac0dfe22389b728a8a9f)

Thank you

---

<div class="post-metadata">

**Author:** ![njuffa](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@njuffa](https://forums.developer.nvidia.com/u/njuffa)\
**Post date:** [December 7, 2018, 6:07pm UTC](https://forums.developer.nvidia.com/t/nan-function-tagp-argument/68266/2 "2018-12-07T18:07:17Z")

</div>

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

> [@](#):
>
> The argument _tagp_ is used in an unspecified manner.

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Robert\_Crovella](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/robert_crovella/32/14043_2.png) [@Robert\_Crovella](https://forums.developer.nvidia.com/u/Robert_Crovella)\
**Post date:** [December 7, 2018, 6:12pm UTC](https://forums.developer.nvidia.com/t/nan-function-tagp-argument/68266/3 "2018-12-07T18:12:20Z")

</div>

This may be of interest:  
[url][Way to get floating-point special values in CUDA? - Stack Overflow](https://stackoverflow.com/questions/15514286/way-to-get-floating-point-special-values-in-cuda%5B/url%5D)

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:

[url][DevDocs](https://devdocs.io/c/numeric/math/nan.2%5B/url%5D)
