1

I checked if sqrt(-1.0) returns NaN (http://en.cppreference.com/w/c/numeric/math/sqrt). In gdb, it does not return NaN

(gdb) p/x sqrt(-1.0)
$10 = 0xe53a86a0
(gdb) p sqrt(-1.0)
$11 = -449149280

Does GDB call a different sqrt? I use gdb 7.6

Joe C
  • 2,757
  • 2
  • 26
  • 46

1 Answers1

1

It looks like GDB does not have access to suitable debugging information. As a result, it assumes that sqrt is a function which returns int:

(gdb) ptype sqrt
type = int ()

You can use a cast to tell GDB the correct type:

(gdb) print ((double (*)(double))sqrt)(2)
$1 = 1.4142135623730951

Or you could load suitable debugging information.

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
  • Although I made the post duplicated with https://stackoverflow.com/questions/5122570/why-does-gdb-evaluate-sqrt3-to-0, the accepted answer at that post (using __sqrt) does not work for -1.0: it returns -165394784. Florian Weimer's answer works to me. – Joe C Jul 28 '17 at 21:13