Codas said:
If I pass a negative number as argument to sqrt() it returns a NAN as
expected. Is there any way to debug this problem using GDB
Let me know
If you are trying to discover what function passes
the negative argument to sqrt(), one C-only approach
would be to "wrap" the sqrt() call with your own function:
#include <stdio.h>
#include <math.h>
double my_sqrt(double x, const char *file, int line) {
if (x < 0.0)
fprintf (stderr, "sqrt(%g) called from %s, line %d\n",
x, file, line);
return sqrt(x);
}
Then in each file that calls sqrt(), you would insert
something like this *after* the #include <math.h>:
#include <math.h>
...
double my_sqrt(double, const char*, int);
#undef sqrt /* in case <math.h> defines it as a macro */
#define sqrt(x) my_sqrt((x), __FILE__, __LINE__)
These "intercepting" lines could, of course, reside in
your own "my_sqrt.h" header file if that's convenient.