Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the source code for isnan?

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)?

like image 745
Dov Avatar asked Oct 22 '25 19:10

Dov


2 Answers

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.)

like image 102
Josh Lee Avatar answered Oct 25 '25 06:10

Josh Lee


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

like image 30
unwind Avatar answered Oct 25 '25 05:10

unwind



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!