EDOM
Linux / POSIXERRORNotableMathHIGH confidence

Math Argument Out of Domain

Production Risk

Silent NaN propagation from an unvalidated EDOM is a data integrity risk in numerical code.

What this means

EDOM (errno 33) is set by math library functions when an argument is outside the domain of the function — for example, passing a negative value to sqrt(), or log(0).

Why it happens
  1. 1sqrt() of a negative number
  2. 2log() or log2() of zero or a negative number
  3. 3asin() or acos() of a value outside [-1, 1]
  4. 4pow(0, negative) — mathematically undefined
How to reproduce

Taking the square root of a negative number.

trigger — this will error
trigger — this will error
#include <math.h>
#include <errno.h>
errno = 0;
double r = sqrt(-1.0);
// r = NaN, errno = EDOM

expected output

sqrt(-1) returns NaN, errno = EDOM

Fix

Validate inputs before calling math functions

WHEN Always — check domain preconditions before calling C math functions

Validate inputs before calling math functions
if (x < 0) {
    fprintf(stderr, "sqrt: negative input\n");
    return -1;
}
double r = sqrt(x);

Why this works

Math functions set errno=EDOM and return NaN for out-of-domain inputs. Validate inputs first to detect logic bugs early rather than propagating NaN.

What not to do

Ignore NaN propagation

NaN values spread silently through calculations. A single EDOM-causing call can corrupt downstream results without any obvious error.

Sources
Official documentation ↗

Linux Programmer Manual math_error(7)

sqrt(3)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Linux / POSIX errors