floating exception??!!

Write here if you have problems with your C source code

Moderator: Board moderators

Post Reply
Melon Melon
New poster
Posts: 17
Joined: Fri May 31, 2002 6:30 pm
Contact:

floating exception??!!

Post by Melon Melon »

:roll: what "floating exception" is....
and how to deal with it............
10153EN
Experienced poster
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:

Post by 10153EN »

Example of floating exception includes division by zero.

I think you can take a look at your program to see if there's such case.
Juergen Werner
New poster
Posts: 27
Joined: Wed Apr 17, 2002 7:54 pm

Post by Juergen Werner »

More about SIGFPE can be found e.g. here:

http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?sigfpe+3
(unfortunately it doesn't tell from which unix version the manpage is taken from)

A short excerpt:

The signal SIGFPE may be raised by the floating-point accelerator upon five different conditions (overflow, underflow, divide-by-zero, inexact result, invalid operand), but usually these conditions are masked and instead of an exception a default value is used as the result of the operation.

In addition, the SIGFPE can be generated by several integer arithmetic instructions (seems nobody wanted to spend another different signal for this?), some of which are usually not masked and cause the FPE, the most common is the division by zero, I guess.

How to handle it?:
There is the possibility to have your own function called whenever a SIGFPE is generated, but for solving problems on this site, in my opinion, there is no need to do this (since the program should not generate them at all).

Example C++ source / output (the result depends on which conditions are masked on the system):

Code: Select all

double f = 1.0e1000, g = acos(2);
cout << f << endl;
cout << g << endl; 
cout << 1.0 / 0.0 << endl;
cout << 0.0 / 0.0 << endl; 
cout << 1 / 0 << endl;

inf
nan
inf
nan
Floating point exception
Post Reply

Return to “C”