Manpage of LIBM
This file documents an ANSI-C conforming mathematical subroutine
library.
Copyright (C) 1992, 1993, 1995, 1996-2004 Red Hat, Inc.
`libm' includes software developed at SunPro, a Sun Microsystems,
Inc. business. Permission to use, copy, modify, and distribute this
software is freely granted, provided that this notice is preserved.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, subject to the
terms of the GNU General Public License, which includes the provision
that the entire resulting derived work is distributed under the terms
of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions.
LIBM
****
* Menu:
* Math:: The mathematical functions (`math.h').
* Reentrancy:: The functions in libm are not reentrant by default.
* Index::
1 Mathematical Functions (`math.h')
***********************************
This chapter groups a wide variety of mathematical functions. The corresponding definitions and declarations are in `math.h'. Two definitions from `math.h' are of particular interest.
1. The representation of infinity as a `double' is defined as
`HUGE_VAL'; this number is returned on overflow by many functions.
2. The structure `exception' is used when you write customized error
handlers for the mathematical functions. You can customize error
handling for most of these functions by defining your own version
of `matherr'; see the section on `matherr' for details.
Since the error handling code calls `fputs', the mathematical
subroutines require stubs or minimal implementations for the same list
of OS subroutines as `fputs': `close', `fstat', `isatty', `lseek',
`read', `sbrk', `write'. *Note System Calls: (libc.info)syscalls, for
a discussion and for sample minimal implementations of these support
subroutines.
Alternative declarations of the mathematical functions, which exploit
specific machine capabilities to operate faster--but generally have
less error checking and may reflect additional limitations on some
machines--are available when you include `fastmath.h' instead of
`math.h'.
* Menu:
* version:: Version of library
* acos:: Arccosine
* acosh:: Inverse hyperbolic cosine
* asin:: Arcsine
* asinh:: Inverse hyperbolic sine
* atan:: Arctangent
* atan2:: Arctangent of y/x
* atanh:: Inverse hyperbolic tangent
* jN:: Bessel functions (jN, yN)
* cbrt:: Cube root
* copysign:: Sign of Y, magnitude of X
* cosh:: Hyperbolic cosine
* erf:: Error function (erf, erfc)
* exp:: Exponential
* expm1:: Exponential of x, - 1
* fabs:: Absolute value (magnitude)
* floor:: Floor and ceiling (floor, ceil)
* fmod:: Floating-point remainder (modulo)
* frexp:: Split floating-point number
* gamma:: Logarithmic gamma function
* hypot:: Distance from origin
* ilogb:: Get exponent
* infinity:: Floating infinity
* isnan:: Check type of number
* ldexp:: Load exponent
* log:: Natural logarithms
* log10:: Base 10 logarithms
* log1p:: Log of 1 + X
* matherr:: Modifiable math error handler
* modf:: Split fractional and integer parts
* nan:: Floating Not a Number
* nextafter:: Get next representable number
* pow:: X to the power Y
* remainder:: remainder of X divided by Y
* scalbn:: scalbn
* sin:: Sine or cosine (sin, cos)
* sinh:: Hyperbolic sine
* sqrt:: Positive square root
* tan:: Tangent
* tanh:: Hyperbolic tangent
1.1 Version of library
There are four different versions of the math library routines: IEEE, POSIX, X/Open, or SVID. The version may be selected at runtime by setting the global variable `_LIB_VERSION', defined in `math.h'. It may be set to one of the following constants defined in `math.h': `_IEEE_', `_POSIX_', `_XOPEN_', or `_SVID_'. The `_LIB_VERSION' variable is not specific to any thread, and changing it will affect all threads.
The versions of the library differ only in how errors are handled.
In IEEE mode, the `matherr' function is never called, no warning
messages are printed, and `errno' is never set.
In POSIX mode, `errno' is set correctly, but the `matherr' function
is never called and no warning messages are printed.
In X/Open mode, `errno' is set correctly, and `matherr' is called,
but warning message are not printed.
In SVID mode, functions which overflow return
3.40282346638528860e+38, the maximum single-precision floating-point
value, rather than infinity. Also, `errno' is set correctly, `matherr'
is called, and, if `matherr' returns 0, warning messages are printed
for some errors. For example, by default `log(-1.0)' writes this
message on standard error output:
log: DOMAIN error
The library is set to X/Open mode by default.
2 Reentrancy Properties of `libm'
*********************************
When a libm function detects an exceptional case, `errno' may be set, the `matherr' function may be called, and a error message may be written to the standard error stream. This behavior may not be reentrant.
With reentrant C libraries like the Red Hat newlib C library,
`errno' is a macro which expands to the per-thread error value. This
makes it thread safe.
When the user provides his own `matherr' function it must be
reentrant for the math library as a whole to be reentrant.
In normal debugged programs, there are usually no math subroutine
errors--and therefore no assignments to `errno' and no `matherr' calls;
in that situation, the math functions behave reentrantly.
Index
*****