matherr(3) Library Functions Manual matherr(3) matherr - SVID LIBRARY Math library (libm, -lm) #include [[deprecated]] int matherr(struct exception *exc); [[deprecated]] extern _LIB_VERSION_TYPE _LIB_VERSION; : , , glibc. glibc 2.27 . glibc 2.27, . , math_error(7) fenv(3). matherr() . System V Interface Definition (SVID) matherr(), . ; matherr() , , , . matherr(), _SVID_SOURCE ( - ) _SVID_ _LIB_VERSION. matherr() . ( ). matherr() , . , exception, : struct exception { int type; /* */ char *name; /* , */ double arg1; /* 1- */ double arg2; /* 2- */ double retval; /* , */ } type : DOMAIN ( , ). ; errno EDOM. SING ( ). , , HUGE ( ) . , errno EDOM. OVERFLOW . , HUGE errno ERANGE. UNDERFLOW . 0.0 errno ERANGE. TLOSS . 0.0 errno ERANGE. PLOSS . glibc ( ). arg1 arg2 , (arg2 , ). retval , . matherr() , . matherr() , errno ( ). matherr() , errno . , matherr() matherr(). <<>> , exc->type, matherr(). <<>> . exc->retval. <<?>> <> , matherr() . <<?>> <>, . : x first argument to function y second argument to function fin finite value for argument neg negative value for argument int integral value for argument o/f result overflowed u/f result underflowed |x| absolute value of x X_TLOSS is a constant defined in ? errno acos(|x|>1) DOMAIN HUGE EDOM asin(|x|>1) DOMAIN HUGE EDOM atan2(0,0) DOMAIN HUGE EDOM acosh(x<1) DOMAIN NAN EDOM atanh(|x|>1) DOMAIN NAN EDOM atanh(|x|==1) SING (x>0.0)? EDOM HUGE_VAL : -HUGE_VAL cosh(fin) o/f OVERFLOW HUGE ERANGE sinh(fin) o/f OVERFLOW (x>0.0) ? ERANGE HUGE : -HUGE sqrt(x<0) DOMAIN 0.0 EDOM hypot(fin,fin) o/f OVERFLOW HUGE ERANGE exp(fin) o/f OVERFLOW HUGE ERANGE exp(fin) u/f UNDERFLOW 0.0 ERANGE exp2(fin) o/f OVERFLOW HUGE ERANGE exp2(fin) u/f UNDERFLOW 0.0 ERANGE exp10(fin) o/f OVERFLOW HUGE ERANGE exp10(fin) u/f UNDERFLOW 0.0 ERANGE j0(|x|>X_TLOSS) TLOSS 0.0 ERANGE j1(|x|>X_TLOSS) TLOSS 0.0 ERANGE jn(|x|>X_TLOSS) TLOSS 0.0 ERANGE y0(x>X_TLOSS) TLOSS 0.0 ERANGE y1(x>X_TLOSS) TLOSS 0.0 ERANGE yn(x>X_TLOSS) TLOSS 0.0 ERANGE y0(0) DOMAIN -HUGE EDOM y0(x<0) DOMAIN -HUGE EDOM y1(0) DOMAIN -HUGE EDOM y1(x<0) DOMAIN -HUGE EDOM yn(n,0) DOMAIN -HUGE EDOM yn(x<0) DOMAIN -HUGE EDOM lgamma(fin) o/f OVERFLOW HUGE ERANGE lgamma(-int) SING HUGE EDOM lgamma(0) tgamma(fin) o/f OVERFLOW HUGE_VAL ERANGE tgamma(-int) SING NAN EDOM tgamma(0) SING copysign( ERANGE HUGE_VAL,x) log(0) SING -HUGE EDOM log(x<0) DOMAIN -HUGE EDOM log2(0) SING -HUGE EDOM log2(x<0) DOMAIN -HUGE EDOM log10(0) SING -HUGE EDOM log10(x<0) DOMAIN -HUGE EDOM pow(0.0,0.0) DOMAIN 0.0 EDOM pow(x,y) o/f OVERFLOW HUGE ERANGE pow(x,y) u/f UNDERFLOW 0.0 ERANGE pow(NaN,0.0) DOMAIN x EDOM 0**neg DOMAIN 0.0 EDOM neg**non-int DOMAIN 0.0 EDOM scalb() o/f OVERFLOW (x>0.0) ? ERANGE HUGE_VAL : -HUGE_VAL scalb() u/f UNDERFLOW copysign( ERANGE 0.0,x) fmod(x,0) DOMAIN x EDOM remainder(x,0) DOMAIN NAN EDOM attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |matherr() | | MT-Safe | +----------------------------+----------------------------------------------------------+--------------------------+ matherr() log(3). . -- , log(3). , _LIB_VERSION _SVID_ , matherr(), matherr(). , , matherr() . , log(3) 0.0 matherr(): \$ ./a.out 0.0 errno: x=-inf matherr() 0: \$ ./a.out 0.0 0 matherr SING log() : 0.000000, 0.000000 ..: -340282346638528859811704183484516925440.000000 log: SING error errno: x=-340282346638528859811704183484516925440.000000 <> . matherr() : \$ ./a.out 0.0 1 matherr SING log() : 0.000000, 0.000000 ..: -340282346638528859811704183484516925440.000000 x=-340282346638528859811704183484516925440.000000 , errno . matherr(), : \$ ./a.out 0.0 1 12345.0 matherr SING log() : 0.000000, 0.000000 ..: -340282346638528859811704183484516925440.000000 x=12345.000000 #define _SVID_SOURCE #include #include #include #include static int matherr_ret = 0; /* Value that matherr() should return */ static int change_retval = 0; /* Should matherr() change function's return value? */ static double new_retval; /* New function return value */ int matherr(struct exception *exc) { fprintf(stderr, "matherr %s exception in %s() function\n", (exc->type == DOMAIN) ? "DOMAIN" : (exc->type == OVERFLOW) ? "OVERFLOW" : (exc->type == UNDERFLOW) ? "UNDERFLOW" : (exc->type == SING) ? "SING" : (exc->type == TLOSS) ? "TLOSS" : (exc->type == PLOSS) ? "PLOSS" : "???", exc->name); fprintf(stderr, " args: %f, %f\n", exc->arg1, exc->arg2); fprintf(stderr, " retval: %f\n", exc->retval); if (change_retval) exc->retval = new_retval; return matherr_ret; } int main(int argc, char *argv[]) { double x; if (argc < 2) { fprintf(stderr, "Usage: %s " " [ []]\n", argv[0]); exit(EXIT_FAILURE); } if (argc > 2) { _LIB_VERSION = _SVID_; matherr_ret = atoi(argv[2]); } if (argc > 3) { change_retval = 1; new_retval = atof(argv[3]); } x = log(atof(argv[1])); if (errno != 0) perror("errno"); printf("x=%f\n", x); exit(EXIT_SUCCESS); } fenv(3), math_error(7), standards(7) aereiae , Alexey , Azamat Hackimov , Dmitriy S. Seregin , Dmitry Bolkhovskikh , ITriskTI , Max Is , Yuri Kozlov , ; GNU (GNU General Public License - GPL, 3 ) , - . - , , <>. Linux man-pages 6.8 2 2024 . matherr(3)