Search code examples
cdivide-by-zero

Why does integer division by zero result in a floating point exception?


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.)


Solution

  • 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".