floating point exceptions 
Author Message
 floating point exceptions

Dear VC++ Gurus,
I am debugging a COM dll. It is called by Visual Basic from excel.
Somewhere in the code a floating exception occurs (division by 0 or
pow(-1,0.5) or ln(-1) etc.)
It seems that a flag is set or some exception is thrown because I get in the
visual basic part the
message that an exception occured but I dont have a chance to locate the
SOURCE of the exception.

After I have found it (half a days work), I can see in the de{*filter*} that the
the variable becomes -1.#IND
but the program goes on.
Is there a compiler flag or any other chance to make the program (in
debugging mode) stop at this line instead of
simply setting the value to infinity?

regards
  Uli



Tue, 05 Nov 2002 03:00:00 GMT  
 floating point exceptions
There is a function you can call. Use _controlfp() to enable divide by
zero and illegal operation exceptions. I recommend enabling these, at
least in the debug version, for every program you write. Otherwise you
may be doing all sorts of illegal floating point operations without ever
realizing it.

It's like putting asserts in front of every floating point operation.

Quote:

> Dear VC++ Gurus,
> I am debugging a COM dll. It is called by visual basic from excel.
> Somewhere in the code a floating exception occurs (division by 0 or
> pow(-1,0.5) or ln(-1) etc.)
> It seems that a flag is set or some exception is thrown because I get in the
> visual basic part the
> message that an exception occured but I dont have a chance to locate the
> SOURCE of the exception.

> After I have found it (half a days work), I can see in the de{*filter*} that the
> the variable becomes -1.#IND
> but the program goes on.
> Is there a compiler flag or any other chance to make the program (in
> debugging mode) stop at this line instead of
> simply setting the value to infinity?

> regards
>   Uli

--
.Bruce Dawson, Humongous Entertainment.
http://www.*-*-*.com/


Sat, 09 Nov 2002 03:00:00 GMT  
 floating point exceptions
Sorry to Bruce for pressing the wrong reply button doh!

I thought divide by zero was enabled by default. Wlil these exceptions be
caught by

try {
    int i = 20 / 0;

Quote:
} catch(...) {
}

On the same track we have had the situation for a long time were debug and
release builds give different results in a big floating point calculation.
Is there any way using the floating point support routines to find out where
things are going wrong/different ?

Thanks

PS
I have been told off about my antispam address several times but I don't
understand whats wrong as I got the idea of viewing news groups. Am I
supposed to just accept spam like I get in my hotmail account since I used
that to do some posting on news groups. Sorry for the of thread post but I'd
like to save people a big hassle when replying to me and also not be deluged
by spam

Thanks again

--


Quote:
> There is a function you can call. Use _controlfp() to enable divide by
> zero and illegal operation exceptions. I recommend enabling these, at
> least in the debug version, for every program you write. Otherwise you
> may be doing all sorts of illegal floating point operations without ever
> realizing it.

> It's like putting asserts in front of every floating point operation.


> > Dear VC++ Gurus,
> > I am debugging a COM dll. It is called by visual basic from excel.
> > Somewhere in the code a floating exception occurs (division by 0 or
> > pow(-1,0.5) or ln(-1) etc.)
> > It seems that a flag is set or some exception is thrown because I get in
the
> > visual basic part the
> > message that an exception occured but I dont have a chance to locate the
> > SOURCE of the exception.

> > After I have found it (half a days work), I can see in the de{*filter*} that
the
> > the variable becomes -1.#IND
> > but the program goes on.
> > Is there a compiler flag or any other chance to make the program (in
> > debugging mode) stop at this line instead of
> > simply setting the value to infinity?

> > regards
> >   Uli

> --
> .Bruce Dawson, Humongous Entertainment.
> http://www.*-*-*.com/



Sun, 10 Nov 2002 03:00:00 GMT  
 floating point exceptions
Integer divide by zero exceptions are always enabled. Floating point
divide by zero exceptions default to being disabled.

Using try/catch to catch CPU exceptions is non-portable and
generally a bad idea (IMHO). Also, the optimizer will by
default assume that the code that you give can not throw any
exceptions (since it can see there are no throw statements) so
it will optimize away the try/catch.

Divide by zero should be treated as a bug - a logic error. You
shouldn't catch bugs with try/catch. IMHO.

Optimized code will frequently give different floating point
results, especially if you use floats. Use the "Improve float
consistency" optimization option to avoid/reduce this.

Regarding anti-spam e-mail addresses - they may be a necessary
evil in newsgroup postings, but are (IMHO) best avoided when sending
e-mail (hence my comment). You can do what you like of course,
but you will miss some replies because of people not demangling
your return address. On my initial reply I did not notice that your
e-mail address was anti-spammed. It's easy to miss.

Quote:

> Sorry to Bruce for pressing the wrong reply button doh!

> I thought divide by zero was enabled by default. Wlil these exceptions be
> caught by

> try {
>     int i = 20 / 0;
> } catch(...) {
> }

> On the same track we have had the situation for a long time were debug and
> release builds give different results in a big floating point calculation.
> Is there any way using the floating point support routines to find out where
> things are going wrong/different ?

> Thanks

> PS
> I have been told off about my antispam address several times but I don't
> understand whats wrong as I got the idea of viewing news groups. Am I
> supposed to just accept spam like I get in my hotmail account since I used
> that to do some posting on news groups. Sorry for the of thread post but I'd
> like to save people a big hassle when replying to me and also not be deluged
> by spam

> Thanks again

> --



> > There is a function you can call. Use _controlfp() to enable divide by
> > zero and illegal operation exceptions. I recommend enabling these, at
> > least in the debug version, for every program you write. Otherwise you
> > may be doing all sorts of illegal floating point operations without ever
> > realizing it.

> > It's like putting asserts in front of every floating point operation.


> > > Dear VC++ Gurus,
> > > I am debugging a COM dll. It is called by visual basic from excel.
> > > Somewhere in the code a floating exception occurs (division by 0 or
> > > pow(-1,0.5) or ln(-1) etc.)
> > > It seems that a flag is set or some exception is thrown because I get in
> the
> > > visual basic part the
> > > message that an exception occured but I dont have a chance to locate the
> > > SOURCE of the exception.

> > > After I have found it (half a days work), I can see in the de{*filter*} that
> the
> > > the variable becomes -1.#IND
> > > but the program goes on.
> > > Is there a compiler flag or any other chance to make the program (in
> > > debugging mode) stop at this line instead of
> > > simply setting the value to infinity?

> > > regards
> > >   Uli

> > --
> > .Bruce Dawson, Humongous Entertainment.
> > http://www.*-*-*.com/

--
.Bruce Dawson, Humongous Entertainment.
http://www.*-*-*.com/


Sun, 10 Nov 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Floating Point Exceptions: MFC or Structured Exception Handling?

2. catching floating point exception - but where is it coming from

3. What causes Floating point exceptions?

4. Floating point exception

5. Stop on floating point exception

6. Why floating point exception ?

7. Floating Point Exceptions in Borland C

8. Trapping floating point exceptions in Sun C?

9. flagging floating point exception

10. Floating point exceptions

11. Help in dealing with floating point exceptions in C on UNIX/VAX

12. Help in dealing with floating point exceptions in C on UNIX/VAX

 

 
Powered by phpBB® Forum Software