| Previous | Next |
| EDOM | EDEADLK |
ERANGE
Valid input, unusable result
ERANGE usually indicates that an operation is meaningful, but its result cannot be represented by the destination type or interface. Mathematical functions can use it for overflow and underflow. A pole error, such as log(0), also produces this result because the exact mathematical result is an infinity.
The same error is not restricted to floating-point math. strtol() returns LONG_MAX or LONG_MIN and sets errno to this result when a parsed integer overflows or underflows long. A caller that only looks at the returned boundary value cannot distinguish a real boundary value from a conversion failure.
How it differs from EDOM
| Condition | Meaning | Typical example |
|---|---|---|
EDOM | The input lies outside the function’s domain. | log(-1) or a negative base with a nonintegral pow() exponent. |
| This result | The operation is defined, but the result does not fit the target representation. | Overflow in pow() or an out-of-range integer parsed by strtol(). |
Checking and handling the condition
- For integer conversion, set
errnoto zero beforestrtol(), keep the end-pointer result, and then test for it. - For mathematical functions, clear floating-point exceptions before the call and inspect
FE_OVERFLOW,FE_UNDERFLOW, andFE_DIVBYZEROtogether with the function result anderrno. - Choose deliberately between rejecting the input, storing a wider type, scaling the value, or applying a documented saturation rule. Silent clamping can conceal an earlier data or unit error.
References
Looking for a different code? Search another status or error code.
