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?
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.
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.
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With