The following C file fails to compile
#include <math.h>
float x = NAN; // Error: undefined identifier `__builtin_nanf`, did you mean template `__builtin_inf()()`?
On macOS, the standard C macro NAN is defined as:
#define NAN __builtin_nanf("0x7fc00000")
On x64 linux, it is defined as:
# define NAN (__builtin_nanf (""))
So the above file preprocesses to:
float x = __builtin_nanf("0x7fc00000");
Looking at https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html, there’s also __builtin_nan and __builtin_nanl.
Comment #1 by dave287091 — 2022-10-14T02:53:50Z
Note that adding:
alias __builtin_nan = imported!"core.stdc.math".nan;
alias __builtin_nanf = imported!"core.stdc.math".nanf;
alias __builtin_nanl = imported!"core.stdc.math".nanl;
to __builtins.di does *not* solve the issue as then it cannot be used as a static initializer:
Error: `nanf` cannot be interpreted at compile time, because it has no available source code.