Created
July 17, 2014 16:13
-
-
Save kosh04/edcc8001f87e33e7c0b7 to your computer and use it in GitHub Desktop.
Test matherr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see also: | |
// http://msdn.microsoft.com/ja-jp/library/k3backsw.aspx | |
// http://linuxjm.sourceforge.jp/html/LDP_man-pages/man3/matherr.3.html | |
#define _SVID_SOURCE | |
#include <math.h> | |
#include <string.h> | |
#include <stdio.h> | |
#ifdef _WIN32 | |
#define matherr _matherr | |
#define exception _exception | |
#endif | |
int main(int argc, char **argv) | |
{ | |
#ifdef __linux__ | |
_LIB_VERSION = _SVID_; | |
#endif | |
printf("log(-2.0) = %e\n", log(-2.0)); | |
printf("log10(-5.0) = %e\n", log10(-5.0)); | |
printf("log(0.0) = %e\n", log(0.0)); | |
return 0; | |
} | |
int matherr(struct exception *e) | |
{ | |
if (e->type == DOMAIN) { | |
if (strcmp(e->name, "log") == 0) | |
{ | |
e->retval = log(-(e->arg1)); | |
fprintf(stderr, "Special: using absolute value: %s: _DOMAIN error\n", e->name); | |
return 1; | |
} | |
else if (strcmp(e->name, "log10") == 0) | |
{ | |
e->retval = log10(-(e->arg1)); | |
fprintf(stderr, "Special: using absolute value: %s _DOMAIN error\n", e->name); | |
return 1; | |
} | |
} | |
fprintf(stderr, "Normal: "); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment