Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why was SIGFPE used for integer arithmetic exceptions?

Tags:

unix

posix

sigfpe

Why was SIGFPE used for integer arithmetic exceptions, such as division by zero, instead of creating a separate signal for integer arithmetic exceptions or naming the signal in the first place for arithmetic exceptions generally?

like image 893
Eric Postpischil Avatar asked Feb 08 '20 14:02

Eric Postpischil


People also ask

What does SIGFPE do?

The SIGFPE signal reports a fatal arithmetic error. Although the name is derived from “floating-point exception”, this signal actually covers all arithmetic errors, including division by zero and overflow.

What triggers SIGFPE?

The SIGFPE signal is raised when a computational error occurs. These errors include floating-point overflow, floating-point underflow, and either integer- or floating-point division by 0.

What is floating-point exception SIGFPE?

Floating-point exception when there is an error in floating-point arithmetic. Causes of floating-point exception include invalid operation and overflow. You cannot avoid floating-point errors, but you can manage them. SIGFPE is a signal raised by the floating-point exception.

How is floating-point exceptions handled?

If a floating-point exception interrupt occurs and you do not have an exception handling routine, the run-time system will respond to the interrupt according to the behavior selected by the compiler option /fpe. Remember, interrupts only occur if an exception is enabled (set to 0).


1 Answers

IEEE Std 1003.1 Standard defines SIGFPE as:

Erroneous arithmetic operation.

And doesn't really mention floating point operations. Reasoning behind this is not clearly stated, but here's my take on it.

x86 FPU can operate on both integer and floating point data at the same time with instructions such as FIDIV, thus it would be unclear whether dividing floating poitn data by integer zero would generate a floating or and integer point exception.

Additionally, up to 80486 (which was released the same year as the ISO/ANSI C standard) x86 CPUs did not have floating point capabilities at all, floating point co-processor was a separate chip. Software floating point emulation could be used in place of the chip, but that used CPU's built in ALU (integer arithmetic-logical unit) which would throw integer exceptions.

like image 200
Sos Sosowski Avatar answered Oct 19 '22 08:10

Sos Sosowski