.\" the source, must acknowledge the copyright and authors of this work.
.\" %%%LICENSE_END
.\"
-.TH MATHERR 3 2014-06-13 "Linux" "Linux Programmer's Manual"
+.TH MATHERR 3 2017-09-15 "Linux" "Linux Programmer's Manual"
.SH NAME
matherr \- SVID math library exception handling
.SH SYNOPSIS
.nf
-.BR "#define _SVID_SOURCE" " /* See feature_test_macros(7) */"
.B #include <math.h>
-
+.PP
.BI "int matherr(struct exception *" exc );
-
+.PP
.B extern _LIB_VERSION_TYPE _LIB_VERSION;
.fi
-.sp
+.PP
Link with \fI\-lm\fP.
.SH DESCRIPTION
+.IR Note :
+the mechanism described in this page is no longer supported by glibc.
+Before glibc 2.27, it had been marked as obsolete.
+Since glibc 2.27,
+.\" glibc commit 813378e9fe17e029caf627cab76fe23eb46815fa
+the mechanism has been removed altogether.
+New applications should use the techniques described in
+.BR math_error (7)
+and
+.BR fenv (3).
+This page documents the
+.BR matherr ()
+mechanism as an aid for maintaining and porting older applications.
+.PP
The System V Interface Definition (SVID) specifies that various
math functions should invoke a function called
.BR matherr ()
.BR matherr ()
returns, the system then returns to the math function,
which in turn returns to the caller.
-
-The
-.BR matherr ()
-mechanism is supported by glibc, but is now obsolete:
-new applications should use the techniques described in
-.BR math_error (7)
-and
-.BR fenv (3).
-This page documents the glibc
-.BR matherr ()
-mechanism as an aid for maintaining and porting older applications.
-
+.PP
To employ
.BR matherr (),
the programmer must define the
.B _SVID_
to the external variable
.BR _LIB_VERSION .
-
+.PP
The system provides a default version of
.BR matherr ().
This version does nothing, and returns zero
The function is invoked with one argument, a pointer to an
.I exception
structure, defined as follows:
-
+.PP
.in +4n
-.nf
+.EX
struct exception {
int type; /* Exception type */
char *name; /* Name of function causing exception */
double arg2; /* 2nd argument to function */
double retval; /* Function return value */
}
-.fi
+.EE
.in
.PP
The
fields are the arguments supplied to the function
.RI ( arg2
is undefined for functions that take only one argument).
-
+.PP
The
.I retval
field specifies the return value that the math
The programmer-defined
.BR matherr ()
can modify this field to change the return value of the math function.
-
+.PP
If the
.BR matherr ()
function returns zero, then the system sets
.I errno
as described above, and may print an error message on standard error
(see below).
-
+.PP
If the
.BR matherr ()
function returns a nonzero value, then the system does not set
.BR matherr ().
The "Result" column is the default return value assigned to
.IR exc\->retval .
-
+.PP
The "Msg?" and "errno" columns describe the default behavior if
.BR matherr ()
returns zero.
If the "Msg?" columns contains "y",
then the system prints an error message on standard error.
-
+.PP
The table uses the following notations and abbreviations:
+.PP
.RS
.nf
-
x first argument to function
y second argument to function
fin finite value for argument
then it specifies an alternative return value that
.BR matherr ()
should assign as the return value of the math function.
-
+.PP
The following example run, where
.BR log (3)
is given an argument of 0.0, does not use
.BR matherr ():
-
+.PP
.in +4n
-.nf
+.EX
.RB "$" " ./a.out 0.0"
errno: Numerical result out of range
x=-inf
-.fi
+.EE
.in
-
+.PP
In the following run,
.BR matherr ()
is called, and returns 0:
-
+.PP
.in +4n
-.nf
+.EX
.RB "$" " ./a.out 0.0 0"
matherr SING exception in log() function
args: 0.000000, 0.000000
log: SING error
errno: Numerical argument out of domain
x=-340282346638528859811704183484516925440.000000
-.fi
+.EE
.in
-
+.PP
The message "log: SING error" was printed by the C library.
-
+.PP
In the following run,
.BR matherr ()
is called, and returns a nonzero value:
-
+.PP
.in +4n
-.nf
+.EX
.RB "$" " ./a.out 0.0 1"
matherr SING exception in log() function
args: 0.000000, 0.000000
retval: \-340282346638528859811704183484516925440.000000
x=-340282346638528859811704183484516925440.000000
-.fi
+.EE
.in
-
+.PP
In this case, the C library did not print a message, and
.I errno
was not set.
-
+.PP
In the following run,
.BR matherr ()
is called, changes the return value of the math function,
and returns a nonzero value:
-
+.PP
.in +4n
-.nf
+.EX
.RB "$" " ./a.out 0.0 1 12345.0"
matherr SING exception in log() function
args: 0.000000, 0.000000
retval: \-340282346638528859811704183484516925440.000000
x=12345.000000
-.fi
+.EE
.in
.SS Program source
\&
-.nf
+.EX
#define _SVID_SOURCE
#include <errno.h>
#include <math.h>
printf("x=%f\\n", x);
exit(EXIT_SUCCESS);
}
-.fi
+.EE
.SH SEE ALSO
.BR fenv (3),
.BR math_error (7),