This question was asked a long time ago but were not really answered. I get some weird wrong results when I try to evaluate math functions in gdb. I started with the following file
#include <math.h>
#include <stdio.h>
int main()
{
double x ;
x=sin(3.14) ;
printf("%f",x) ;
}
Launch gdb on it and break just before the printf. Now at the gdb prompt:
(gdb) p x
$1 = 0.0015926529164868282
(gdb) p sin(3.14)
$2 = 1074339512
(gdb) p ((double(*)())sin)(3.14)
$3 = 3.1399999999999997
Does anybody have an explanation of this? How can I evaluate the sin function in gdb and if I can't why?
Edited: The answer provided previously does not seems to work, at least for sin (see my comment).