svcadm(8)을 검색하려면 섹션에서 8 을 선택하고, 맨 페이지 이름에 svcadm을 입력하고 검색을 누른다.
matherr(3m)
Mathematical Library Functions matherr(3M)
NAME
matherr - math library exception-handling function
SYNOPSIS
#include <math.h>
int matherr(struct exception *exc);
DESCRIPTION
The System V Interface Definition, Third Edition (SVID3) specifies that
certain libm functions call matherr() when exceptions are detected.
Users may define their own mechanisms for handling exceptions, by
including a function named matherr() in their programs. The matherr()
function is of the form described above. When an exception occurs, a
pointer to the exception structure exc will be passed to the user-sup‐
plied matherr() function. This structure, which is defined in the
<math.h> header file, is as follows:
struct exception {
int type;
char *name;
double arg1, arg2, retval;
};
The type member is an integer describing the type of exception that has
occurred, from the following list of constants (defined in the header
file):
DOMAIN argument domain exception
SING argument singularity
OVERFLOW overflow range exception
UNDERFLOW underflow range exception
TLOSS total loss of significance
PLOSS partial loss of significance
Both TLOSS and PLOSS reflect limitations of particular algorithms for
trigonometric functions that suffer abrupt declines in accuracy at def‐
inite boundaries. Since the implementation does not suffer such abrupt
declines, PLOSS is never signaled. TLOSS is signaled for Bessel func‐
tions only to satisfy SVID3 requirements.
The name member points to a string containing the name of the function
that incurred the exception. The arg1 and arg2 members are the argu‐
ments with which the function was invoked. retval is set to the default
value that will be returned by the function unless the user's matherr()
sets it to a different value.
If the user's matherr() function returns non-zero, no exception message
will be printed and errno is not set.
SVID3 STANDARD CONFORMANCE
When an application is built as a SVID3 conforming application (see
standards(7)), if matherr() is not supplied by the user, the default
matherr exception-handling mechanisms, summarized in the table below,
are invoked upon exception:
DOMAIN 0.0 is usually returned, errno is set to EDOM and a mes‐
sage is usually printed on standard error.
SING The largest finite single-precision number, HUGE of appro‐
priate sign, is returned, errno is set to EDOM, and a mes‐
sage is printed on standard error.
OVERFLOW The largest finite single-precision number, HUGE of appro‐
priate sign, is usually returned and errno is set to
ERANGE.
UNDERFLOW 0.0 is returned and errno is set to ERANGE.
TLOSS 0.0 is returned, errno is set to ERANGE, and a message is
printed on standard error.
In general, errno is not a reliable error indicator because it can be
unexpectedly set by a function in a handler for an asynchronous signal.
SVID3 ERROR HANDLING PROCEDURES (compile with cc \-Xt)
tab() box; cw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|lw(0.71i) lw(1.29i) |cw(0.81i) |cw(0.79i) |cw(0.88i) |cw(1.03i)
|cw(0.71i)
<math.h> typeDOMAINSINGOVERFLOWUNDERFLOWTLOSS _ errnoEDOME‐
DOMERANGEERANGEERANGE _ IEEE ExceptionInvalid OperationDivision by
ZeroOverflowUnderflow− _ fp_exception_typefp_invalidfp_divisionfp_over‐
flowfp_underflow − _ ACOS, ASIN(|x| > 1):Md, 0.0−−− − _ ACOSH(x < 1),
ATANH(|x| > 1):NaN−−−− _ ATAN2(0,0):Md, 0.0−−−− _ COSH, SINH:−−±HUGE−−
_ EXP:−−+HUGE0.0− _ FMOD(x,0):x−−−− _ HYPOT:−−+HUGE−− _ J0, J1, JN(|x|
> X_TLOSS):−−−−Mt, 0.0 _ LGAMMA:
usual cases−−+HUGE− −
(x = 0 or −integer) −Ms, +HUGE−− − _ LOG, LOG10:
(x < 0)Md, −HUGE− −− −
(x = 0)−Ms, −HUGE−−− _ POW:
usual cases−−±HUGE±0.0 −
(x < 0) ** (y not an integer)Md, 0.0−−−−
0 ** 0Md, 0.0−−−−
0 ** (y < 0)Md, 0.0−−− _ REMAINDER(x,0):NaN−−−− _
SCALB:−−±HUGE_VAL±0.0− _ SQRT(x < 0):Md, 0.0−−− − _ Y0, Y1, YN:
(x < 0)Md, −HUGE−−− −
(x = 0)−Md, −HUGE−− −
(x > X_TLOSS)−−−−Mt, 0.0
Abbreviations
Md Message is printed (DOMAIN error).
Ms Message is printed (SING error).
Mt Message is printed (TLOSS error).
NaN IEEE NaN result and invalid operation exception.
HUGE Maximum finite single-precision floating-point number.
HUGE_VAL IEEE ∞ result and division-by-zero exception.
X_TLOSS The value X_TLOSS is defined in <values.h>.
The interaction of IEEE arithmetic and matherr() is not defined when
executing under IEEE rounding modes other than the default round to
nearest: matherr() is not always called on overflow or underflow and
can return results that differ from those in this table.
X/OPEN COMMON APPLICATION ENVIRONMENT (CAE) SPECIFICATIONS CONFORMANCE
The X/Open System Interfaces and Headers (XSH) Issue 3 and later revi‐
sions of that specification no longer sanctions the use of the matherr
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, pow(NaN,0)
= NaN.
CAE SPECIFICATION ERROR HANDLING PROCEDURES (compile with cc -Xa)
tab() box; cw(0.82i) |cw(1.03i) |cw(1i) |cw(0.97i) |cw(0.96i)
|cw(0.72i) lw(0.82i) |cw(1.03i) |cw(1i) |cw(0.97i) |cw(0.96i)
|cw(0.72i)
<math.h> typeDOMAINSINGOVERFLOWUNDERFLOWTLOSS _ errnoEDOME‐
DOMERANGEERANGEERANGE _ ACOS, ASIN(|x| > 1):0.0−−− − _
ATAN2(0,0):0.0−−−− _ COSH, SINH:−−{±HUGE_VAL}− − _
EXP:−−{+HUGE_VAL}{0.0}− _ FMOD(x,0):{NaN}−−−− _ HYPOT:−−{+HUGE_VAL}−− _
J0, J1, JN(|x| > X_TLOSS):−−−−{0.0} _ LGAMMA:
usual cases−−{+HUGE_VAL}− −
(x = 0 or −integer) −+HUGE_VAL−− − _ LOG, LOG10:
(x < 0)-HUGE_VAL−−−−
(x = 0)−-HUGE_VAL−− − _ POW:
usual cases−−±HUGE_VAL±0.0−
(x < 0) ** (y not an integer)0.0−−−−
0 ** 0{1.0}−−−−
0 ** (y < 0){-HUGE_VAL}−−−− _ SQRT(x < 0):0.0−−−− _ Y0, Y1, YN:
(x < 0){-HUGE_VAL}−−−−
(x = 0)−{-HUGE_VAL}−−−
(x > X_TLOSS)−−−−0.0
Abbreviations
{...} errno is not to be relied upon in all braced cases.
NaN IEEE NaN result and invalid operation exception.
HUGE_VAL IEEE ∞ result and division-by-zero exception.
X_TLOSS The value X_TLOSS is defined in <values.h>.
ANSI/ISO-C STANDARD CONFORMANCE
The ANSI/ISO-C standard covers a small subset of the CAE specification.
The following table summarizes the values returned in the exceptional
cases.
ANSI/ISO-C ERROR HANDLING PROCEDURES (compile with cc -Xc)
tab() box; cw(1.1i) |cw(1.1i) |cw(1.1i) |cw(1.1i) |cw(1.11i) lw(1.1i)
|cw(1.1i) |cw(1.1i) |cw(1.1i) |cw(1.11i)
<math.h> typeDOMAINSINGOVERFLOWUNDERFLOW _ errnoEDOMEDOMERANGEERANGE _
ACOS, ASIN(|x| > 1):0.0−−− _ ATAN2(0,0):0.0−−− _ EXP:−−+HUGE_VAL0.0 _
FMOD(x,0):NaN−−− _ LOG, LOG10:
(x < 0)-HUGE_VAL−−−
(x = 0)−-HUGE_VAL−− _ POW:
usual cases−−±HUGE_VAL±0.0
(x < 0) ** (y not an integer)0.0−−−
0 ** (y < 0)-HUGE_VAL−−− _ SQRT(x < 0):0.0−−−
ABBREVIATIONS
NaN IEEE NaN result and invalid operation exception.
HUGE_VAL IEEE ∞ result and division-by-zero.
EXAMPLES
Example 1 Example of matherr() function
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int
matherr(struct exception *x) {
switch (x−>type) {
case DOMAIN:
/* change sqrt to return sqrt(−arg1), not NaN */
if (!strcmp(x−>name, "sqrt")) {
x−>retval = sqrt(−x−>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\n", x−>name);
abort( );
break;
}
return (0); /* all other exceptions, execute default procedure */
}
ATTRIBUTES
See attributes(7) for descriptions of the following attributes:
tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i)
ATTRIBUTE TYPEATTRIBUTE VALUE _ MT-LevelMT-Safe _ Availabilitysys‐
tem/library/math
SEE ALSO
attributes(7), standards(7)
Solaris 11.4 27 Sept 2016 matherr(3M)