For all functions, a domain error occurs if an input argument is outside the domain over which the mathematical function is defined. On a domain error, the function returns an implementation-defined value.
EDOM: Domain Error
#include <stdio.h>
#include <errno.h>
#include <math.h>
#define POSITIVE 25
#define NEGATIVE -25
int main()
{
double ret;
errno = 0;
ret = sqrt(NEGATIVE);
if (errno == EDOM) /*EDOM Signifies Domain Error*/
printf("Domain Error : Invalid Input To Function\n");
else
printf("Valid Input To Function\n");
errno = 0;
ret = sqrt(POSITIVE);
if (errno == EDOM)
printf("Domain Error : Invalid Input To Function\n");
else
printf("Valid Input To Function\n");
return 0;
}
/***
* Output
* Domain Error:Invalid Input To Function
* Valid Input To Function
***/
Dave Sinkula 2,398 long time no c Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.