Division by zero in a C program results in abnormal termination with the error message Floating point exception (core dumped)
. This is unsurprising for floating point division, but why does it say this when integer division by zero occurs? Does integer division actually use the FPU under the hood?
(This is all on Linux under x86, by the way.)
Why Is There a Floating Point Exception (Core Dumped) Error? Floating point exception occurs because of several reasons such as invalid operation, division by zero, overflow, underflow, or inexact.
Floating point error means that there is a division by a zero value in your code. It can be a variable, input, or a function in use that returns zero value. You need to identify this variable/input/function and make sure that the returned value is not zero.
The division operator / means integer division if there is an integer on both sides of it. If one or two sides has a floating point number, then it means floating point division.
Dividing a floating-point value by zero doesn't throw an exception; it results in positive infinity, negative infinity, or not a number (NaN), according to the rules of IEEE 754 arithmetic.
Does integer division actually use the FPU under the hood?
No, Linux just generates SIGFPE in this case too (it's a legacy name whose usage has now been extended). Indeed, the Single Unix Specification defines SIGFPE as "Erroneous arithmetic operation".
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