The EDOM is a macro defined in the errno.h header file. This macro helps to show a domain error, which occurs when an input argument is outside the domain over the defined mathematical function and the errno is set to EDOM.
#define EDOM some_value;
The EDOM macro does not take any parameters. The argument is out of domain means, consider the situation when we asking for the square root of a negative number.
The macro EDOM 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 value;
errno = 0;
value = sqrt(-10);
if(errno == EDOM) {
printf("Value is Invalid \n");
} else {
printf("Value is valid \n");
}
errno = 0;
value = sqrt(10);
if(errno == EDOM) {
printf("Value is Invalid\n");
} else {
printf("Value is valid\n");
}
return(0);
}
Output:
Value is Invalid Value is valid