C EDOM

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; 

 

EDOM Parameters: 

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.

 

EDOM Return Value

The macro EDOM does not return any value, it expands to a nonzero integer constant and its value is implementation-defined.


 

Examples of EDOM

Example 1: Working of EDOM function in C?


#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