matherr.3m
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 3M 代码 · 共 176 行
3M
176 行
.\" SCCSID: @(#)matherr.3m 8.1 9/11/90.TH matherr 3m VAX.SH Namematherr \- error-handling function for System V math library.SH Syntax.PP.B #include <math.h>.PP.B int matherr (x).br.B struct exception \(**x;.SH Description.NXR "matherr subroutine".NXR "error function" "System V and"The.PN matherrsubroutineis invoked by functions in the System V Math Library whenerrors are detected.Users may define their own procedures for handling errorsby including a function named.PN matherrin their programs.The.PN matherrsubroutine must be of the form described above.A pointer to the exception structure.I x\^will be passed to the user-supplied.PN matherrfunction when an error occurs.This structure,which is defined in the <math.h> header file, is as follows:.EXstruct exception { int type; char \(**name; double arg1, arg2, retval;};.EE.PPThe element.I type\^is an integer describing the type of error that has occurred, from thefollowing list of constants (defined in the header file):.EXDOMAIN domain errorSING singularityOVERFLOW overflowUNDERFLOW underflowTLOSS total loss of significancePLOSS partial loss of significance.EE.PPThe element.I name\^points to a string containingthe name of the function that had the error.The variables.I arg1\^and.I arg2\^are the arguments to the function that had the error.The.I retval\^is a double that is returned by the functionhaving the error.If it supplies a return value, the user's.PN matherr\^must return nonzero.If the default error value is to be returned, the user's.PN matherr\^must return 0..PPIf.PN matherr\^is not supplied by the user,the default error-handling procedures, described withthe math functions involved, will be invoked upon error.These procedures are also summarized in the table below.In every case,.I errno\^is set to nonzero and the program continues..SH Examples.NXR(e) "matherr subroutine" "using".EX 0matherr(x)register struct exception \(**x;{ switch (x\->type) { case DOMAIN: case SING: /\(** print message and abort \(**/ fprintf(stderr, "domain error in %s\en", x\->name); abort( ); case OVERFLOW: if (!strcmp("exp", x\->name)) { /\(** if exp, print message, return the argument \(**/ fprintf(stderr, "exp of %f\en", x\->arg1); x\->retval = x\->arg1; } else if (!strcmp("sinh", x\->name)) { /\(** if sinh, set errno, return 0 \(**/ errno = ERANGE; x\->retval = 0; } else /\(** otherwise, return HUGE \(**/ x\->retval = HUGE; break; case UNDERFLOW: return (0); /\(** execute default procedure \(**/ case TLOSS: case PLOSS: /\(** print message and return 0 \(**/ fprintf(stderr, "loss of significance in %s\en", x\->name); x\->retval = 0; break; } return (1);}.EE.PP.in 0.TSexpand box ;cB s s s s s sc | cI s s s s sc | c | c | c | c | c | cl | c | c | c | c | c | c .DEFAULT ERROR HANDLING PROCEDURES.NXR(t) "matherr subroutine" "error-handling procedures"_ Types of Errors_ DOMAIN SING OVERFLOW UNDERFLOW TLOSS PLOSS _BESSEL: \- \- H 0 M, 0 \(**y0, y1, yn M, \-H \- \- \- \- \- (neg. no.)_EXP: \- \- H 0 \-_POW: \- \- H 0 \- \-(neg.)\(**\(**(non- M, 0 \- \- \- \- \- int.), 0\(**\(**0_LOG:log(0): \- M, \-H \- \- \- \-log(neg.): M, \-H \- \- \- \- \-_SQRT: M, 0 \- \- \- \- \-_GAMMA: \- M, H \- \- \- \-_HYPOT: \- \- H \- \- \-_SINH, COSH: \- \- H \- \- \-_SIN, COS: \- \- \- \- M, 0 \(**_TAN: \- \- H \- M, 0 \(**_ACOS, ASIN: M, 0 \- \- \- \- \-.TE.PP.TSbox;cB sc l .ABBREVIATIONS \(** As much as possible of the value is returned. M Message is printed. H HUGE is returned. \-H \-HUGE is returned. 0 0 is returned..TE
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?