2 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH MATHERR 3M "Sep 23, 1997" "SunOS 5.11" "Mathematical Library Functions"
8 matherr \- math library exception-handling function
14 \fBint\fR \fBmatherr\fR(\fBstruct exception *\fR\fIexc\fR);
20 The System V Interface Definition, Third Edition (SVID3) specifies that certain
21 \fBlibm\fR functions call \fBmatherr()\fR when exceptions are detected. Users
22 may define their own mechanisms for handling exceptions, by including a
23 function named \fBmatherr()\fR in their programs. The \fBmatherr()\fR function
24 is of the form described above. When an exception occurs, a pointer to the
25 exception structure \fIexc\fR will be passed to the user-supplied
26 \fBmatherr()\fR function. This structure, which is defined in the
27 \fB<math.h>\fR header file, is as follows:
34 double arg1, arg2, retval;
41 The \fBtype\fR member is an integer describing the type of exception that has
42 occurred, from the following list of constants (defined in the header file):
51 argument domain exception
73 overflow range exception
84 underflow range exception
95 total loss of significance
106 partial loss of significance
111 Both \fBTLOSS\fR and \fBPLOSS\fR reflect limitations of particular algorithms
112 for trigonometric functions that suffer abrupt declines in accuracy at definite
113 boundaries. Since the implementation does not suffer such abrupt declines,
114 \fBPLOSS\fR is never signaled. \fBTLOSS\fR is signaled for Bessel functions
115 \fIonly\fR to satisfy SVID3 requirements.
118 The \fBname\fR member points to a string containing the name of the function
119 that incurred the exception. The \fBarg1\fR and \fBarg2\fR members are the
120 arguments with which the function was invoked. \fBretval\fR is set to the
121 default value that will be returned by the function unless the user's
122 \fBmatherr()\fR sets it to a different value.
125 If the user's \fBmatherr()\fR function returns non-zero, no exception message
126 will be printed and \fBerrno\fR is not set.
127 .SH SVID3 STANDARD CONFORMANCE
130 When an application is built as a SVID3 conforming application (see
131 \fBstandards\fR(5)), if \fBmatherr()\fR is not supplied by the user, the
132 default matherr exception-handling mechanisms, summarized in the table below,
133 are invoked upon exception:
142 0.0 is usually returned, \fBerrno\fR is set to \fBEDOM\fR and a message is
143 usually printed on standard error.
154 The largest finite single-precision number, \fBHUGE\fR of appropriate sign, is
155 returned, \fBerrno\fR is set to \fBEDOM\fR, and a message is printed on
167 The largest finite single-precision number, \fBHUGE\fR of appropriate sign, is
168 usually returned and \fBerrno\fR is set to \fBERANGE\fR.
175 \fB\fBUNDERFLOW\fR\fR
179 0.0 is returned and \fBerrno\fR is set to \fBERANGE\fR.
190 0.0 is returned, \fBerrno\fR is set to \fBERANGE\fR, and a message is printed
196 In general, \fBerrno\fR is not a reliable error indicator because it can be
197 unexpectedly set by a function in a handler for an asynchronous signal.
198 .SS "SVID3 ERROR HANDLING PROCEDURES (compile with cc \e-Xt)"
204 cw(1.29i) |cw(.81i) |cw(.79i) |cw(.87i) |cw(1.03i) |cw(.71i)
205 lw(1.29i) |lw(.81i) |lw(.79i) |lw(.87i) |lw(1.03i) |lw(.71i)
207 <math.h> type DOMAIN SING OVERFLOW UNDERFLOW TLOSS
209 \fBerrno\fR EDOM EDOM ERANGE ERANGE ERANGE
211 IEEE Exception Invalid Operation Division by Zero Overflow Underflow \(mi
213 fp_exception_type fp_invalid fp_division fp_overflow fp_underflow \(mi
215 ACOS, ASIN\|(|x| > 1): Md, 0.0 \(mi \(mi \(mi \(mi
217 ACOSH\|(x < 1), ATANH\|(|x| > 1): NaN \(mi \(mi \(mi \(mi
219 ATAN2\|(0,0): Md, 0.0 \(mi \(mi \(mi \(mi
221 COSH, SINH: \(mi \(mi \(+-HUGE \(mi \(mi
223 EXP: \(mi \(mi +HUGE 0.0 \(mi
225 FMOD\|(x,0): x \(mi \(mi \(mi \(mi
227 HYPOT: \(mi \(mi +HUGE \(mi \(mi
229 J0, J1, JN\|(|x| > X_TLOSS): \(mi \(mi \(mi \(mi Mt, 0.0
232 usual cases \(mi \(mi +HUGE \(mi \(mi
233 (x = 0 or \(miinteger) \(mi Ms, +HUGE \(mi \(mi \(mi
236 (x < 0) Md, \(miHUGE \(mi \(mi \(mi \(mi
237 (x = 0) \(mi Ms, \(miHUGE \(mi \(mi \(mi
240 usual cases \(mi \(mi \(+-HUGE \(+-0.0 \(mi
241 (x < 0) ** (y not an integer) Md, 0.0 \(mi \(mi \(mi \(mi
242 0 ** 0 Md, 0.0 \(mi \(mi \(mi \(mi
243 0 ** (y < 0) Md, 0.0 \(mi \(mi \(mi
245 REMAINDER\|(x,0): NaN \(mi \(mi \(mi \(mi
247 SCALB: \(mi \(mi \(+-HUGE_VAL \(+-0.0 \(mi
249 SQRT\|(x < 0): Md, 0.0 \(mi \(mi \(mi \(mi
252 (x < 0) Md, \(miHUGE \(mi \(mi \(mi \(mi
253 (x = 0) \(mi Md, \(miHUGE \(mi \(mi \(mi
254 (x > X_TLOSS) \(mi \(mi \(mi \(mi Mt, 0.0
266 Message is printed (DOMAIN error).
277 Message is printed (SING error).
288 Message is printed (TLOSS error).
299 IEEE NaN result and invalid operation exception.
310 Maximum finite single-precision floating-point number.
321 IEEE \(if result and division-by-zero exception.
332 The value X_TLOSS is defined in <values.h>.
337 The interaction of IEEE arithmetic and \fBmatherr()\fR is not defined when
338 executing under IEEE rounding modes other than the default round to nearest:
339 \fBmatherr()\fR is not always called on overflow or underflow and can return
340 results that differ from those in this table.
341 .SH X/OPEN COMMON APPLICATION ENVIRONMENT (CAE) SPECIFICATIONS CONFORMANCE
344 The X/Open System Interfaces and Headers (XSH) Issue 3 and later revisions of
345 that specification no longer sanctions the use of the \fBmatherr\fR interface.
346 The following table summarizes the values returned in the exceptional cases.
347 In general, XSH dictates that as long as one of the input argument(s) is a NaN,
348 NaN is returned. In particular, \fBpow(NaN,0)\fR = NaN.
349 .SS "CAE SPECIFICATION ERROR HANDLING PROCEDURES (compile with cc \fB-Xa\fR)"
355 cw(.82i) |cw(1.03i) |cw(1i) |cw(.97i) |cw(.96i) |cw(.72i)
356 lw(.82i) |lw(1.03i) |lw(1i) |lw(.97i) |lw(.96i) |lw(.72i)
358 <math.h> type DOMAIN SING OVERFLOW UNDERFLOW TLOSS
360 \fBerrno\fR EDOM EDOM ERANGE ERANGE ERANGE
362 ACOS, ASIN\|(|x| > 1): 0.0 \(mi \(mi \(mi \(mi
364 ATAN2\|(0,0): 0.0 \(mi \(mi \(mi \(mi
366 COSH, SINH: \(mi \(mi {\(+-HUGE_VAL} \(mi \(mi
368 EXP: \(mi \(mi {+HUGE_VAL} {0.0} \(mi
370 FMOD\|(x,0): {NaN} \(mi \(mi \(mi \(mi
372 HYPOT: \(mi \(mi {+HUGE_VAL} \(mi \(mi
374 J0, J1, JN\|(|x| > X_TLOSS): \(mi \(mi \(mi \(mi {0.0}
377 usual cases \(mi \(mi {+HUGE_VAL} \(mi \(mi
378 (x = 0 or \(miinteger) \(mi +HUGE_VAL \(mi \(mi \(mi
381 (x < 0) \fB-HUGE_VAL\fR \(mi \(mi \(mi \(mi
382 (x = 0) \(mi \fB-HUGE_VAL\fR \(mi \(mi \(mi
385 usual cases \(mi \(mi \(+-HUGE_VAL \(+-0.0 \(mi
386 (x < 0) ** (y not an integer) 0.0 \(mi \(mi \(mi \(mi
387 0 ** 0 {1.0} \(mi \(mi \(mi \(mi
388 0 ** (y < 0) {\fB-HUGE_VAL\fR} \(mi \(mi \(mi \(mi
390 SQRT\|(x < 0): 0.0 \(mi \(mi \(mi \(mi
393 (x < 0) {\fB-HUGE_VAL\fR} \(mi \(mi \(mi \(mi
394 (x = 0) \(mi {\fB-HUGE_VAL\fR} \(mi \(mi \(mi
395 (x > X_TLOSS) \(mi \(mi \(mi \(mi 0.0
407 \fBerrno\fR is not to be relied upon in all braced cases.
418 IEEE NaN result and invalid operation exception.
429 IEEE \(if result and division-by-zero exception.
440 The value X_TLOSS is defined in <\fBvalues.h\fR>.
443 .SH ANSI/ISO-C STANDARD CONFORMANCE
446 The ANSI/ISO-C standard covers a small subset of the CAE specification.
449 The following table summarizes the values returned in the exceptional cases.
450 .SS "ANSI/ISO-C ERROR HANDLING PROCEDURES (compile with cc \fB-Xc\fR)"
456 cw(1.1i) |cw(1.1i) |cw(1.1i) |cw(1.1i) |cw(1.11i)
457 lw(1.1i) |lw(1.1i) |lw(1.1i) |lw(1.1i) |lw(1.11i)
459 <math.h> type DOMAIN SING OVERFLOW UNDERFLOW
461 \fBerrno\fR EDOM EDOM ERANGE ERANGE
463 ACOS, ASIN\|(|x| > 1): 0.0 \(mi \(mi \(mi
465 ATAN2\|(0,0): 0.0 \(mi \(mi \(mi
467 EXP: \(mi \(mi +HUGE_VAL 0.0
469 FMOD\|(x,0): NaN \(mi \(mi \(mi
472 (x < 0) \fB-HUGE_VAL\fR \(mi \(mi \(mi
473 (x = 0) \(mi \fB-HUGE_VAL\fR \(mi \(mi
476 usual cases \(mi \(mi \(+-HUGE_VAL \(+-0.0
477 (x < 0) ** (y not an integer) 0.0 \(mi \(mi \(mi
478 0 ** (y < 0) \fB-HUGE_VAL\fR \(mi \(mi \(mi
480 SQRT\|(x < 0): 0.0 \(mi \(mi \(mi
492 IEEE NaN result and invalid operation exception.
503 IEEE \(if result and division-by-zero.
508 \fBExample 1 \fRExample of \fBmatherr()\fR function
517 matherr(struct exception *x) {
518 switch (x\(mi>type) {
520 /* change sqrt to return sqrt(\(miarg1), not NaN */
521 if (!strcmp(x\(mi>name, "sqrt")) {
522 x\(mi>retval = sqrt(\(mix\(mi>arg1);
523 return (0); /* print message and set errno */
526 /* all other domain or sing exceptions, print message and */
528 fprintf(stderr, "domain exception in %s\en", x\(mi>name);
532 return (0); /* all other exceptions, execute default procedure */
540 See \fBattributes\fR(5) for descriptions of the following attributes:
549 ATTRIBUTE TYPE ATTRIBUTE VALUE
557 \fBattributes\fR(5), \fBstandards\fR(5)