- SIGFPE
Infobox Computing signal
description = Erroneous arithmetic operation
action = Abnormal termination of the process
FPE_INTDIV | Integer divide by zero
FPE_INTOVF | Integer overflow
FPE_FLTDIV | Floating-point divide by zero
FPE_FLTOVF | Floating-point overflow
FPE_FLTUND | Floating-point underflow
FPE_FLTRES | Floating-point inexact result
FPE_FLTINV | Invalid floating-point operation
FPE_FLTSUB | Subscript out of rangeSIGFPE is the signal sent to computer programs that perform erroneous arithmetic operations on
POSIX compliant platforms. The symbolic constant for SIGFPE is defined in theheader file
. Symbolic signal names are used because signal numbers can vary across platforms.signal.h Etymology
"SIG" is a common
prefix for signal names; "FPE" is anacronym for "floating-point exception". Although SIGFPE does not necessarily involvefloating-point arithmetic , there is no way to change its name without breakingbackward compatibility .Description
SIGFPE is sent to processes for a variety of reasons. A common example might be an unexpected type overflow (eg, unsigned integer) owing to exceptional input, or an error in a program construct.
SIGFPE can be handled. That is, programmers can specify the action they want to occur on receiving the signal, such as calling a
subroutine , ignoring the event, or restoring the default action.Under certain circumstances, ignoring SIGFPE can result in
undefined behaviour . In particular, the program may hang as the offending operation is forever retried. However, it is safe to ignore SIGFPE signals not actually resulting from computation, such as those sent via thekill
system call .A common oversight is to consider division by zero the only source of SIGFPE conditions. On some architectures (IA-32 included), integer division of INT_MIN, the smallest representable negative integer value, by −1 triggers the signal because the quotient, a positive number, is not representable.
Example
Here is an example of an
ANSI C program that attempts to perform an erroneous arithmetic operation, namelyinteger division by zero , or "FPE_INTDIV".int main() { int x = 42/0; return 0; /* Never reached */ }
Compiling and running it on
IA-32 withLinux produces the following:$ gcc -o sigfpe sigfpe.c sigfpe.c: In function ‘main’: sigfpe.c:3: warning: division by zero $ ./sigfpe Floating point exception (core dumped)
A
backtrace fromgdb shows that the SIGFPE signal occurred in themain
function:Program received signal SIGFPE, Arithmetic exception. 0x08048373 in main ()
Compare the output from SIGFPE with that of a segmentation fault or the SIGILL signal for illegal instructions.
See also
*
Division by zero
*Floating point
Wikimedia Foundation. 2010.