@node Math
@chapter Mathematical Functions (@file{libm/math.h})

This chapter groups a wide variety of mathematical functions.  The
corresponding definitions and declarations are in @file{libm/math.h}.
If you want to use these functions with programs which
@w{@code{#include <math.h>}}, you need to define the symbol
@code{_USE_LIBM_MATH_H} at compile time, e.g. via the compiler option
@samp{-D_USE_LIBM_MATH_H}.

Two definitions from @file{libm/math.h} are of particular interest.

@enumerate
@item
The representation of infinity as a @code{double} is defined as
@code{HUGE_VAL}; this number is returned on overflow by many functions.

@item
The structure @code{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
@code{matherr}; see the section on @code{matherr} for details.
@end enumerate

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---are
available when you include @file{math.h} instead of @file{libm/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
* rint::	Round and  remainder (rint, remainder)
* scalbn::	Scale number
* sin::		Sine or cosine (sin, cos)
* sinh::	Hyperbolic sine
* sqrt::	Positive square root
* tan::		Tangent
* tanh::	Hyperbolic tangent
@end menu

@page
@node version
@section 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 @code{_LIB_VERSION}, defined in
@file{libm/math.h}, to one of the following constants: @code{_IEEE_},
@code{_POSIX_}, @code{_XOPEN_}, or @code{_SVID_}.  (With reentrant C
libraries like the Cygnus C library, the @code{_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 @code{matherr} function is never called, no warning
messages are printed, and @code{errno} is never set.

In POSIX mode, @code{errno} is set correctly, but the @code{matherr}
function is never called and no warning messages are printed.

In X/Open mode, @code{errno} is set correctly, and @code{matherr} is
called, but warning messages are not printed.

In SVID mode, functions which overflow return 3.40282346638528860e+38,
the maximum single precision floating point value, rather than infinity.
Also, @code{errno} is set correctly, @code{matherr} is called, and, if
@code{matherr} returns 0, warning messages are printed for some errors.
For example, by default @samp{log(-1.0)} writes this message on standard
error output:

@example
log: DOMAIN error
@end example

The library is set to X/Open mode by default.

@page
@include w_acos.def

@page
@include w_acosh.def

@page
@include w_asin.def

@page
@include s_asinh.def

@page
@include s_atan.def

@page
@include w_atan2.def

@page
@include w_atanh.def

@page
@include w_j0.def

@page
@include s_cbrt.def

@page
@include s_copysign.def

@page
@include w_cosh.def

@page
@include s_erf.def

@page
@include w_exp.def

@page
@include s_expm1.def

@page
@include s_fabs.def

@page
@include s_floor.def

@page
@include w_fmod.def

@page
@include s_frexp.def

@page
@include w_gamma.def

@page
@include w_hypot.def

@page
@include s_ilogb.def

@page
@include s_infinity.def

@page
@include s_isnan.def

@page
@include s_ldexp.def

@page
@include w_log.def

@page
@include w_log10.def

@page
@include s_log1p.def

@page
@include s_matherr.def

@page
@include s_modf.def

@page
@include s_nan.def

@page
@include s_nextafter.def

@page
@include w_pow.def

@page
@include w_remainder.def

@page
@include s_scalbn.def

@page
@include w_sqrt.def

@page
@include s_sin.def

@page
@include w_sinh.def

@page
@include s_tan.def

@page
@include s_tanh.def
