'\" te .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] .TH MATHERR 3M "Sep 23, 1997" "SunOS 5.11" "Mathematical Library Functions" .SH NAME matherr \- math library exception-handling function .SH SYNOPSIS .LP .nf #include \fBint\fR \fBmatherr\fR(\fBstruct exception *\fR\fIexc\fR); .fi .SH DESCRIPTION .sp .LP The System V Interface Definition, Third Edition (SVID3) specifies that certain \fBlibm\fR functions call \fBmatherr()\fR when exceptions are detected. Users may define their own mechanisms for handling exceptions, by including a function named \fBmatherr()\fR in their programs. The \fBmatherr()\fR function is of the form described above. When an exception occurs, a pointer to the exception structure \fIexc\fR will be passed to the user-supplied \fBmatherr()\fR function. This structure, which is defined in the \fB\fR header file, is as follows: .sp .in +2 .nf struct exception { int type; char *name; double arg1, arg2, retval; }; .fi .in -2 .sp .LP The \fBtype\fR member is an integer describing the type of exception that has occurred, from the following list of constants (defined in the header file): .sp .ne 2 .mk .na \fB\fBDOMAIN\fR\fR .ad .RS 13n .rt argument domain exception .RE .sp .ne 2 .mk .na \fB\fBSING\fR\fR .ad .RS 13n .rt argument singularity .RE .sp .ne 2 .mk .na \fB\fBOVERFLOW\fR\fR .ad .RS 13n .rt overflow range exception .RE .sp .ne 2 .mk .na \fB\fBUNDERFLOW\fR\fR .ad .RS 13n .rt underflow range exception .RE .sp .ne 2 .mk .na \fB\fBTLOSS\fR\fR .ad .RS 13n .rt total loss of significance .RE .sp .ne 2 .mk .na \fB\fBPLOSS\fR\fR .ad .RS 13n .rt partial loss of significance .RE .sp .LP Both \fBTLOSS\fR and \fBPLOSS\fR reflect limitations of particular algorithms for trigonometric functions that suffer abrupt declines in accuracy at definite boundaries. Since the implementation does not suffer such abrupt declines, \fBPLOSS\fR is never signaled. \fBTLOSS\fR is signaled for Bessel functions \fIonly\fR to satisfy SVID3 requirements. .sp .LP The \fBname\fR member points to a string containing the name of the function that incurred the exception. The \fBarg1\fR and \fBarg2\fR members are the arguments with which the function was invoked. \fBretval\fR is set to the default value that will be returned by the function unless the user's \fBmatherr()\fR sets it to a different value. .sp .LP If the user's \fBmatherr()\fR function returns non-zero, no exception message will be printed and \fBerrno\fR is not set. .SH SVID3 STANDARD CONFORMANCE .sp .LP When an application is built as a SVID3 conforming application (see \fBstandards\fR(7)), if \fBmatherr()\fR is not supplied by the user, the default matherr exception-handling mechanisms, summarized in the table below, are invoked upon exception: .sp .ne 2 .mk .na \fB\fBDOMAIN\fR\fR .ad .RS 13n .rt 0.0 is usually returned, \fBerrno\fR is set to \fBEDOM\fR and a message is usually printed on standard error. .RE .sp .ne 2 .mk .na \fB\fBSING\fR\fR .ad .RS 13n .rt The largest finite single-precision number, \fBHUGE\fR of appropriate sign, is returned, \fBerrno\fR is set to \fBEDOM\fR, and a message is printed on standard error. .RE .sp .ne 2 .mk .na \fB\fBOVERFLOW\fR\fR .ad .RS 13n .rt The largest finite single-precision number, \fBHUGE\fR of appropriate sign, is usually returned and \fBerrno\fR is set to \fBERANGE\fR. .RE .sp .ne 2 .mk .na \fB\fBUNDERFLOW\fR\fR .ad .RS 13n .rt 0.0 is returned and \fBerrno\fR is set to \fBERANGE\fR. .RE .sp .ne 2 .mk .na \fB\fBTLOSS\fR\fR .ad .RS 13n .rt 0.0 is returned, \fBerrno\fR is set to \fBERANGE\fR, and a message is printed on standard error. .RE .sp .LP In general, \fBerrno\fR is not a reliable error indicator because it can be unexpectedly set by a function in a handler for an asynchronous signal. .SS "SVID3 ERROR HANDLING PROCEDURES (compile with cc \e-Xt)" .sp .sp .TS tab( ) box; cw(1.29i) |cw(.81i) |cw(.79i) |cw(.87i) |cw(1.03i) |cw(.71i) lw(1.29i) |lw(.81i) |lw(.79i) |lw(.87i) |lw(1.03i) |lw(.71i) . type DOMAIN SING OVERFLOW UNDERFLOW TLOSS _ \fBerrno\fR EDOM EDOM ERANGE ERANGE ERANGE _ IEEE Exception Invalid Operation Division by Zero Overflow Underflow \(mi _ fp_exception_type fp_invalid fp_division fp_overflow fp_underflow \(mi _ ACOS, ASIN\|(|x| > 1): Md, 0.0 \(mi \(mi \(mi \(mi _ ACOSH\|(x < 1), ATANH\|(|x| > 1): NaN \(mi \(mi \(mi \(mi _ ATAN2\|(0,0): Md, 0.0 \(mi \(mi \(mi \(mi _ COSH, SINH: \(mi \(mi \(+-HUGE \(mi \(mi _ EXP: \(mi \(mi +HUGE 0.0 \(mi _ FMOD\|(x,0): x \(mi \(mi \(mi \(mi _ HYPOT: \(mi \(mi +HUGE \(mi \(mi _ J0, J1, JN\|(|x| > X_TLOSS): \(mi \(mi \(mi \(mi Mt, 0.0 _ LGAMMA: usual cases \(mi \(mi +HUGE \(mi \(mi (x = 0 or \(miinteger) \(mi Ms, +HUGE \(mi \(mi \(mi _ LOG, LOG10: (x < 0) Md, \(miHUGE \(mi \(mi \(mi \(mi (x = 0) \(mi Ms, \(miHUGE \(mi \(mi \(mi _ POW: usual cases \(mi \(mi \(+-HUGE \(+-0.0 \(mi (x < 0) ** (y not an integer) Md, 0.0 \(mi \(mi \(mi \(mi 0 ** 0 Md, 0.0 \(mi \(mi \(mi \(mi 0 ** (y < 0) Md, 0.0 \(mi \(mi \(mi _ REMAINDER\|(x,0): NaN \(mi \(mi \(mi \(mi _ SCALB: \(mi \(mi \(+-HUGE_VAL \(+-0.0 \(mi _ SQRT\|(x < 0): Md, 0.0 \(mi \(mi \(mi \(mi _ Y0, Y1, YN: (x < 0) Md, \(miHUGE \(mi \(mi \(mi \(mi (x = 0) \(mi Md, \(miHUGE \(mi \(mi \(mi (x > X_TLOSS) \(mi \(mi \(mi \(mi Mt, 0.0 .TE .SS "Abbreviations" .sp .ne 2 .mk .na \fBMd\fR .ad .RS 12n .rt Message is printed (DOMAIN error). .RE .sp .ne 2 .mk .na \fBMs\fR .ad .RS 12n .rt Message is printed (SING error). .RE .sp .ne 2 .mk .na \fBMt\fR .ad .RS 12n .rt Message is printed (TLOSS error). .RE .sp .ne 2 .mk .na \fBNaN\fR .ad .RS 12n .rt IEEE NaN result and invalid operation exception. .RE .sp .ne 2 .mk .na \fBHUGE\fR .ad .RS 12n .rt Maximum finite single-precision floating-point number. .RE .sp .ne 2 .mk .na \fBHUGE_VAL\fR .ad .RS 12n .rt IEEE \(if result and division-by-zero exception. .RE .sp .ne 2 .mk .na \fBX_TLOSS\fR .ad .RS 12n .rt The value X_TLOSS is defined in . .RE .sp .LP The interaction of IEEE arithmetic and \fBmatherr()\fR is not defined when executing under IEEE rounding modes other than the default round to nearest: \fBmatherr()\fR is not always called on overflow or underflow and can return results that differ from those in this table. .SH X/OPEN COMMON APPLICATION ENVIRONMENT (CAE) SPECIFICATIONS CONFORMANCE .sp .LP The X/Open System Interfaces and Headers (XSH) Issue 3 and later revisions of that specification no longer sanctions the use of the \fBmatherr\fR interface. The following table summarizes the values returned in the exceptional cases. In general, XSH dictates that as long as one of the input argument(s) is a NaN, NaN is returned. In particular, \fBpow(NaN,0)\fR = NaN. .SS "CAE SPECIFICATION ERROR HANDLING PROCEDURES (compile with cc \fB-Xa\fR)" .sp .sp .TS tab( ) box; cw(.82i) |cw(1.03i) |cw(1i) |cw(.97i) |cw(.96i) |cw(.72i) lw(.82i) |lw(1.03i) |lw(1i) |lw(.97i) |lw(.96i) |lw(.72i) . type DOMAIN SING OVERFLOW UNDERFLOW TLOSS _ \fBerrno\fR EDOM EDOM ERANGE ERANGE ERANGE _ ACOS, ASIN\|(|x| > 1): 0.0 \(mi \(mi \(mi \(mi _ ATAN2\|(0,0): 0.0 \(mi \(mi \(mi \(mi _ COSH, SINH: \(mi \(mi {\(+-HUGE_VAL} \(mi \(mi _ EXP: \(mi \(mi {+HUGE_VAL} {0.0} \(mi _ FMOD\|(x,0): {NaN} \(mi \(mi \(mi \(mi _ HYPOT: \(mi \(mi {+HUGE_VAL} \(mi \(mi _ J0, J1, JN\|(|x| > X_TLOSS): \(mi \(mi \(mi \(mi {0.0} _ LGAMMA: usual cases \(mi \(mi {+HUGE_VAL} \(mi \(mi (x = 0 or \(miinteger) \(mi +HUGE_VAL \(mi \(mi \(mi _ LOG, LOG10: (x < 0) \fB-HUGE_VAL\fR \(mi \(mi \(mi \(mi (x = 0) \(mi \fB-HUGE_VAL\fR \(mi \(mi \(mi _ POW: usual cases \(mi \(mi \(+-HUGE_VAL \(+-0.0 \(mi (x < 0) ** (y not an integer) 0.0 \(mi \(mi \(mi \(mi 0 ** 0 {1.0} \(mi \(mi \(mi \(mi 0 ** (y < 0) {\fB-HUGE_VAL\fR} \(mi \(mi \(mi \(mi _ SQRT\|(x < 0): 0.0 \(mi \(mi \(mi \(mi _ Y0, Y1, YN: (x < 0) {\fB-HUGE_VAL\fR} \(mi \(mi \(mi \(mi (x = 0) \(mi {\fB-HUGE_VAL\fR} \(mi \(mi \(mi (x > X_TLOSS) \(mi \(mi \(mi \(mi 0.0 .TE .SS "Abbreviations" .sp .ne 2 .mk .na \fB{...}\fR .ad .RS 12n .rt \fBerrno\fR is not to be relied upon in all braced cases. .RE .sp .ne 2 .mk .na \fBNaN\fR .ad .RS 12n .rt IEEE NaN result and invalid operation exception. .RE .sp .ne 2 .mk .na \fBHUGE_VAL\fR .ad .RS 12n .rt IEEE \(if result and division-by-zero exception. .RE .sp .ne 2 .mk .na \fBX_TLOSS\fR .ad .RS 12n .rt The value X_TLOSS is defined in <\fBvalues.h\fR>. .RE .SH ANSI/ISO-C STANDARD CONFORMANCE .sp .LP The ANSI/ISO-C standard covers a small subset of the CAE specification. .sp .LP The following table summarizes the values returned in the exceptional cases. .SS "ANSI/ISO-C ERROR HANDLING PROCEDURES (compile with cc \fB-Xc\fR)" .sp .sp .TS tab( ) box; cw(1.1i) |cw(1.1i) |cw(1.1i) |cw(1.1i) |cw(1.11i) lw(1.1i) |lw(1.1i) |lw(1.1i) |lw(1.1i) |lw(1.11i) . type DOMAIN SING OVERFLOW UNDERFLOW _ \fBerrno\fR EDOM EDOM ERANGE ERANGE _ ACOS, ASIN\|(|x| > 1): 0.0 \(mi \(mi \(mi _ ATAN2\|(0,0): 0.0 \(mi \(mi \(mi _ EXP: \(mi \(mi +HUGE_VAL 0.0 _ FMOD\|(x,0): NaN \(mi \(mi \(mi _ LOG, LOG10: (x < 0) \fB-HUGE_VAL\fR \(mi \(mi \(mi (x = 0) \(mi \fB-HUGE_VAL\fR \(mi \(mi _ POW: usual cases \(mi \(mi \(+-HUGE_VAL \(+-0.0 (x < 0) ** (y not an integer) 0.0 \(mi \(mi \(mi 0 ** (y < 0) \fB-HUGE_VAL\fR \(mi \(mi \(mi _ SQRT\|(x < 0): 0.0 \(mi \(mi \(mi .TE .SS "ABBREVIATIONS" .sp .ne 2 .mk .na \fBNaN\fR .ad .RS 12n .rt IEEE NaN result and invalid operation exception. .RE .sp .ne 2 .mk .na \fBHUGE_VAL\fR .ad .RS 12n .rt IEEE \(if result and division-by-zero. .RE .SH EXAMPLES .LP \fBExample 1 \fRExample of \fBmatherr()\fR function .sp .in +2 .nf #include #include #include int matherr(struct exception *x) { switch (x\(mi>type) { case DOMAIN: /* change sqrt to return sqrt(\(miarg1), not NaN */ if (!strcmp(x\(mi>name, "sqrt")) { x\(mi>retval = sqrt(\(mix\(mi>arg1); return (0); /* print message and set errno */ } /* FALLTHRU */ case SING: /* all other domain or sing exceptions, print message and */ /* abort */ fprintf(stderr, "domain exception in %s\en", x\(mi>name); abort( ); break; } return (0); /* all other exceptions, execute default procedure */ } .fi .in -2 .SH ATTRIBUTES .sp .LP See \fBattributes\fR(7) for descriptions of the following attributes: .sp .sp .TS tab( ) box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPE ATTRIBUTE VALUE _ MT-Level MT-Safe .TE .SH SEE ALSO .sp .LP .BR attributes (7), .BR standards (7)