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,291
  • 4
  • 35
  • 48
Dov
  • 8,000
  • 8
  • 46
  • 75

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
  • 171,072
  • 38
  • 269
  • 275
1

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

unwind
  • 391,730
  • 64
  • 469
  • 606