The ERANGE is a macro defined in the errno.h header file. This macro helps to show a range error, which occurs when an input argument is outside the range over the defined mathematical function and the errno is set to ERANGE.
#define ERANGE some_value;
The ERANGE macro does not take any parameters. The argument is out of range means, consider the situation when there is an overflow from the pow function.
The macro ERANGE does not return any value, it expands to a nonzero integer constant and its value is implementation-defined.
#include <stdio.h>
#include <errno.h>
#include <math.h>
int main () {
double k;
double v;
k = 2.000000;
v = log(k);
if( errno == ERANGE ) {
printf("Log(%f) is said to be out of range\n", k);
} else {
printf("Log(%f) is %f\n", k, v);
}
k = 1.000000;
v = log(k);
if( errno == ERANGE ) {
printf("Log(%f) is said to be out of range\n", k);
} else {
printf("Log(%f) is %f\n", k, v);
}
k = 0.000000;
v = log(k);
if( errno == ERANGE ) {
printf("Log(%f) is said to be out of range\n", k);
} else {
printf("Log(%f) is %f\n", k, v);
}
return 0;
}
Output:
Log(2.000000) is 0.693147 Log(1.000000) is 0.000000 Log(0.000000) is said to be out of range