3

Because of the layers of standards, the include files for c++ are a rats nest. I was trying to figure out what __isnan actually calls, and couldn't find anywhere with an actual definition.

So I just compiled with -S to see the assembly, and if I write:

#include <ieee754.h>

void f(double x) {
  if (__isinf(x) ...

  if (__isnan(x)) ...
}

Both of these routines are called. I would like to see the actual definition, and possibly refactor things like this to be inline, since it should be just a bit comparison, albeit one that is hard to achieve when the value is in a floating point register.

Anyway, whether or not it's a good idea, the question stands: WHERE is the source code for __isnan(x)?

mskfisher
  • 3,177
  • 3
  • 33
  • 47
Dov
  • 7,218
  • 7
  • 42
  • 64

2 Answers2

3

Glibc has versions of the code in the sysdeps folder for each of the systems it supports. The one you’re looking for is in sysdeps/ieee754/dbl-64/s_isnan.c. I found this with git grep __isnan.

(While C++ headers include code for templates, functions from the C library will not, and you have to look inside glibc or whichever.)

Josh Lee
  • 161,055
  • 37
  • 262
  • 269
1

Here, for the master head of glibc, for instance.

unwind
  • 378,987
  • 63
  • 458
  • 590