473,498 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

NAN error and debugging with GDB

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
Co
Nov 14 '05 #1
10 7108
Codas obfuscatus wrote:
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
Co


If it's doing what you expected, I don't see a problem (but note that
the result of such a domain error is implementation-defined, and not
necessarily portable).

Specific tools (such as gdb) are off-topic here. This group discusses
the C language, not tools.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #2
Codas obfuscatus wrote:

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.

--
Er*********@sun.com
Nov 14 '05 #3
Eric Sosman wrote:
Codas obfuscatus wrote:
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.


That's a *great* idea!
Where did you get it? ;-)

Nov 14 '05 #4
Eric Sosman <Er*********@sun.com> wrote in message news:<3F***************@sun.com>...

<snip>

#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__)

^^^
Why parenthesise x here?

--
Peter
Nov 14 '05 #5
ai***@acay.com.au (Peter Nilsson) writes:
Eric Sosman <Er*********@sun.com> wrote in message
news:<3F***************@sun.com>...

<snip>

#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__)

^^^
Why parenthesise x here?


Because all macro arguments should be fully parenthesized to avoid
operator precedence problems. (This assumes that the macro is
supposed to act like a function call and the arguments are supposed to
be expressions.)

In this particular case, the argument to the sqrt() macro is already
enclosed in parentheses, so there may not be any actual argument that
would be legal for a call to the sqrt() function that would cause
problems for the sqrt() macro. I've tried and failed to come up with
a problematic example using the comma operator. But it's much easier
to add the parentheses than to prove that they're unnecessary in this
particular case.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #6
Keith Thompson wrote:
ai***@acay.com.au (Peter Nilsson) writes:
Eric Sosman <Er*********@sun.com> wrote in message

<snip>

#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__)

^^^
Why parenthesise x here?


Because all macro arguments should be fully parenthesized to
avoid operator precedence problems. (This assumes that the macro
is supposed to act like a function call and the arguments are
supposed to be expressions.)

In this particular case, the argument to the sqrt() macro is already
enclosed in parentheses, so there may not be any actual argument that
would be legal for a call to the sqrt() function that would cause
problems for the sqrt() macro. I've tried and failed to come up with
a problematic example using the comma operator. But it's much easier
to add the parentheses than to prove that they're unnecessary in this
particular case.


Won't "foo = sqrt(2, 4);" foul up without the parens? It should
barf at compile time.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #7
CBFalconer wrote:
#define sqrt(x) my_sqrt((x), __FILE__, __LINE__)

^^^
Why parenthesise x here?


Won't "foo = sqrt(2, 4);" foul up without the parens? It should
barf at compile time.


Won't it foul up either way? The comma in that context should act as an
argument separator, not the comma operator, shouldn't it?

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #8
CBFalconer <cb********@yahoo.com> writes:
Keith Thompson wrote:
ai***@acay.com.au (Peter Nilsson) writes:
Eric Sosman <Er*********@sun.com> wrote in message

<snip>
>
> #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__)
^^^
Why parenthesise x here?


Because all macro arguments should be fully parenthesized to
avoid operator precedence problems. (This assumes that the macro
is supposed to act like a function call and the arguments are
supposed to be expressions.)

In this particular case, the argument to the sqrt() macro is already
enclosed in parentheses, so there may not be any actual argument that
would be legal for a call to the sqrt() function that would cause
problems for the sqrt() macro. I've tried and failed to come up with
a problematic example using the comma operator. But it's much easier
to add the parentheses than to prove that they're unnecessary in this
particular case.


Won't "foo = sqrt(2, 4);" foul up without the parens? It should
barf at compile time.


That's basically the example I was trying to come up with, but
"foo = sqrt(2, 4);" would foul up whether sqrt() is a macro or a
function taking one argument. The resulting error message might be
confusing, though.

If you want to pass an expression with a comma operator as a function
argument, you have to parenthesize it: "foo = sqrt((2, 4));" -- which
also avoids the problem.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #9
Peter Nilsson wrote:

Eric Sosman <Er*********@sun.com> wrote in message news:<3F***************@sun.com>...

<snip>

#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__)

^^^
Why parenthesise x here?


Because (good habits) are (hard (to break))?

--
Er*********@sun.com
Nov 14 '05 #10
Keith Thompson <ks***@mib.org> wrote in message news:<ln************@nuthaus.mib.org>...
ai***@acay.com.au (Peter Nilsson) writes:
Eric Sosman <Er*********@sun.com> wrote in message
news:<3F***************@sun.com>...

<snip>

#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__)

^^^
Why parenthesise x here?


<snip> ... it's much easier to add the parentheses than to prove that they're
unnecessary in this particular case.


In this particular case, I think it's much easier to leave them out:

#define sqrt(x) my_sqrt(x, __FILE__, __LINE__)

As Dan Pop once said, "[it] isn't unclear *at all* and only an expert
could actually have doubts about it". ;)

--
Peter
Nov 14 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
15924
by: Bob Bamberg | last post by:
Hello All, I have been trying without luck to get some information on debugging the Runtime Error R6025 - Pure Virtual Function Call. I am working in C++ and have only one class that is derived...
10
2680
by: Brian Conway | last post by:
I have no idea what is going on. I have a Login screen where someone types in their login information and this populates a datagrid based off of the login. Works great in debug and test through...
4
11125
by: Stephen Miller | last post by:
Hi, I am running v1.1.4322 on Win2K server and unable to debug a ASP.Net application running locally, using a full URL (ie www.mysite.com). When I hit F5, I get the following error message: ...
5
2046
by: Don Hans | last post by:
Gents, Have .Net2003 Enterprise architect installed on a Win2k Server with IIS. Even logged in as administrator, I cannot run any ASP.NET app with debugging. I always get the error "Unable to...
1
1848
by: Matt | last post by:
When I try to run the ASP.NET application, it has the following error messages: Error while trying to run project: unable to start debugging on the web server. The project is not configured to...
5
6546
by: Bruce Schechter | last post by:
I just started to develop an ASP.NET application in vs.net 2003 . But each time I try to execute the application (which is basically empty so far), I get a dialog box titled "Microsoft Development...
10
8679
by: Shawn | last post by:
JIT Debugging failed with the following error: Access is denied. JIT Debugging was initiated by the following account 'PLISKEN\ASPNET' I get this messag in a dialog window when I try to open an...
5
3609
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
0
5746
by: Benny | last post by:
I have been trying to instal AutoCAD 2008 on a single PC and get the following Microsoft .NET Framework security error. I have updated to the latest .NET Framework 2.0 software, however, this...
0
1796
by: John [H2O] | last post by:
There's a lot of greek for me here ... should I post to numpy-discussions as well??? The backtrace is at the bottom.... Thanks! GNU gdb Fedora (6.8-21.fc9) Copyright (C) 2008 Free...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7004
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7167
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5464
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3095
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.