Error Codes Wiki

Linux SIGFPE — Floating Point Exception (Arithmetic Error)

Warningsignal

Overview

Linux SIGFPE (signal 8) occurs from arithmetic errors including integer division by zero, integer overflow, and floating-point exceptions.

Key Details

  • SIGFPE (signal 8) is misleadingly named — it covers ALL arithmetic errors, not just floating-point
  • Most common cause: integer division by zero
  • Integer overflow does not normally raise SIGFPE unless compiled with -ftrapv (GCC)
  • Floating-point operations normally produce Inf/NaN instead of SIGFPE by default
  • SIGFPE from floating-point only occurs if FP exceptions are explicitly enabled (feenableexcept)

Common Causes

  • Integer division by zero (/ or % operator with divisor = 0)
  • Integer overflow with -ftrapv compiler flag enabled
  • Floating-point exception explicitly enabled with feenableexcept()
  • INT_MIN / -1 causing overflow in two's complement arithmetic
  • Modulo by zero (x % 0)

Steps

  1. 1Use GDB to find the exact line: gdb ./program, run, then 'bt' at SIGFPE
  2. 2Add division-by-zero guards in code: if (divisor != 0) result = x / divisor;
  3. 3For C code: compile with -fsanitize=integer for runtime overflow detection
  4. 4Check for INT_MIN / -1 edge case (yields INT_MIN + 1 which overflows)
  5. 5Review floating-point exception settings: check for feenableexcept() calls

Tags

linuxsigfpearithmetic-errorsignal-8division-by-zero

More in Signal

Frequently Asked Questions

Historical name from when all arithmetic was done by the floating-point unit. The name stuck even though it covers all arithmetic exceptions now.