•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 397,759 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,461 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
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.
Last edited : Dec 16th, 2006.
#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 ***/
Comments (Newest First)
Dave Sinkula | long time no c | Jan 23rd, 2007
•
•
•
•
Consider also using
perror to diagnose the problem.#include <stdio.h>
#include <errno.h>
#include <math.h>
void test(double value)
{
double ret;
errno = 0;
ret = sqrt(value);
if ( errno )
{
perror("sqrt");
}
else
{
printf("ret = %g\n", ret);
}
}
int main()
{
test(-25);
test(25);
}
/* my output
sqrt: Domain error
ret = 5
*/Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)