Blame manual/math.texi

Packit Service 82fcde
@c We need some definitions here.
Packit Service 82fcde
@ifclear mult
Packit Service 82fcde
@ifhtml
Packit Service 82fcde
@set mult ·
Packit Service 82fcde
@set infty ∞
Packit Service 82fcde
@set pie π
Packit Service 82fcde
@end ifhtml
Packit Service 82fcde
@iftex
Packit Service 82fcde
@set mult @cdot
Packit Service 82fcde
@set infty @infty
Packit Service 82fcde
@end iftex
Packit Service 82fcde
@ifclear mult
Packit Service 82fcde
@set mult *
Packit Service 82fcde
@set infty oo
Packit Service 82fcde
@set pie pi
Packit Service 82fcde
@end ifclear
Packit Service 82fcde
@macro mul
Packit Service 82fcde
@value{mult}
Packit Service 82fcde
@end macro
Packit Service 82fcde
@macro infinity
Packit Service 82fcde
@value{infty}
Packit Service 82fcde
@end macro
Packit Service 82fcde
@ifnottex
Packit Service 82fcde
@macro pi
Packit Service 82fcde
@value{pie}
Packit Service 82fcde
@end macro
Packit Service 82fcde
@end ifnottex
Packit Service 82fcde
@end ifclear
Packit Service 82fcde
Packit Service 82fcde
@node Mathematics, Arithmetic, Syslog, Top
Packit Service 82fcde
@c %MENU% Math functions, useful constants, random numbers
Packit Service 82fcde
@chapter Mathematics
Packit Service 82fcde
Packit Service 82fcde
This chapter contains information about functions for performing
Packit Service 82fcde
mathematical computations, such as trigonometric functions.  Most of
Packit Service 82fcde
these functions have prototypes declared in the header file
Packit Service 82fcde
@file{math.h}.  The complex-valued functions are defined in
Packit Service 82fcde
@file{complex.h}.
Packit Service 82fcde
@pindex math.h
Packit Service 82fcde
@pindex complex.h
Packit Service 82fcde
Packit Service 82fcde
All mathematical functions which take a floating-point argument
Packit Service 82fcde
have three variants, one each for @code{double}, @code{float}, and
Packit Service 82fcde
@code{long double} arguments.  The @code{double} versions are mostly
Packit Service 82fcde
defined in @w{ISO C89}.  The @code{float} and @code{long double}
Packit Service 82fcde
versions are from the numeric extensions to C included in @w{ISO C99}.
Packit Service 82fcde
Packit Service 82fcde
Which of the three versions of a function should be used depends on the
Packit Service 82fcde
situation.  For most calculations, the @code{float} functions are the
Packit Service 82fcde
fastest.  On the other hand, the @code{long double} functions have the
Packit Service 82fcde
highest precision.  @code{double} is somewhere in between.  It is
Packit Service 82fcde
usually wise to pick the narrowest type that can accommodate your data.
Packit Service 82fcde
Not all machines have a distinct @code{long double} type; it may be the
Packit Service 82fcde
same as @code{double}.
Packit Service 82fcde
Packit Service 82fcde
@Theglibc{} also provides @code{_Float@var{N}} and
Packit Service 82fcde
@code{_Float@var{N}x} types.  These types are defined in @w{ISO/IEC TS
Packit Service 82fcde
18661-3}, which extends @w{ISO C} and defines floating-point types that
Packit Service 82fcde
are not machine-dependent.  When such a type, such as @code{_Float128},
Packit Service 82fcde
is supported by @theglibc{}, extra variants for most of the mathematical
Packit Service 82fcde
functions provided for @code{double}, @code{float}, and @code{long
Packit Service 82fcde
double} are also provided for the supported type.  Throughout this
Packit Service 82fcde
manual, the @code{_Float@var{N}} and @code{_Float@var{N}x} variants of
Packit Service 82fcde
these functions are described along with the @code{double},
Packit Service 82fcde
@code{float}, and @code{long double} variants and they come from
Packit Service 82fcde
@w{ISO/IEC TS 18661-3}, unless explicitly stated otherwise.
Packit Service 82fcde
Packit Service 82fcde
Support for @code{_Float@var{N}} or @code{_Float@var{N}x} types is
Packit Service 82fcde
provided for @code{_Float32}, @code{_Float64} and @code{_Float32x} on
Packit Service 82fcde
all platforms.
Packit Service 82fcde
It is also provided for @code{_Float128} and @code{_Float64x} on
Packit Service 82fcde
powerpc64le (PowerPC 64-bits little-endian), x86_64, x86, ia64,
Packit Service 82fcde
aarch64, alpha, mips64, riscv, s390 and sparc.
Packit Service 82fcde
Packit Service 82fcde
@menu
Packit Service 82fcde
* Mathematical Constants::      Precise numeric values for often-used
Packit Service 82fcde
                                 constants.
Packit Service 82fcde
* Trig Functions::              Sine, cosine, tangent, and friends.
Packit Service 82fcde
* Inverse Trig Functions::      Arcsine, arccosine, etc.
Packit Service 82fcde
* Exponents and Logarithms::    Also pow and sqrt.
Packit Service 82fcde
* Hyperbolic Functions::        sinh, cosh, tanh, etc.
Packit Service 82fcde
* Special Functions::           Bessel, gamma, erf.
Packit Service 82fcde
* Errors in Math Functions::    Known Maximum Errors in Math Functions.
Packit Service 82fcde
* Pseudo-Random Numbers::       Functions for generating pseudo-random
Packit Service 82fcde
				 numbers.
Packit Service 82fcde
* FP Function Optimizations::   Fast code or small code.
Packit Service 82fcde
@end menu
Packit Service 82fcde
Packit Service 82fcde
@node Mathematical Constants
Packit Service 82fcde
@section Predefined Mathematical Constants
Packit Service 82fcde
@cindex constants
Packit Service 82fcde
@cindex mathematical constants
Packit Service 82fcde
Packit Service 82fcde
The header @file{math.h} defines several useful mathematical constants.
Packit Service 82fcde
All values are defined as preprocessor macros starting with @code{M_}.
Packit Service 82fcde
The values provided are:
Packit Service 82fcde
Packit Service 82fcde
@vtable @code
Packit Service 82fcde
@item M_E
Packit Service 82fcde
The base of natural logarithms.
Packit Service 82fcde
@item M_LOG2E
Packit Service 82fcde
The logarithm to base @code{2} of @code{M_E}.
Packit Service 82fcde
@item M_LOG10E
Packit Service 82fcde
The logarithm to base @code{10} of @code{M_E}.
Packit Service 82fcde
@item M_LN2
Packit Service 82fcde
The natural logarithm of @code{2}.
Packit Service 82fcde
@item M_LN10
Packit Service 82fcde
The natural logarithm of @code{10}.
Packit Service 82fcde
@item M_PI
Packit Service 82fcde
Pi, the ratio of a circle's circumference to its diameter.
Packit Service 82fcde
@item M_PI_2
Packit Service 82fcde
Pi divided by two.
Packit Service 82fcde
@item M_PI_4
Packit Service 82fcde
Pi divided by four.
Packit Service 82fcde
@item M_1_PI
Packit Service 82fcde
The reciprocal of pi (1/pi)
Packit Service 82fcde
@item M_2_PI
Packit Service 82fcde
Two times the reciprocal of pi.
Packit Service 82fcde
@item M_2_SQRTPI
Packit Service 82fcde
Two times the reciprocal of the square root of pi.
Packit Service 82fcde
@item M_SQRT2
Packit Service 82fcde
The square root of two.
Packit Service 82fcde
@item M_SQRT1_2
Packit Service 82fcde
The reciprocal of the square root of two (also the square root of 1/2).
Packit Service 82fcde
@end vtable
Packit Service 82fcde
Packit Service 82fcde
These constants come from the Unix98 standard and were also available in
Packit Service 82fcde
4.4BSD; therefore they are only defined if
Packit Service 82fcde
@code{_XOPEN_SOURCE=500}, or a more general feature select macro, is
Packit Service 82fcde
defined.  The default set of features includes these constants.
Packit Service 82fcde
@xref{Feature Test Macros}.
Packit Service 82fcde
Packit Service 82fcde
All values are of type @code{double}.  As an extension, @theglibc{}
Packit Service 82fcde
also defines these constants with type @code{long double}.  The
Packit Service 82fcde
@code{long double} macros have a lowercase @samp{l} appended to their
Packit Service 82fcde
names: @code{M_El}, @code{M_PIl}, and so forth.  These are only
Packit Service 82fcde
available if @code{_GNU_SOURCE} is defined.
Packit Service 82fcde
Packit Service 82fcde
Likewise, @theglibc{} also defines these constants with the types
Packit Service 82fcde
@code{_Float@var{N}} and @code{_Float@var{N}x} for the machines that
Packit Service 82fcde
have support for such types enabled (@pxref{Mathematics}) and if
Packit Service 82fcde
@code{_GNU_SOURCE} is defined.  When available, the macros names are
Packit Service 82fcde
appended with @samp{f@var{N}} or @samp{f@var{N}x}, such as @samp{f128}
Packit Service 82fcde
for the type @code{_Float128}.
Packit Service 82fcde
Packit Service 82fcde
@vindex PI
Packit Service 82fcde
@emph{Note:} Some programs use a constant named @code{PI} which has the
Packit Service 82fcde
same value as @code{M_PI}.  This constant is not standard; it may have
Packit Service 82fcde
appeared in some old AT&T headers, and is mentioned in Stroustrup's book
Packit Service 82fcde
on C++.  It infringes on the user's name space, so @theglibc{}
Packit Service 82fcde
does not define it.  Fixing programs written to expect it is simple:
Packit Service 82fcde
replace @code{PI} with @code{M_PI} throughout, or put @samp{-DPI=M_PI}
Packit Service 82fcde
on the compiler command line.
Packit Service 82fcde
Packit Service 82fcde
@node Trig Functions
Packit Service 82fcde
@section Trigonometric Functions
Packit Service 82fcde
@cindex trigonometric functions
Packit Service 82fcde
Packit Service 82fcde
These are the familiar @code{sin}, @code{cos}, and @code{tan} functions.
Packit Service 82fcde
The arguments to all of these functions are in units of radians; recall
Packit Service 82fcde
that pi radians equals 180 degrees.
Packit Service 82fcde
Packit Service 82fcde
@cindex pi (trigonometric constant)
Packit Service 82fcde
The math library normally defines @code{M_PI} to a @code{double}
Packit Service 82fcde
approximation of pi.  If strict ISO and/or POSIX compliance
Packit Service 82fcde
are requested this constant is not defined, but you can easily define it
Packit Service 82fcde
yourself:
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
#define M_PI 3.14159265358979323846264338327
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@noindent
Packit Service 82fcde
You can also compute the value of pi with the expression @code{acos
Packit Service 82fcde
(-1.0)}.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double sin (double @var{x})
Packit Service 82fcde
@deftypefunx float sinf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} sinl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN sinfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx sinfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{sinfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{sinfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the sine of @var{x}, where @var{x} is given in
Packit Service 82fcde
radians.  The return value is in the range @code{-1} to @code{1}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double cos (double @var{x})
Packit Service 82fcde
@deftypefunx float cosf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} cosl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN cosfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx cosfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{cosfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{cosfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the cosine of @var{x}, where @var{x} is given in
Packit Service 82fcde
radians.  The return value is in the range @code{-1} to @code{1}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double tan (double @var{x})
Packit Service 82fcde
@deftypefunx float tanf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} tanl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN tanfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx tanfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{tanfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{tanfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the tangent of @var{x}, where @var{x} is given in
Packit Service 82fcde
radians.
Packit Service 82fcde
Packit Service 82fcde
Mathematically, the tangent function has singularities at odd multiples
Packit Service 82fcde
of pi/2.  If the argument @var{x} is too close to one of these
Packit Service 82fcde
singularities, @code{tan} will signal overflow.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
In many applications where @code{sin} and @code{cos} are used, the sine
Packit Service 82fcde
and cosine of the same angle are needed at the same time.  It is more
Packit Service 82fcde
efficient to compute them simultaneously, so the library provides a
Packit Service 82fcde
function to do that.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun void sincos (double @var{x}, double *@var{sinx}, double *@var{cosx})
Packit Service 82fcde
@deftypefunx void sincosf (float @var{x}, float *@var{sinx}, float *@var{cosx})
Packit Service 82fcde
@deftypefunx void sincosl (long double @var{x}, long double *@var{sinx}, long double *@var{cosx})
Packit Service 82fcde
@deftypefunx _FloatN sincosfN (_Float@var{N} @var{x}, _Float@var{N} *@var{sinx}, _Float@var{N} *@var{cosx})
Packit Service 82fcde
@deftypefunx _FloatNx sincosfNx (_Float@var{N}x @var{x}, _Float@var{N}x *@var{sinx}, _Float@var{N}x *@var{cosx})
Packit Service 82fcde
@standards{GNU, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the sine of @var{x} in @code{*@var{sinx}} and the
Packit Service 82fcde
cosine of @var{x} in @code{*@var{cosx}}, where @var{x} is given in
Packit Service 82fcde
radians.  Both values, @code{*@var{sinx}} and @code{*@var{cosx}}, are in
Packit Service 82fcde
the range of @code{-1} to @code{1}.
Packit Service 82fcde
Packit Service 82fcde
All these functions, including the @code{_Float@var{N}} and
Packit Service 82fcde
@code{_Float@var{N}x} variants, are GNU extensions.  Portable programs
Packit Service 82fcde
should be prepared to cope with their absence.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@cindex complex trigonometric functions
Packit Service 82fcde
Packit Service 82fcde
@w{ISO C99} defines variants of the trig functions which work on
Packit Service 82fcde
complex numbers.  @Theglibc{} provides these functions, but they
Packit Service 82fcde
are only useful if your compiler supports the new complex types defined
Packit Service 82fcde
by the standard.
Packit Service 82fcde
@c XXX Change this when gcc is fixed. -zw
Packit Service 82fcde
(As of this writing GCC supports complex numbers, but there are bugs in
Packit Service 82fcde
the implementation.)
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} csin (complex double @var{z})
Packit Service 82fcde
@deftypefunx {complex float} csinf (complex float @var{z})
Packit Service 82fcde
@deftypefunx {complex long double} csinl (complex long double @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatN} csinfN (complex _Float@var{N} @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} csinfNx (complex _Float@var{N}x @var{z})
Packit Service 82fcde
@standards{ISO, complex.h}
Packit Service 82fcde
@standardsx{csinfN, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@standardsx{csinfNx, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@c There are calls to nan* that could trigger @mtslocale if they didn't get
Packit Service 82fcde
@c empty strings.
Packit Service 82fcde
These functions return the complex sine of @var{z}.
Packit Service 82fcde
The mathematical definition of the complex sine is
Packit Service 82fcde
Packit Service 82fcde
@ifnottex
Packit Service 82fcde
@math{sin (z) = 1/(2*i) * (exp (z*i) - exp (-z*i))}.
Packit Service 82fcde
@end ifnottex
Packit Service 82fcde
@tex
Packit Service 82fcde
$$\sin(z) = {1\over 2i} (e^{zi} - e^{-zi})$$
Packit Service 82fcde
@end tex
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} ccos (complex double @var{z})
Packit Service 82fcde
@deftypefunx {complex float} ccosf (complex float @var{z})
Packit Service 82fcde
@deftypefunx {complex long double} ccosl (complex long double @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatN} ccosfN (complex _Float@var{N} @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} ccosfNx (complex _Float@var{N}x @var{z})
Packit Service 82fcde
@standards{ISO, complex.h}
Packit Service 82fcde
@standardsx{ccosfN, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@standardsx{ccosfNx, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the complex cosine of @var{z}.
Packit Service 82fcde
The mathematical definition of the complex cosine is
Packit Service 82fcde
Packit Service 82fcde
@ifnottex
Packit Service 82fcde
@math{cos (z) = 1/2 * (exp (z*i) + exp (-z*i))}
Packit Service 82fcde
@end ifnottex
Packit Service 82fcde
@tex
Packit Service 82fcde
$$\cos(z) = {1\over 2} (e^{zi} + e^{-zi})$$
Packit Service 82fcde
@end tex
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} ctan (complex double @var{z})
Packit Service 82fcde
@deftypefunx {complex float} ctanf (complex float @var{z})
Packit Service 82fcde
@deftypefunx {complex long double} ctanl (complex long double @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatN} ctanfN (complex _Float@var{N} @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} ctanfNx (complex _Float@var{N}x @var{z})
Packit Service 82fcde
@standards{ISO, complex.h}
Packit Service 82fcde
@standardsx{ctanfN, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@standardsx{ctanfNx, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the complex tangent of @var{z}.
Packit Service 82fcde
The mathematical definition of the complex tangent is
Packit Service 82fcde
Packit Service 82fcde
@ifnottex
Packit Service 82fcde
@math{tan (z) = -i * (exp (z*i) - exp (-z*i)) / (exp (z*i) + exp (-z*i))}
Packit Service 82fcde
@end ifnottex
Packit Service 82fcde
@tex
Packit Service 82fcde
$$\tan(z) = -i \cdot {e^{zi} - e^{-zi}\over e^{zi} + e^{-zi}}$$
Packit Service 82fcde
@end tex
Packit Service 82fcde
Packit Service 82fcde
@noindent
Packit Service 82fcde
The complex tangent has poles at @math{pi/2 + 2n}, where @math{n} is an
Packit Service 82fcde
integer.  @code{ctan} may signal overflow if @var{z} is too close to a
Packit Service 82fcde
pole.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@node Inverse Trig Functions
Packit Service 82fcde
@section Inverse Trigonometric Functions
Packit Service 82fcde
@cindex inverse trigonometric functions
Packit Service 82fcde
Packit Service 82fcde
These are the usual arcsine, arccosine and arctangent functions,
Packit Service 82fcde
which are the inverses of the sine, cosine and tangent functions
Packit Service 82fcde
respectively.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double asin (double @var{x})
Packit Service 82fcde
@deftypefunx float asinf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} asinl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN asinfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx asinfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{asinfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{asinfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions compute the arcsine of @var{x}---that is, the value whose
Packit Service 82fcde
sine is @var{x}.  The value is in units of radians.  Mathematically,
Packit Service 82fcde
there are infinitely many such values; the one actually returned is the
Packit Service 82fcde
one between @code{-pi/2} and @code{pi/2} (inclusive).
Packit Service 82fcde
Packit Service 82fcde
The arcsine function is defined mathematically only
Packit Service 82fcde
over the domain @code{-1} to @code{1}.  If @var{x} is outside the
Packit Service 82fcde
domain, @code{asin} signals a domain error.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double acos (double @var{x})
Packit Service 82fcde
@deftypefunx float acosf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} acosl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN acosfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx acosfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{acosfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{acosfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions compute the arccosine of @var{x}---that is, the value
Packit Service 82fcde
whose cosine is @var{x}.  The value is in units of radians.
Packit Service 82fcde
Mathematically, there are infinitely many such values; the one actually
Packit Service 82fcde
returned is the one between @code{0} and @code{pi} (inclusive).
Packit Service 82fcde
Packit Service 82fcde
The arccosine function is defined mathematically only
Packit Service 82fcde
over the domain @code{-1} to @code{1}.  If @var{x} is outside the
Packit Service 82fcde
domain, @code{acos} signals a domain error.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double atan (double @var{x})
Packit Service 82fcde
@deftypefunx float atanf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} atanl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN atanfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx atanfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{atanfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{atanfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions compute the arctangent of @var{x}---that is, the value
Packit Service 82fcde
whose tangent is @var{x}.  The value is in units of radians.
Packit Service 82fcde
Mathematically, there are infinitely many such values; the one actually
Packit Service 82fcde
returned is the one between @code{-pi/2} and @code{pi/2} (inclusive).
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double atan2 (double @var{y}, double @var{x})
Packit Service 82fcde
@deftypefunx float atan2f (float @var{y}, float @var{x})
Packit Service 82fcde
@deftypefunx {long double} atan2l (long double @var{y}, long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN atan2fN (_Float@var{N} @var{y}, _Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx atan2fNx (_Float@var{N}x @var{y}, _Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{atan2fN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{atan2fNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
This function computes the arctangent of @var{y}/@var{x}, but the signs
Packit Service 82fcde
of both arguments are used to determine the quadrant of the result, and
Packit Service 82fcde
@var{x} is permitted to be zero.  The return value is given in radians
Packit Service 82fcde
and is in the range @code{-pi} to @code{pi}, inclusive.
Packit Service 82fcde
Packit Service 82fcde
If @var{x} and @var{y} are coordinates of a point in the plane,
Packit Service 82fcde
@code{atan2} returns the signed angle between the line from the origin
Packit Service 82fcde
to that point and the x-axis.  Thus, @code{atan2} is useful for
Packit Service 82fcde
converting Cartesian coordinates to polar coordinates.  (To compute the
Packit Service 82fcde
radial coordinate, use @code{hypot}; see @ref{Exponents and
Packit Service 82fcde
Logarithms}.)
Packit Service 82fcde
Packit Service 82fcde
@c This is experimentally true.  Should it be so? -zw
Packit Service 82fcde
If both @var{x} and @var{y} are zero, @code{atan2} returns zero.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@cindex inverse complex trigonometric functions
Packit Service 82fcde
@w{ISO C99} defines complex versions of the inverse trig functions.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} casin (complex double @var{z})
Packit Service 82fcde
@deftypefunx {complex float} casinf (complex float @var{z})
Packit Service 82fcde
@deftypefunx {complex long double} casinl (complex long double @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatN} casinfN (complex _Float@var{N} @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} casinfNx (complex _Float@var{N}x @var{z})
Packit Service 82fcde
@standards{ISO, complex.h}
Packit Service 82fcde
@standardsx{casinfN, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@standardsx{casinfNx, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions compute the complex arcsine of @var{z}---that is, the
Packit Service 82fcde
value whose sine is @var{z}.  The value returned is in radians.
Packit Service 82fcde
Packit Service 82fcde
Unlike the real-valued functions, @code{casin} is defined for all
Packit Service 82fcde
values of @var{z}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} cacos (complex double @var{z})
Packit Service 82fcde
@deftypefunx {complex float} cacosf (complex float @var{z})
Packit Service 82fcde
@deftypefunx {complex long double} cacosl (complex long double @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatN} cacosfN (complex _Float@var{N} @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} cacosfNx (complex _Float@var{N}x @var{z})
Packit Service 82fcde
@standards{ISO, complex.h}
Packit Service 82fcde
@standardsx{cacosfN, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@standardsx{cacosfNx, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions compute the complex arccosine of @var{z}---that is, the
Packit Service 82fcde
value whose cosine is @var{z}.  The value returned is in radians.
Packit Service 82fcde
Packit Service 82fcde
Unlike the real-valued functions, @code{cacos} is defined for all
Packit Service 82fcde
values of @var{z}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} catan (complex double @var{z})
Packit Service 82fcde
@deftypefunx {complex float} catanf (complex float @var{z})
Packit Service 82fcde
@deftypefunx {complex long double} catanl (complex long double @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatN} catanfN (complex _Float@var{N} @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} catanfNx (complex _Float@var{N}x @var{z})
Packit Service 82fcde
@standards{ISO, complex.h}
Packit Service 82fcde
@standardsx{catanfN, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@standardsx{catanfNx, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions compute the complex arctangent of @var{z}---that is,
Packit Service 82fcde
the value whose tangent is @var{z}.  The value is in units of radians.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@node Exponents and Logarithms
Packit Service 82fcde
@section Exponentiation and Logarithms
Packit Service 82fcde
@cindex exponentiation functions
Packit Service 82fcde
@cindex power functions
Packit Service 82fcde
@cindex logarithm functions
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double exp (double @var{x})
Packit Service 82fcde
@deftypefunx float expf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} expl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN expfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx expfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{expfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{expfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions compute @code{e} (the base of natural logarithms) raised
Packit Service 82fcde
to the power @var{x}.
Packit Service 82fcde
Packit Service 82fcde
If the magnitude of the result is too large to be representable,
Packit Service 82fcde
@code{exp} signals overflow.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double exp2 (double @var{x})
Packit Service 82fcde
@deftypefunx float exp2f (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} exp2l (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN exp2fN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx exp2fNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{exp2fN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{exp2fNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions compute @code{2} raised to the power @var{x}.
Packit Service 82fcde
Mathematically, @code{exp2 (x)} is the same as @code{exp (x * log (2))}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double exp10 (double @var{x})
Packit Service 82fcde
@deftypefunx float exp10f (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} exp10l (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN exp10fN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx exp10fNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{exp10fN, TS 18661-4:2015, math.h}
Packit Service 82fcde
@standardsx{exp10fNx, TS 18661-4:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions compute @code{10} raised to the power @var{x}.
Packit Service 82fcde
Mathematically, @code{exp10 (x)} is the same as @code{exp (x * log (10))}.
Packit Service 82fcde
Packit Service 82fcde
The @code{exp10} functions are from TS 18661-4:2015.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double log (double @var{x})
Packit Service 82fcde
@deftypefunx float logf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} logl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN logfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx logfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{logfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{logfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions compute the natural logarithm of @var{x}.  @code{exp (log
Packit Service 82fcde
(@var{x}))} equals @var{x}, exactly in mathematics and approximately in
Packit Service 82fcde
C.
Packit Service 82fcde
Packit Service 82fcde
If @var{x} is negative, @code{log} signals a domain error.  If @var{x}
Packit Service 82fcde
is zero, it returns negative infinity; if @var{x} is too close to zero,
Packit Service 82fcde
it may signal overflow.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double log10 (double @var{x})
Packit Service 82fcde
@deftypefunx float log10f (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} log10l (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN log10fN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx log10fNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{log10fN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{log10fNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the base-10 logarithm of @var{x}.
Packit Service 82fcde
@code{log10 (@var{x})} equals @code{log (@var{x}) / log (10)}.
Packit Service 82fcde
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double log2 (double @var{x})
Packit Service 82fcde
@deftypefunx float log2f (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} log2l (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN log2fN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx log2fNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{log2fN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{log2fNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the base-2 logarithm of @var{x}.
Packit Service 82fcde
@code{log2 (@var{x})} equals @code{log (@var{x}) / log (2)}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double logb (double @var{x})
Packit Service 82fcde
@deftypefunx float logbf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} logbl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN logbfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx logbfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{logbfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{logbfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions extract the exponent of @var{x} and return it as a
Packit Service 82fcde
floating-point value.  If @code{FLT_RADIX} is two, @code{logb} is equal
Packit Service 82fcde
to @code{floor (log2 (x))}, except it's probably faster.
Packit Service 82fcde
Packit Service 82fcde
If @var{x} is de-normalized, @code{logb} returns the exponent @var{x}
Packit Service 82fcde
would have if it were normalized.  If @var{x} is infinity (positive or
Packit Service 82fcde
negative), @code{logb} returns @math{@infinity{}}.  If @var{x} is zero,
Packit Service 82fcde
@code{logb} returns @math{@infinity{}}.  It does not signal.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int ilogb (double @var{x})
Packit Service 82fcde
@deftypefunx int ilogbf (float @var{x})
Packit Service 82fcde
@deftypefunx int ilogbl (long double @var{x})
Packit Service 82fcde
@deftypefunx int ilogbfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx int ilogbfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@deftypefunx {long int} llogb (double @var{x})
Packit Service 82fcde
@deftypefunx {long int} llogbf (float @var{x})
Packit Service 82fcde
@deftypefunx {long int} llogbl (long double @var{x})
Packit Service 82fcde
@deftypefunx {long int} llogbfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx {long int} llogbfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{ilogbfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{ilogbfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{llogbfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{llogbfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions are equivalent to the corresponding @code{logb}
Packit Service 82fcde
functions except that they return signed integer values.  The
Packit Service 82fcde
@code{ilogb}, @code{ilogbf}, and @code{ilogbl} functions are from ISO
Packit Service 82fcde
C99; the @code{llogb}, @code{llogbf}, @code{llogbl} functions are from
Packit Service 82fcde
TS 18661-1:2014; the @code{ilogbfN}, @code{ilogbfNx}, @code{llogbfN},
Packit Service 82fcde
and @code{llogbfNx} functions are from TS 18661-3:2015.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@noindent
Packit Service 82fcde
Since integers cannot represent infinity and NaN, @code{ilogb} instead
Packit Service 82fcde
returns an integer that can't be the exponent of a normal floating-point
Packit Service 82fcde
number.  @file{math.h} defines constants so you can check for this.
Packit Service 82fcde
Packit Service 82fcde
@deftypevr Macro int FP_ILOGB0
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@code{ilogb} returns this value if its argument is @code{0}.  The
Packit Service 82fcde
numeric value is either @code{INT_MIN} or @code{-INT_MAX}.
Packit Service 82fcde
Packit Service 82fcde
This macro is defined in @w{ISO C99}.
Packit Service 82fcde
@end deftypevr
Packit Service 82fcde
Packit Service 82fcde
@deftypevr Macro {long int} FP_LLOGB0
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@code{llogb} returns this value if its argument is @code{0}.  The
Packit Service 82fcde
numeric value is either @code{LONG_MIN} or @code{-LONG_MAX}.
Packit Service 82fcde
Packit Service 82fcde
This macro is defined in TS 18661-1:2014.
Packit Service 82fcde
@end deftypevr
Packit Service 82fcde
Packit Service 82fcde
@deftypevr Macro int FP_ILOGBNAN
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@code{ilogb} returns this value if its argument is @code{NaN}.  The
Packit Service 82fcde
numeric value is either @code{INT_MIN} or @code{INT_MAX}.
Packit Service 82fcde
Packit Service 82fcde
This macro is defined in @w{ISO C99}.
Packit Service 82fcde
@end deftypevr
Packit Service 82fcde
Packit Service 82fcde
@deftypevr Macro {long int} FP_LLOGBNAN
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@code{llogb} returns this value if its argument is @code{NaN}.  The
Packit Service 82fcde
numeric value is either @code{LONG_MIN} or @code{LONG_MAX}.
Packit Service 82fcde
Packit Service 82fcde
This macro is defined in TS 18661-1:2014.
Packit Service 82fcde
@end deftypevr
Packit Service 82fcde
Packit Service 82fcde
These values are system specific.  They might even be the same.  The
Packit Service 82fcde
proper way to test the result of @code{ilogb} is as follows:
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
i = ilogb (f);
Packit Service 82fcde
if (i == FP_ILOGB0 || i == FP_ILOGBNAN)
Packit Service 82fcde
  @{
Packit Service 82fcde
    if (isnan (f))
Packit Service 82fcde
      @{
Packit Service 82fcde
        /* @r{Handle NaN.}  */
Packit Service 82fcde
      @}
Packit Service 82fcde
    else if (f  == 0.0)
Packit Service 82fcde
      @{
Packit Service 82fcde
        /* @r{Handle 0.0.}  */
Packit Service 82fcde
      @}
Packit Service 82fcde
    else
Packit Service 82fcde
      @{
Packit Service 82fcde
        /* @r{Some other value with large exponent,}
Packit Service 82fcde
           @r{perhaps +Inf.}  */
Packit Service 82fcde
      @}
Packit Service 82fcde
  @}
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double pow (double @var{base}, double @var{power})
Packit Service 82fcde
@deftypefunx float powf (float @var{base}, float @var{power})
Packit Service 82fcde
@deftypefunx {long double} powl (long double @var{base}, long double @var{power})
Packit Service 82fcde
@deftypefunx _FloatN powfN (_Float@var{N} @var{base}, _Float@var{N} @var{power})
Packit Service 82fcde
@deftypefunx _FloatNx powfNx (_Float@var{N}x @var{base}, _Float@var{N}x @var{power})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{powfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{powfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These are general exponentiation functions, returning @var{base} raised
Packit Service 82fcde
to @var{power}.
Packit Service 82fcde
Packit Service 82fcde
Mathematically, @code{pow} would return a complex number when @var{base}
Packit Service 82fcde
is negative and @var{power} is not an integral value.  @code{pow} can't
Packit Service 82fcde
do that, so instead it signals a domain error. @code{pow} may also
Packit Service 82fcde
underflow or overflow the destination type.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@cindex square root function
Packit Service 82fcde
@deftypefun double sqrt (double @var{x})
Packit Service 82fcde
@deftypefunx float sqrtf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} sqrtl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN sqrtfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx sqrtfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{sqrtfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{sqrtfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the nonnegative square root of @var{x}.
Packit Service 82fcde
Packit Service 82fcde
If @var{x} is negative, @code{sqrt} signals a domain error.
Packit Service 82fcde
Mathematically, it should return a complex number.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@cindex cube root function
Packit Service 82fcde
@deftypefun double cbrt (double @var{x})
Packit Service 82fcde
@deftypefunx float cbrtf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} cbrtl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN cbrtfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx cbrtfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{BSD, math.h}
Packit Service 82fcde
@standardsx{cbrtfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{cbrtfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the cube root of @var{x}.  They cannot
Packit Service 82fcde
fail; every representable real value has a representable real cube root.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double hypot (double @var{x}, double @var{y})
Packit Service 82fcde
@deftypefunx float hypotf (float @var{x}, float @var{y})
Packit Service 82fcde
@deftypefunx {long double} hypotl (long double @var{x}, long double @var{y})
Packit Service 82fcde
@deftypefunx _FloatN hypotfN (_Float@var{N} @var{x}, _Float@var{N} @var{y})
Packit Service 82fcde
@deftypefunx _FloatNx hypotfNx (_Float@var{N}x @var{x}, _Float@var{N}x @var{y})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{hypotfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{hypotfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return @code{sqrt (@var{x}*@var{x} +
Packit Service 82fcde
@var{y}*@var{y})}.  This is the length of the hypotenuse of a right
Packit Service 82fcde
triangle with sides of length @var{x} and @var{y}, or the distance
Packit Service 82fcde
of the point (@var{x}, @var{y}) from the origin.  Using this function
Packit Service 82fcde
instead of the direct formula is wise, since the error is
Packit Service 82fcde
much smaller.  See also the function @code{cabs} in @ref{Absolute Value}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double expm1 (double @var{x})
Packit Service 82fcde
@deftypefunx float expm1f (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} expm1l (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN expm1fN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx expm1fNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{expm1fN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{expm1fNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return a value equivalent to @code{exp (@var{x}) - 1}.
Packit Service 82fcde
They are computed in a way that is accurate even if @var{x} is
Packit Service 82fcde
near zero---a case where @code{exp (@var{x}) - 1} would be inaccurate owing
Packit Service 82fcde
to subtraction of two numbers that are nearly equal.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double log1p (double @var{x})
Packit Service 82fcde
@deftypefunx float log1pf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} log1pl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN log1pfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx log1pfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{log1pfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{log1pfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return a value equivalent to @w{@code{log (1 + @var{x})}}.
Packit Service 82fcde
They are computed in a way that is accurate even if @var{x} is
Packit Service 82fcde
near zero.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@cindex complex exponentiation functions
Packit Service 82fcde
@cindex complex logarithm functions
Packit Service 82fcde
Packit Service 82fcde
@w{ISO C99} defines complex variants of some of the exponentiation and
Packit Service 82fcde
logarithm functions.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} cexp (complex double @var{z})
Packit Service 82fcde
@deftypefunx {complex float} cexpf (complex float @var{z})
Packit Service 82fcde
@deftypefunx {complex long double} cexpl (complex long double @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatN} cexpfN (complex _Float@var{N} @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} cexpfNx (complex _Float@var{N}x @var{z})
Packit Service 82fcde
@standards{ISO, complex.h}
Packit Service 82fcde
@standardsx{cexpfN, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@standardsx{cexpfNx, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return @code{e} (the base of natural
Packit Service 82fcde
logarithms) raised to the power of @var{z}.
Packit Service 82fcde
Mathematically, this corresponds to the value
Packit Service 82fcde
Packit Service 82fcde
@ifnottex
Packit Service 82fcde
@math{exp (z) = exp (creal (z)) * (cos (cimag (z)) + I * sin (cimag (z)))}
Packit Service 82fcde
@end ifnottex
Packit Service 82fcde
@tex
Packit Service 82fcde
$$\exp(z) = e^z = e^{{\rm Re}\,z} (\cos ({\rm Im}\,z) + i \sin ({\rm Im}\,z))$$
Packit Service 82fcde
@end tex
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} clog (complex double @var{z})
Packit Service 82fcde
@deftypefunx {complex float} clogf (complex float @var{z})
Packit Service 82fcde
@deftypefunx {complex long double} clogl (complex long double @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatN} clogfN (complex _Float@var{N} @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} clogfNx (complex _Float@var{N}x @var{z})
Packit Service 82fcde
@standards{ISO, complex.h}
Packit Service 82fcde
@standardsx{clogfN, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@standardsx{clogfNx, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the natural logarithm of @var{z}.
Packit Service 82fcde
Mathematically, this corresponds to the value
Packit Service 82fcde
Packit Service 82fcde
@ifnottex
Packit Service 82fcde
@math{log (z) = log (cabs (z)) + I * carg (z)}
Packit Service 82fcde
@end ifnottex
Packit Service 82fcde
@tex
Packit Service 82fcde
$$\log(z) = \log |z| + i \arg z$$
Packit Service 82fcde
@end tex
Packit Service 82fcde
Packit Service 82fcde
@noindent
Packit Service 82fcde
@code{clog} has a pole at 0, and will signal overflow if @var{z} equals
Packit Service 82fcde
or is very close to 0.  It is well-defined for all other values of
Packit Service 82fcde
@var{z}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} clog10 (complex double @var{z})
Packit Service 82fcde
@deftypefunx {complex float} clog10f (complex float @var{z})
Packit Service 82fcde
@deftypefunx {complex long double} clog10l (complex long double @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatN} clog10fN (complex _Float@var{N} @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} clog10fNx (complex _Float@var{N}x @var{z})
Packit Service 82fcde
@standards{GNU, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the base 10 logarithm of the complex value
Packit Service 82fcde
@var{z}.  Mathematically, this corresponds to the value
Packit Service 82fcde
Packit Service 82fcde
@ifnottex
Packit Service 82fcde
@math{log10 (z) = log10 (cabs (z)) + I * carg (z) / log (10)}
Packit Service 82fcde
@end ifnottex
Packit Service 82fcde
@tex
Packit Service 82fcde
$$\log_{10}(z) = \log_{10}|z| + i \arg z / \log (10)$$
Packit Service 82fcde
@end tex
Packit Service 82fcde
Packit Service 82fcde
All these functions, including the @code{_Float@var{N}} and
Packit Service 82fcde
@code{_Float@var{N}x} variants, are GNU extensions.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} csqrt (complex double @var{z})
Packit Service 82fcde
@deftypefunx {complex float} csqrtf (complex float @var{z})
Packit Service 82fcde
@deftypefunx {complex long double} csqrtl (complex long double @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatN} csqrtfN (_Float@var{N} @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} csqrtfNx (complex _Float@var{N}x @var{z})
Packit Service 82fcde
@standards{ISO, complex.h}
Packit Service 82fcde
@standardsx{csqrtfN, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@standardsx{csqrtfNx, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the complex square root of the argument @var{z}.  Unlike
Packit Service 82fcde
the real-valued functions, they are defined for all values of @var{z}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} cpow (complex double @var{base}, complex double @var{power})
Packit Service 82fcde
@deftypefunx {complex float} cpowf (complex float @var{base}, complex float @var{power})
Packit Service 82fcde
@deftypefunx {complex long double} cpowl (complex long double @var{base}, complex long double @var{power})
Packit Service 82fcde
@deftypefunx {complex _FloatN} cpowfN (complex _Float@var{N} @var{base}, complex _Float@var{N} @var{power})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} cpowfNx (complex _Float@var{N}x @var{base}, complex _Float@var{N}x @var{power})
Packit Service 82fcde
@standards{ISO, complex.h}
Packit Service 82fcde
@standardsx{cpowfN, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@standardsx{cpowfNx, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return @var{base} raised to the power of
Packit Service 82fcde
@var{power}.  This is equivalent to @w{@code{cexp (y * clog (x))}}
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@node Hyperbolic Functions
Packit Service 82fcde
@section Hyperbolic Functions
Packit Service 82fcde
@cindex hyperbolic functions
Packit Service 82fcde
Packit Service 82fcde
The functions in this section are related to the exponential functions;
Packit Service 82fcde
see @ref{Exponents and Logarithms}.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double sinh (double @var{x})
Packit Service 82fcde
@deftypefunx float sinhf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} sinhl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN sinhfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx sinhfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{sinhfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{sinhfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the hyperbolic sine of @var{x}, defined
Packit Service 82fcde
mathematically as @w{@code{(exp (@var{x}) - exp (-@var{x})) / 2}}.  They
Packit Service 82fcde
may signal overflow if @var{x} is too large.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double cosh (double @var{x})
Packit Service 82fcde
@deftypefunx float coshf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} coshl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN coshfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx coshfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{coshfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{coshfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the hyperbolic cosine of @var{x},
Packit Service 82fcde
defined mathematically as @w{@code{(exp (@var{x}) + exp (-@var{x})) / 2}}.
Packit Service 82fcde
They may signal overflow if @var{x} is too large.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double tanh (double @var{x})
Packit Service 82fcde
@deftypefunx float tanhf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} tanhl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN tanhfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx tanhfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{tanhfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{tanhfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the hyperbolic tangent of @var{x},
Packit Service 82fcde
defined mathematically as @w{@code{sinh (@var{x}) / cosh (@var{x})}}.
Packit Service 82fcde
They may signal overflow if @var{x} is too large.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@cindex hyperbolic functions
Packit Service 82fcde
Packit Service 82fcde
There are counterparts for the hyperbolic functions which take
Packit Service 82fcde
complex arguments.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} csinh (complex double @var{z})
Packit Service 82fcde
@deftypefunx {complex float} csinhf (complex float @var{z})
Packit Service 82fcde
@deftypefunx {complex long double} csinhl (complex long double @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatN} csinhfN (complex _Float@var{N} @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} csinhfNx (complex _Float@var{N}x @var{z})
Packit Service 82fcde
@standards{ISO, complex.h}
Packit Service 82fcde
@standardsx{csinhfN, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@standardsx{csinhfNx, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the complex hyperbolic sine of @var{z}, defined
Packit Service 82fcde
mathematically as @w{@code{(exp (@var{z}) - exp (-@var{z})) / 2}}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} ccosh (complex double @var{z})
Packit Service 82fcde
@deftypefunx {complex float} ccoshf (complex float @var{z})
Packit Service 82fcde
@deftypefunx {complex long double} ccoshl (complex long double @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatN} ccoshfN (complex _Float@var{N} @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} ccoshfNx (complex _Float@var{N}x @var{z})
Packit Service 82fcde
@standards{ISO, complex.h}
Packit Service 82fcde
@standardsx{ccoshfN, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@standardsx{ccoshfNx, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the complex hyperbolic cosine of @var{z}, defined
Packit Service 82fcde
mathematically as @w{@code{(exp (@var{z}) + exp (-@var{z})) / 2}}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} ctanh (complex double @var{z})
Packit Service 82fcde
@deftypefunx {complex float} ctanhf (complex float @var{z})
Packit Service 82fcde
@deftypefunx {complex long double} ctanhl (complex long double @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatN} ctanhfN (complex _Float@var{N} @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} ctanhfNx (complex _Float@var{N}x @var{z})
Packit Service 82fcde
@standards{ISO, complex.h}
Packit Service 82fcde
@standardsx{ctanhfN, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@standardsx{ctanhfNx, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the complex hyperbolic tangent of @var{z},
Packit Service 82fcde
defined mathematically as @w{@code{csinh (@var{z}) / ccosh (@var{z})}}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@cindex inverse hyperbolic functions
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double asinh (double @var{x})
Packit Service 82fcde
@deftypefunx float asinhf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} asinhl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN asinhfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx asinhfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{asinhfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{asinhfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the inverse hyperbolic sine of @var{x}---the
Packit Service 82fcde
value whose hyperbolic sine is @var{x}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double acosh (double @var{x})
Packit Service 82fcde
@deftypefunx float acoshf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} acoshl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN acoshfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx acoshfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{acoshfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{acoshfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the inverse hyperbolic cosine of @var{x}---the
Packit Service 82fcde
value whose hyperbolic cosine is @var{x}.  If @var{x} is less than
Packit Service 82fcde
@code{1}, @code{acosh} signals a domain error.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double atanh (double @var{x})
Packit Service 82fcde
@deftypefunx float atanhf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} atanhl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN atanhfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx atanhfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{ISO, math.h}
Packit Service 82fcde
@standardsx{atanhfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{atanhfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the inverse hyperbolic tangent of @var{x}---the
Packit Service 82fcde
value whose hyperbolic tangent is @var{x}.  If the absolute value of
Packit Service 82fcde
@var{x} is greater than @code{1}, @code{atanh} signals a domain error;
Packit Service 82fcde
if it is equal to 1, @code{atanh} returns infinity.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@cindex inverse complex hyperbolic functions
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} casinh (complex double @var{z})
Packit Service 82fcde
@deftypefunx {complex float} casinhf (complex float @var{z})
Packit Service 82fcde
@deftypefunx {complex long double} casinhl (complex long double @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatN} casinhfN (complex _Float@var{N} @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} casinhfNx (complex _Float@var{N}x @var{z})
Packit Service 82fcde
@standards{ISO, complex.h}
Packit Service 82fcde
@standardsx{casinhfN, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@standardsx{casinhfNx, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the inverse complex hyperbolic sine of
Packit Service 82fcde
@var{z}---the value whose complex hyperbolic sine is @var{z}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} cacosh (complex double @var{z})
Packit Service 82fcde
@deftypefunx {complex float} cacoshf (complex float @var{z})
Packit Service 82fcde
@deftypefunx {complex long double} cacoshl (complex long double @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatN} cacoshfN (complex _Float@var{N} @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} cacoshfNx (complex _Float@var{N}x @var{z})
Packit Service 82fcde
@standards{ISO, complex.h}
Packit Service 82fcde
@standardsx{cacoshfN, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@standardsx{cacoshfNx, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the inverse complex hyperbolic cosine of
Packit Service 82fcde
@var{z}---the value whose complex hyperbolic cosine is @var{z}.  Unlike
Packit Service 82fcde
the real-valued functions, there are no restrictions on the value of @var{z}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {complex double} catanh (complex double @var{z})
Packit Service 82fcde
@deftypefunx {complex float} catanhf (complex float @var{z})
Packit Service 82fcde
@deftypefunx {complex long double} catanhl (complex long double @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatN} catanhfN (complex _Float@var{N} @var{z})
Packit Service 82fcde
@deftypefunx {complex _FloatNx} catanhfNx (complex _Float@var{N}x @var{z})
Packit Service 82fcde
@standards{ISO, complex.h}
Packit Service 82fcde
@standardsx{catanhfN, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@standardsx{catanhfNx, TS 18661-3:2015, complex.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
These functions return the inverse complex hyperbolic tangent of
Packit Service 82fcde
@var{z}---the value whose complex hyperbolic tangent is @var{z}.  Unlike
Packit Service 82fcde
the real-valued functions, there are no restrictions on the value of
Packit Service 82fcde
@var{z}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@node Special Functions
Packit Service 82fcde
@section Special Functions
Packit Service 82fcde
@cindex special functions
Packit Service 82fcde
@cindex Bessel functions
Packit Service 82fcde
@cindex gamma function
Packit Service 82fcde
Packit Service 82fcde
These are some more exotic mathematical functions which are sometimes
Packit Service 82fcde
useful.  Currently they only have real-valued versions.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double erf (double @var{x})
Packit Service 82fcde
@deftypefunx float erff (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} erfl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN erffN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx erffNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{SVID, math.h}
Packit Service 82fcde
@standardsx{erffN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{erffNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@code{erf} returns the error function of @var{x}.  The error
Packit Service 82fcde
function is defined as
Packit Service 82fcde
@tex
Packit Service 82fcde
$$\hbox{erf}(x) = {2\over\sqrt{\pi}}\cdot\int_0^x e^{-t^2} \hbox{d}t$$
Packit Service 82fcde
@end tex
Packit Service 82fcde
@ifnottex
Packit Service 82fcde
@smallexample
Packit Service 82fcde
erf (x) = 2/sqrt(pi) * integral from 0 to x of exp(-t^2) dt
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
@end ifnottex
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double erfc (double @var{x})
Packit Service 82fcde
@deftypefunx float erfcf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} erfcl (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN erfcfN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx erfcfNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{SVID, math.h}
Packit Service 82fcde
@standardsx{erfcfN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{erfcfNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@code{erfc} returns @code{1.0 - erf(@var{x})}, but computed in a
Packit Service 82fcde
fashion that avoids round-off error when @var{x} is large.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double lgamma (double @var{x})
Packit Service 82fcde
@deftypefunx float lgammaf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} lgammal (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN lgammafN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx lgammafNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{SVID, math.h}
Packit Service 82fcde
@standardsx{lgammafN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{lgammafNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:signgam}}@asunsafe{}@acsafe{}}
Packit Service 82fcde
@code{lgamma} returns the natural logarithm of the absolute value of
Packit Service 82fcde
the gamma function of @var{x}.  The gamma function is defined as
Packit Service 82fcde
@tex
Packit Service 82fcde
$$\Gamma(x) = \int_0^\infty t^{x-1} e^{-t} \hbox{d}t$$
Packit Service 82fcde
@end tex
Packit Service 82fcde
@ifnottex
Packit Service 82fcde
@smallexample
Packit Service 82fcde
gamma (x) = integral from 0 to @infinity{} of t^(x-1) e^-t dt
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
@end ifnottex
Packit Service 82fcde
Packit Service 82fcde
@vindex signgam
Packit Service 82fcde
The sign of the gamma function is stored in the global variable
Packit Service 82fcde
@var{signgam}, which is declared in @file{math.h}.  It is @code{1} if
Packit Service 82fcde
the intermediate result was positive or zero, or @code{-1} if it was
Packit Service 82fcde
negative.
Packit Service 82fcde
Packit Service 82fcde
To compute the real gamma function you can use the @code{tgamma}
Packit Service 82fcde
function or you can compute the values as follows:
Packit Service 82fcde
@smallexample
Packit Service 82fcde
lgam = lgamma(x);
Packit Service 82fcde
gam  = signgam*exp(lgam);
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
The gamma function has singularities at the non-positive integers.
Packit Service 82fcde
@code{lgamma} will raise the zero divide exception if evaluated at a
Packit Service 82fcde
singularity.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double lgamma_r (double @var{x}, int *@var{signp})
Packit Service 82fcde
@deftypefunx float lgammaf_r (float @var{x}, int *@var{signp})
Packit Service 82fcde
@deftypefunx {long double} lgammal_r (long double @var{x}, int *@var{signp})
Packit Service 82fcde
@deftypefunx _FloatN lgammafN_r (_Float@var{N} @var{x}, int *@var{signp})
Packit Service 82fcde
@deftypefunx _FloatNx lgammafNx_r (_Float@var{N}x @var{x}, int *@var{signp})
Packit Service 82fcde
@standards{XPG, math.h}
Packit Service 82fcde
@standardsx{lgammafN_r, GNU, math.h}
Packit Service 82fcde
@standardsx{lgammafNx_r, GNU, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@code{lgamma_r} is just like @code{lgamma}, but it stores the sign of
Packit Service 82fcde
the intermediate result in the variable pointed to by @var{signp}
Packit Service 82fcde
instead of in the @var{signgam} global.  This means it is reentrant.
Packit Service 82fcde
Packit Service 82fcde
The @code{lgammaf@var{N}_r} and @code{lgammaf@var{N}x_r} functions are
Packit Service 82fcde
GNU extensions.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double gamma (double @var{x})
Packit Service 82fcde
@deftypefunx float gammaf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} gammal (long double @var{x})
Packit Service 82fcde
@standards{SVID, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:signgam}}@asunsafe{}@acsafe{}}
Packit Service 82fcde
These functions exist for compatibility reasons.  They are equivalent to
Packit Service 82fcde
@code{lgamma} etc.  It is better to use @code{lgamma} since for one the
Packit Service 82fcde
name reflects better the actual computation, and moreover @code{lgamma} is
Packit Service 82fcde
standardized in @w{ISO C99} while @code{gamma} is not.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double tgamma (double @var{x})
Packit Service 82fcde
@deftypefunx float tgammaf (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} tgammal (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN tgammafN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx tgammafNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standardsx{tgamma, XPG, math.h}
Packit Service 82fcde
@standardsx{tgamma, ISO, math.h}
Packit Service 82fcde
@standardsx{tgammaf, XPG, math.h}
Packit Service 82fcde
@standardsx{tgammaf, ISO, math.h}
Packit Service 82fcde
@standardsx{tgammal, XPG, math.h}
Packit Service 82fcde
@standardsx{tgammal, ISO, math.h}
Packit Service 82fcde
@standardsx{tgammafN, TS 18661-3:2015, math.h}
Packit Service 82fcde
@standardsx{tgammafNx, TS 18661-3:2015, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@code{tgamma} applies the gamma function to @var{x}.  The gamma
Packit Service 82fcde
function is defined as
Packit Service 82fcde
@tex
Packit Service 82fcde
$$\Gamma(x) = \int_0^\infty t^{x-1} e^{-t} \hbox{d}t$$
Packit Service 82fcde
@end tex
Packit Service 82fcde
@ifnottex
Packit Service 82fcde
@smallexample
Packit Service 82fcde
gamma (x) = integral from 0 to @infinity{} of t^(x-1) e^-t dt
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
@end ifnottex
Packit Service 82fcde
Packit Service 82fcde
This function was introduced in @w{ISO C99}.  The @code{_Float@var{N}}
Packit Service 82fcde
and @code{_Float@var{N}x} variants were introduced in @w{ISO/IEC TS
Packit Service 82fcde
18661-3}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double j0 (double @var{x})
Packit Service 82fcde
@deftypefunx float j0f (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} j0l (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN j0fN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx j0fNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{SVID, math.h}
Packit Service 82fcde
@standardsx{j0fN, GNU, math.h}
Packit Service 82fcde
@standardsx{j0fNx, GNU, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@code{j0} returns the Bessel function of the first kind of order 0 of
Packit Service 82fcde
@var{x}.  It may signal underflow if @var{x} is too large.
Packit Service 82fcde
Packit Service 82fcde
The @code{_Float@var{N}} and @code{_Float@var{N}x} variants are GNU
Packit Service 82fcde
extensions.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double j1 (double @var{x})
Packit Service 82fcde
@deftypefunx float j1f (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} j1l (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN j1fN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx j1fNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{SVID, math.h}
Packit Service 82fcde
@standardsx{j1fN, GNU, math.h}
Packit Service 82fcde
@standardsx{j1fNx, GNU, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@code{j1} returns the Bessel function of the first kind of order 1 of
Packit Service 82fcde
@var{x}.  It may signal underflow if @var{x} is too large.
Packit Service 82fcde
Packit Service 82fcde
The @code{_Float@var{N}} and @code{_Float@var{N}x} variants are GNU
Packit Service 82fcde
extensions.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double jn (int @var{n}, double @var{x})
Packit Service 82fcde
@deftypefunx float jnf (int @var{n}, float @var{x})
Packit Service 82fcde
@deftypefunx {long double} jnl (int @var{n}, long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN jnfN (int @var{n}, _Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx jnfNx (int @var{n}, _Float@var{N}x @var{x})
Packit Service 82fcde
@standards{SVID, math.h}
Packit Service 82fcde
@standardsx{jnfN, GNU, math.h}
Packit Service 82fcde
@standardsx{jnfNx, GNU, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@code{jn} returns the Bessel function of the first kind of order
Packit Service 82fcde
@var{n} of @var{x}.  It may signal underflow if @var{x} is too large.
Packit Service 82fcde
Packit Service 82fcde
The @code{_Float@var{N}} and @code{_Float@var{N}x} variants are GNU
Packit Service 82fcde
extensions.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double y0 (double @var{x})
Packit Service 82fcde
@deftypefunx float y0f (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} y0l (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN y0fN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx y0fNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{SVID, math.h}
Packit Service 82fcde
@standardsx{y0fN, GNU, math.h}
Packit Service 82fcde
@standardsx{y0fNx, GNU, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@code{y0} returns the Bessel function of the second kind of order 0 of
Packit Service 82fcde
@var{x}.  It may signal underflow if @var{x} is too large.  If @var{x}
Packit Service 82fcde
is negative, @code{y0} signals a domain error; if it is zero,
Packit Service 82fcde
@code{y0} signals overflow and returns @math{-@infinity}.
Packit Service 82fcde
Packit Service 82fcde
The @code{_Float@var{N}} and @code{_Float@var{N}x} variants are GNU
Packit Service 82fcde
extensions.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double y1 (double @var{x})
Packit Service 82fcde
@deftypefunx float y1f (float @var{x})
Packit Service 82fcde
@deftypefunx {long double} y1l (long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN y1fN (_Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx y1fNx (_Float@var{N}x @var{x})
Packit Service 82fcde
@standards{SVID, math.h}
Packit Service 82fcde
@standardsx{y1fN, GNU, math.h}
Packit Service 82fcde
@standardsx{y1fNx, GNU, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@code{y1} returns the Bessel function of the second kind of order 1 of
Packit Service 82fcde
@var{x}.  It may signal underflow if @var{x} is too large.  If @var{x}
Packit Service 82fcde
is negative, @code{y1} signals a domain error; if it is zero,
Packit Service 82fcde
@code{y1} signals overflow and returns @math{-@infinity}.
Packit Service 82fcde
Packit Service 82fcde
The @code{_Float@var{N}} and @code{_Float@var{N}x} variants are GNU
Packit Service 82fcde
extensions.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double yn (int @var{n}, double @var{x})
Packit Service 82fcde
@deftypefunx float ynf (int @var{n}, float @var{x})
Packit Service 82fcde
@deftypefunx {long double} ynl (int @var{n}, long double @var{x})
Packit Service 82fcde
@deftypefunx _FloatN ynfN (int @var{n}, _Float@var{N} @var{x})
Packit Service 82fcde
@deftypefunx _FloatNx ynfNx (int @var{n}, _Float@var{N}x @var{x})
Packit Service 82fcde
@standards{SVID, math.h}
Packit Service 82fcde
@standardsx{ynfN, GNU, math.h}
Packit Service 82fcde
@standardsx{ynfNx, GNU, math.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@code{yn} returns the Bessel function of the second kind of order @var{n} of
Packit Service 82fcde
@var{x}.  It may signal underflow if @var{x} is too large.  If @var{x}
Packit Service 82fcde
is negative, @code{yn} signals a domain error; if it is zero,
Packit Service 82fcde
@code{yn} signals overflow and returns @math{-@infinity}.
Packit Service 82fcde
Packit Service 82fcde
The @code{_Float@var{N}} and @code{_Float@var{N}x} variants are GNU
Packit Service 82fcde
extensions.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@node Errors in Math Functions
Packit Service 82fcde
@section Known Maximum Errors in Math Functions
Packit Service 82fcde
@cindex math errors
Packit Service 82fcde
@cindex ulps
Packit Service 82fcde
Packit Service 82fcde
This section lists the known errors of the functions in the math
Packit Service 82fcde
library.  Errors are measured in ``units of the last place''.  This is a
Packit Service 82fcde
measure for the relative error.  For a number @math{z} with the
Packit Service 82fcde
representation @math{d.d@dots{}d@mul{}2^e} (we assume IEEE
Packit Service 82fcde
floating-point numbers with base 2) the ULP is represented by
Packit Service 82fcde
Packit Service 82fcde
@tex
Packit Service 82fcde
$${|d.d\dots d - (z/2^e)|}\over {2^{p-1}}$$
Packit Service 82fcde
@end tex
Packit Service 82fcde
@ifnottex
Packit Service 82fcde
@smallexample
Packit Service 82fcde
|d.d...d - (z / 2^e)| / 2^(p - 1)
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
@end ifnottex
Packit Service 82fcde
Packit Service 82fcde
@noindent
Packit Service 82fcde
where @math{p} is the number of bits in the mantissa of the
Packit Service 82fcde
floating-point number representation.  Ideally the error for all
Packit Service 82fcde
functions is always less than 0.5ulps in round-to-nearest mode.  Using
Packit Service 82fcde
rounding bits this is also
Packit Service 82fcde
possible and normally implemented for the basic operations.  Except
Packit Service 82fcde
for certain functions such as @code{sqrt}, @code{fma} and @code{rint}
Packit Service 82fcde
whose results are fully specified by reference to corresponding IEEE
Packit Service 82fcde
754 floating-point operations, and conversions between strings and
Packit Service 82fcde
floating point, @theglibc{} does not aim for correctly rounded results
Packit Service 82fcde
for functions in the math library, and does not aim for correctness in
Packit Service 82fcde
whether ``inexact'' exceptions are raised.  Instead, the goals for
Packit Service 82fcde
accuracy of functions without fully specified results are as follows;
Packit Service 82fcde
some functions have bugs meaning they do not meet these goals in all
Packit Service 82fcde
cases.  In the future, @theglibc{} may provide some other correctly
Packit Service 82fcde
rounding functions under the names such as @code{crsin} proposed for
Packit Service 82fcde
an extension to ISO C.
Packit Service 82fcde
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
Each function with a floating-point result behaves as if it computes
Packit Service 82fcde
an infinite-precision result that is within a few ulp (in both real
Packit Service 82fcde
and complex parts, for functions with complex results) of the
Packit Service 82fcde
mathematically correct value of the function (interpreted together
Packit Service 82fcde
with ISO C or POSIX semantics for the function in question) at the
Packit Service 82fcde
exact value passed as the input.  Exceptions are raised appropriately
Packit Service 82fcde
for this value and in accordance with IEEE 754 / ISO C / POSIX
Packit Service 82fcde
semantics, and it is then rounded according to the current rounding
Packit Service 82fcde
direction to the result that is returned to the user.  @code{errno}
Packit Service 82fcde
may also be set (@pxref{Math Error Reporting}).  (The ``inexact''
Packit Service 82fcde
exception may be raised, or not raised, even if this is inconsistent
Packit Service 82fcde
with the infinite-precision value.)
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
For the IBM @code{long double} format, as used on PowerPC GNU/Linux,
Packit Service 82fcde
the accuracy goal is weaker for input values not exactly representable
Packit Service 82fcde
in 106 bits of precision; it is as if the input value is some value
Packit Service 82fcde
within 0.5ulp of the value actually passed, where ``ulp'' is
Packit Service 82fcde
interpreted in terms of a fixed-precision 106-bit mantissa, but not
Packit Service 82fcde
necessarily the exact value actually passed with discontiguous
Packit Service 82fcde
mantissa bits.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
For the IBM @code{long double} format, functions whose results are
Packit Service 82fcde
fully specified by reference to corresponding IEEE 754 floating-point
Packit Service 82fcde
operations have the same accuracy goals as other functions, but with
Packit Service 82fcde
the error bound being the same as that for division (3ulp).
Packit Service 82fcde
Furthermore, ``inexact'' and ``underflow'' exceptions may be raised
Packit Service 82fcde
for all functions for any inputs, even where such exceptions are
Packit Service 82fcde
inconsistent with the returned value, since the underlying
Packit Service 82fcde
floating-point arithmetic has that property.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
Functions behave as if the infinite-precision result computed is zero,
Packit Service 82fcde
infinity or NaN if and only if that is the mathematically correct
Packit Service 82fcde
infinite-precision result.  They behave as if the infinite-precision
Packit Service 82fcde
result computed always has the same sign as the mathematically correct
Packit Service 82fcde
result.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
If the mathematical result is more than a few ulp above the overflow
Packit Service 82fcde
threshold for the current rounding direction, the value returned is
Packit Service 82fcde
the appropriate overflow value for the current rounding direction,
Packit Service 82fcde
with the overflow exception raised.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
If the mathematical result has magnitude well below half the least
Packit Service 82fcde
subnormal magnitude, the returned value is either zero or the least
Packit Service 82fcde
subnormal (in each case, with the correct sign), according to the
Packit Service 82fcde
current rounding direction and with the underflow exception raised.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
Where the mathematical result underflows (before rounding) and is not
Packit Service 82fcde
exactly representable as a floating-point value, the function does not
Packit Service 82fcde
behave as if the computed infinite-precision result is an exact value
Packit Service 82fcde
in the subnormal range.  This means that the underflow exception is
Packit Service 82fcde
raised other than possibly for cases where the mathematical result is
Packit Service 82fcde
very close to the underflow threshold and the function behaves as if
Packit Service 82fcde
it computes an infinite-precision result that does not underflow.  (So
Packit Service 82fcde
there may be spurious underflow exceptions in cases where the
Packit Service 82fcde
underflowing result is exact, but not missing underflow exceptions in
Packit Service 82fcde
cases where it is inexact.)
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@Theglibc{} does not aim for functions to satisfy other properties of
Packit Service 82fcde
the underlying mathematical function, such as monotonicity, where not
Packit Service 82fcde
implied by the above goals.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
All the above applies to both real and complex parts, for complex
Packit Service 82fcde
functions.
Packit Service 82fcde
Packit Service 82fcde
@end itemize
Packit Service 82fcde
Packit Service 82fcde
Therefore many of the functions in the math library have errors.  The
Packit Service 82fcde
table lists the maximum error for each function which is exposed by one
Packit Service 82fcde
of the existing tests in the test suite.  The table tries to cover as much
Packit Service 82fcde
as possible and list the actual maximum error (or at least a ballpark
Packit Service 82fcde
figure) but this is often not achieved due to the large search space.
Packit Service 82fcde
Packit Service 82fcde
The table lists the ULP values for different architectures.  Different
Packit Service 82fcde
architectures have different results since their hardware support for
Packit Service 82fcde
floating-point operations varies and also the existing hardware support
Packit Service 82fcde
is different.  Only the round-to-nearest rounding mode is covered by
Packit Service 82fcde
this table, and vector versions of functions are not covered.
Packit Service 82fcde
Functions not listed do not have known errors.
Packit Service 82fcde
Packit Service 82fcde
@page
Packit Service 82fcde
@c This multitable does not fit on a single page
Packit Service 82fcde
@include libm-err.texi
Packit Service 82fcde
Packit Service 82fcde
@node Pseudo-Random Numbers
Packit Service 82fcde
@section Pseudo-Random Numbers
Packit Service 82fcde
@cindex random numbers
Packit Service 82fcde
@cindex pseudo-random numbers
Packit Service 82fcde
@cindex seed (for random numbers)
Packit Service 82fcde
Packit Service 82fcde
This section describes the GNU facilities for generating a series of
Packit Service 82fcde
pseudo-random numbers.  The numbers generated are not truly random;
Packit Service 82fcde
typically, they form a sequence that repeats periodically, with a period
Packit Service 82fcde
so large that you can ignore it for ordinary purposes.  The random
Packit Service 82fcde
number generator works by remembering a @dfn{seed} value which it uses
Packit Service 82fcde
to compute the next random number and also to compute a new seed.
Packit Service 82fcde
Packit Service 82fcde
Although the generated numbers look unpredictable within one run of a
Packit Service 82fcde
program, the sequence of numbers is @emph{exactly the same} from one run
Packit Service 82fcde
to the next.  This is because the initial seed is always the same.  This
Packit Service 82fcde
is convenient when you are debugging a program, but it is unhelpful if
Packit Service 82fcde
you want the program to behave unpredictably.  If you want a different
Packit Service 82fcde
pseudo-random series each time your program runs, you must specify a
Packit Service 82fcde
different seed each time.  For ordinary purposes, basing the seed on the
Packit Service 82fcde
current time works well.  For random numbers in cryptography,
Packit Service 82fcde
@pxref{Unpredictable Bytes}.
Packit Service 82fcde
Packit Service 82fcde
You can obtain repeatable sequences of numbers on a particular machine type
Packit Service 82fcde
by specifying the same initial seed value for the random number
Packit Service 82fcde
generator.  There is no standard meaning for a particular seed value;
Packit Service 82fcde
the same seed, used in different C libraries or on different CPU types,
Packit Service 82fcde
will give you different random numbers.
Packit Service 82fcde
Packit Service 82fcde
@Theglibc{} supports the standard @w{ISO C} random number functions
Packit Service 82fcde
plus two other sets derived from BSD and SVID.  The BSD and @w{ISO C}
Packit Service 82fcde
functions provide identical, somewhat limited functionality.  If only a
Packit Service 82fcde
small number of random bits are required, we recommend you use the
Packit Service 82fcde
@w{ISO C} interface, @code{rand} and @code{srand}.  The SVID functions
Packit Service 82fcde
provide a more flexible interface, which allows better random number
Packit Service 82fcde
generator algorithms, provides more random bits (up to 48) per call, and
Packit Service 82fcde
can provide random floating-point numbers.  These functions are required
Packit Service 82fcde
by the XPG standard and therefore will be present in all modern Unix
Packit Service 82fcde
systems.
Packit Service 82fcde
Packit Service 82fcde
@menu
Packit Service 82fcde
* ISO Random::                  @code{rand} and friends.
Packit Service 82fcde
* BSD Random::                  @code{random} and friends.
Packit Service 82fcde
* SVID Random::                 @code{drand48} and friends.
Packit Service 82fcde
@end menu
Packit Service 82fcde
Packit Service 82fcde
@node ISO Random
Packit Service 82fcde
@subsection ISO C Random Number Functions
Packit Service 82fcde
Packit Service 82fcde
This section describes the random number functions that are part of
Packit Service 82fcde
the @w{ISO C} standard.
Packit Service 82fcde
Packit Service 82fcde
To use these facilities, you should include the header file
Packit Service 82fcde
@file{stdlib.h} in your program.
Packit Service 82fcde
@pindex stdlib.h
Packit Service 82fcde
Packit Service 82fcde
@deftypevr Macro int RAND_MAX
Packit Service 82fcde
@standards{ISO, stdlib.h}
Packit Service 82fcde
The value of this macro is an integer constant representing the largest
Packit Service 82fcde
value the @code{rand} function can return.  In @theglibc{}, it is
Packit Service 82fcde
@code{2147483647}, which is the largest signed integer representable in
Packit Service 82fcde
32 bits.  In other libraries, it may be as low as @code{32767}.
Packit Service 82fcde
@end deftypevr
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int rand (void)
Packit Service 82fcde
@standards{ISO, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@asunsafe{@asulock{}}@acunsafe{@aculock{}}}
Packit Service 82fcde
@c Just calls random.
Packit Service 82fcde
The @code{rand} function returns the next pseudo-random number in the
Packit Service 82fcde
series.  The value ranges from @code{0} to @code{RAND_MAX}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun void srand (unsigned int @var{seed})
Packit Service 82fcde
@standards{ISO, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@asunsafe{@asulock{}}@acunsafe{@aculock{}}}
Packit Service 82fcde
@c Alias to srandom.
Packit Service 82fcde
This function establishes @var{seed} as the seed for a new series of
Packit Service 82fcde
pseudo-random numbers.  If you call @code{rand} before a seed has been
Packit Service 82fcde
established with @code{srand}, it uses the value @code{1} as a default
Packit Service 82fcde
seed.
Packit Service 82fcde
Packit Service 82fcde
To produce a different pseudo-random series each time your program is
Packit Service 82fcde
run, do @code{srand (time (0))}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
POSIX.1 extended the C standard functions to support reproducible random
Packit Service 82fcde
numbers in multi-threaded programs.  However, the extension is badly
Packit Service 82fcde
designed and unsuitable for serious work.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int rand_r (unsigned int *@var{seed})
Packit Service 82fcde
@standards{POSIX.1, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
This function returns a random number in the range 0 to @code{RAND_MAX}
Packit Service 82fcde
just as @code{rand} does.  However, all its state is stored in the
Packit Service 82fcde
@var{seed} argument.  This means the RNG's state can only have as many
Packit Service 82fcde
bits as the type @code{unsigned int} has.  This is far too few to
Packit Service 82fcde
provide a good RNG.
Packit Service 82fcde
Packit Service 82fcde
If your program requires a reentrant RNG, we recommend you use the
Packit Service 82fcde
reentrant GNU extensions to the SVID random number generator.  The
Packit Service 82fcde
POSIX.1 interface should only be used when the GNU extensions are not
Packit Service 82fcde
available.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@node BSD Random
Packit Service 82fcde
@subsection BSD Random Number Functions
Packit Service 82fcde
Packit Service 82fcde
This section describes a set of random number generation functions that
Packit Service 82fcde
are derived from BSD.  There is no advantage to using these functions
Packit Service 82fcde
with @theglibc{}; we support them for BSD compatibility only.
Packit Service 82fcde
Packit Service 82fcde
The prototypes for these functions are in @file{stdlib.h}.
Packit Service 82fcde
@pindex stdlib.h
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {long int} random (void)
Packit Service 82fcde
@standards{BSD, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@asunsafe{@asulock{}}@acunsafe{@aculock{}}}
Packit Service 82fcde
@c Takes a lock and calls random_r with an automatic variable and the
Packit Service 82fcde
@c global state, while holding a lock.
Packit Service 82fcde
This function returns the next pseudo-random number in the sequence.
Packit Service 82fcde
The value returned ranges from @code{0} to @code{2147483647}.
Packit Service 82fcde
Packit Service 82fcde
@strong{NB:} Temporarily this function was defined to return a
Packit Service 82fcde
@code{int32_t} value to indicate that the return value always contains
Packit Service 82fcde
32 bits even if @code{long int} is wider.  The standard demands it
Packit Service 82fcde
differently.  Users must always be aware of the 32-bit limitation,
Packit Service 82fcde
though.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun void srandom (unsigned int @var{seed})
Packit Service 82fcde
@standards{BSD, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@asunsafe{@asulock{}}@acunsafe{@aculock{}}}
Packit Service 82fcde
@c Takes a lock and calls srandom_r with an automatic variable and a
Packit Service 82fcde
@c static buffer.  There's no MT-safety issue because the static buffer
Packit Service 82fcde
@c is internally protected by a lock, although other threads may modify
Packit Service 82fcde
@c the set state before it is used.
Packit Service 82fcde
The @code{srandom} function sets the state of the random number
Packit Service 82fcde
generator based on the integer @var{seed}.  If you supply a @var{seed} value
Packit Service 82fcde
of @code{1}, this will cause @code{random} to reproduce the default set
Packit Service 82fcde
of random numbers.
Packit Service 82fcde
Packit Service 82fcde
To produce a different set of pseudo-random numbers each time your
Packit Service 82fcde
program runs, do @code{srandom (time (0))}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {char *} initstate (unsigned int @var{seed}, char *@var{state}, size_t @var{size})
Packit Service 82fcde
@standards{BSD, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@asunsafe{@asulock{}}@acunsafe{@aculock{}}}
Packit Service 82fcde
The @code{initstate} function is used to initialize the random number
Packit Service 82fcde
generator state.  The argument @var{state} is an array of @var{size}
Packit Service 82fcde
bytes, used to hold the state information.  It is initialized based on
Packit Service 82fcde
@var{seed}.  The size must be between 8 and 256 bytes, and should be a
Packit Service 82fcde
power of two.  The bigger the @var{state} array, the better.
Packit Service 82fcde
Packit Service 82fcde
The return value is the previous value of the state information array.
Packit Service 82fcde
You can use this value later as an argument to @code{setstate} to
Packit Service 82fcde
restore that state.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {char *} setstate (char *@var{state})
Packit Service 82fcde
@standards{BSD, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@asunsafe{@asulock{}}@acunsafe{@aculock{}}}
Packit Service 82fcde
The @code{setstate} function restores the random number state
Packit Service 82fcde
information @var{state}.  The argument must have been the result of
Packit Service 82fcde
a previous call to @var{initstate} or @var{setstate}.
Packit Service 82fcde
Packit Service 82fcde
The return value is the previous value of the state information array.
Packit Service 82fcde
You can use this value later as an argument to @code{setstate} to
Packit Service 82fcde
restore that state.
Packit Service 82fcde
Packit Service 82fcde
If the function fails the return value is @code{NULL}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
The four functions described so far in this section all work on a state
Packit Service 82fcde
which is shared by all threads.  The state is not directly accessible to
Packit Service 82fcde
the user and can only be modified by these functions.  This makes it
Packit Service 82fcde
hard to deal with situations where each thread should have its own
Packit Service 82fcde
pseudo-random number generator.
Packit Service 82fcde
Packit Service 82fcde
@Theglibc{} contains four additional functions which contain the
Packit Service 82fcde
state as an explicit parameter and therefore make it possible to handle
Packit Service 82fcde
thread-local PRNGs.  Besides this there is no difference.  In fact, the
Packit Service 82fcde
four functions already discussed are implemented internally using the
Packit Service 82fcde
following interfaces.
Packit Service 82fcde
Packit Service 82fcde
The @file{stdlib.h} header contains a definition of the following type:
Packit Service 82fcde
Packit Service 82fcde
@deftp {Data Type} {struct random_data}
Packit Service 82fcde
@standards{GNU, stdlib.h}
Packit Service 82fcde
Packit Service 82fcde
Objects of type @code{struct random_data} contain the information
Packit Service 82fcde
necessary to represent the state of the PRNG.  Although a complete
Packit Service 82fcde
definition of the type is present the type should be treated as opaque.
Packit Service 82fcde
@end deftp
Packit Service 82fcde
Packit Service 82fcde
The functions modifying the state follow exactly the already described
Packit Service 82fcde
functions.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int random_r (struct random_data *restrict @var{buf}, int32_t *restrict @var{result})
Packit Service 82fcde
@standards{GNU, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{@mtsrace{:buf}}@assafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
The @code{random_r} function behaves exactly like the @code{random}
Packit Service 82fcde
function except that it uses and modifies the state in the object
Packit Service 82fcde
pointed to by the first parameter instead of the global state.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int srandom_r (unsigned int @var{seed}, struct random_data *@var{buf})
Packit Service 82fcde
@standards{GNU, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{@mtsrace{:buf}}@assafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
The @code{srandom_r} function behaves exactly like the @code{srandom}
Packit Service 82fcde
function except that it uses and modifies the state in the object
Packit Service 82fcde
pointed to by the second parameter instead of the global state.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int initstate_r (unsigned int @var{seed}, char *restrict @var{statebuf}, size_t @var{statelen}, struct random_data *restrict @var{buf})
Packit Service 82fcde
@standards{GNU, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{@mtsrace{:buf}}@assafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
The @code{initstate_r} function behaves exactly like the @code{initstate}
Packit Service 82fcde
function except that it uses and modifies the state in the object
Packit Service 82fcde
pointed to by the fourth parameter instead of the global state.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int setstate_r (char *restrict @var{statebuf}, struct random_data *restrict @var{buf})
Packit Service 82fcde
@standards{GNU, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{@mtsrace{:buf}}@assafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
The @code{setstate_r} function behaves exactly like the @code{setstate}
Packit Service 82fcde
function except that it uses and modifies the state in the object
Packit Service 82fcde
pointed to by the first parameter instead of the global state.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@node SVID Random
Packit Service 82fcde
@subsection SVID Random Number Function
Packit Service 82fcde
Packit Service 82fcde
The C library on SVID systems contains yet another kind of random number
Packit Service 82fcde
generator functions.  They use a state of 48 bits of data.  The user can
Packit Service 82fcde
choose among a collection of functions which return the random bits
Packit Service 82fcde
in different forms.
Packit Service 82fcde
Packit Service 82fcde
Generally there are two kinds of function.  The first uses a state of
Packit Service 82fcde
the random number generator which is shared among several functions and
Packit Service 82fcde
by all threads of the process.  The second requires the user to handle
Packit Service 82fcde
the state.
Packit Service 82fcde
Packit Service 82fcde
All functions have in common that they use the same congruential
Packit Service 82fcde
formula with the same constants.  The formula is
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
Y = (a * X + c) mod m
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@noindent
Packit Service 82fcde
where @var{X} is the state of the generator at the beginning and
Packit Service 82fcde
@var{Y} the state at the end.  @code{a} and @code{c} are constants
Packit Service 82fcde
determining the way the generator works.  By default they are
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
a = 0x5DEECE66D = 25214903917
Packit Service 82fcde
c = 0xb = 11
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@noindent
Packit Service 82fcde
but they can also be changed by the user.  @code{m} is of course 2^48
Packit Service 82fcde
since the state consists of a 48-bit array.
Packit Service 82fcde
Packit Service 82fcde
The prototypes for these functions are in @file{stdlib.h}.
Packit Service 82fcde
@pindex stdlib.h
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double drand48 (void)
Packit Service 82fcde
@standards{SVID, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:drand48}}@asunsafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
@c Uses of the static state buffer are not guarded by a lock (thus
Packit Service 82fcde
@c @mtasurace:drand48), so they may be found or left at a
Packit Service 82fcde
@c partially-updated state in case of calls from within signal handlers
Packit Service 82fcde
@c or cancellation.  None of this will break safety rules or invoke
Packit Service 82fcde
@c undefined behavior, but it may affect randomness.
Packit Service 82fcde
This function returns a @code{double} value in the range of @code{0.0}
Packit Service 82fcde
to @code{1.0} (exclusive).  The random bits are determined by the global
Packit Service 82fcde
state of the random number generator in the C library.
Packit Service 82fcde
Packit Service 82fcde
Since the @code{double} type according to @w{IEEE 754} has a 52-bit
Packit Service 82fcde
mantissa this means 4 bits are not initialized by the random number
Packit Service 82fcde
generator.  These are (of course) chosen to be the least significant
Packit Service 82fcde
bits and they are initialized to @code{0}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun double erand48 (unsigned short int @var{xsubi}[3])
Packit Service 82fcde
@standards{SVID, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:drand48}}@asunsafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
@c The static buffer is just initialized with default parameters, which
Packit Service 82fcde
@c are later read to advance the state held in xsubi.
Packit Service 82fcde
This function returns a @code{double} value in the range of @code{0.0}
Packit Service 82fcde
to @code{1.0} (exclusive), similarly to @code{drand48}.  The argument is
Packit Service 82fcde
an array describing the state of the random number generator.
Packit Service 82fcde
Packit Service 82fcde
This function can be called subsequently since it updates the array to
Packit Service 82fcde
guarantee random numbers.  The array should have been initialized before
Packit Service 82fcde
initial use to obtain reproducible results.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {long int} lrand48 (void)
Packit Service 82fcde
@standards{SVID, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:drand48}}@asunsafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
The @code{lrand48} function returns an integer value in the range of
Packit Service 82fcde
@code{0} to @code{2^31} (exclusive).  Even if the size of the @code{long
Packit Service 82fcde
int} type can take more than 32 bits, no higher numbers are returned.
Packit Service 82fcde
The random bits are determined by the global state of the random number
Packit Service 82fcde
generator in the C library.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {long int} nrand48 (unsigned short int @var{xsubi}[3])
Packit Service 82fcde
@standards{SVID, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:drand48}}@asunsafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
This function is similar to the @code{lrand48} function in that it
Packit Service 82fcde
returns a number in the range of @code{0} to @code{2^31} (exclusive) but
Packit Service 82fcde
the state of the random number generator used to produce the random bits
Packit Service 82fcde
is determined by the array provided as the parameter to the function.
Packit Service 82fcde
Packit Service 82fcde
The numbers in the array are updated afterwards so that subsequent calls
Packit Service 82fcde
to this function yield different results (as is expected of a random
Packit Service 82fcde
number generator).  The array should have been initialized before the
Packit Service 82fcde
first call to obtain reproducible results.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {long int} mrand48 (void)
Packit Service 82fcde
@standards{SVID, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:drand48}}@asunsafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
The @code{mrand48} function is similar to @code{lrand48}.  The only
Packit Service 82fcde
difference is that the numbers returned are in the range @code{-2^31} to
Packit Service 82fcde
@code{2^31} (exclusive).
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {long int} jrand48 (unsigned short int @var{xsubi}[3])
Packit Service 82fcde
@standards{SVID, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:drand48}}@asunsafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
The @code{jrand48} function is similar to @code{nrand48}.  The only
Packit Service 82fcde
difference is that the numbers returned are in the range @code{-2^31} to
Packit Service 82fcde
@code{2^31} (exclusive).  For the @code{xsubi} parameter the same
Packit Service 82fcde
requirements are necessary.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
The internal state of the random number generator can be initialized in
Packit Service 82fcde
several ways.  The methods differ in the completeness of the
Packit Service 82fcde
information provided.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun void srand48 (long int @var{seedval})
Packit Service 82fcde
@standards{SVID, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:drand48}}@asunsafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
The @code{srand48} function sets the most significant 32 bits of the
Packit Service 82fcde
internal state of the random number generator to the least
Packit Service 82fcde
significant 32 bits of the @var{seedval} parameter.  The lower 16 bits
Packit Service 82fcde
are initialized to the value @code{0x330E}.  Even if the @code{long
Packit Service 82fcde
int} type contains more than 32 bits only the lower 32 bits are used.
Packit Service 82fcde
Packit Service 82fcde
Owing to this limitation, initialization of the state of this
Packit Service 82fcde
function is not very useful.  But it makes it easy to use a construct
Packit Service 82fcde
like @code{srand48 (time (0))}.
Packit Service 82fcde
Packit Service 82fcde
A side-effect of this function is that the values @code{a} and @code{c}
Packit Service 82fcde
from the internal state, which are used in the congruential formula,
Packit Service 82fcde
are reset to the default values given above.  This is of importance once
Packit Service 82fcde
the user has called the @code{lcong48} function (see below).
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {unsigned short int *} seed48 (unsigned short int @var{seed16v}[3])
Packit Service 82fcde
@standards{SVID, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:drand48}}@asunsafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
The @code{seed48} function initializes all 48 bits of the state of the
Packit Service 82fcde
internal random number generator from the contents of the parameter
Packit Service 82fcde
@var{seed16v}.  Here the lower 16 bits of the first element of
Packit Service 82fcde
@var{seed16v} initialize the least significant 16 bits of the internal
Packit Service 82fcde
state, the lower 16 bits of @code{@var{seed16v}[1]} initialize the mid-order
Packit Service 82fcde
16 bits of the state and the 16 lower bits of @code{@var{seed16v}[2]}
Packit Service 82fcde
initialize the most significant 16 bits of the state.
Packit Service 82fcde
Packit Service 82fcde
Unlike @code{srand48} this function lets the user initialize all 48 bits
Packit Service 82fcde
of the state.
Packit Service 82fcde
Packit Service 82fcde
The value returned by @code{seed48} is a pointer to an array containing
Packit Service 82fcde
the values of the internal state before the change.  This might be
Packit Service 82fcde
useful to restart the random number generator at a certain state.
Packit Service 82fcde
Otherwise the value can simply be ignored.
Packit Service 82fcde
Packit Service 82fcde
As for @code{srand48}, the values @code{a} and @code{c} from the
Packit Service 82fcde
congruential formula are reset to the default values.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
There is one more function to initialize the random number generator
Packit Service 82fcde
which enables you to specify even more information by allowing you to
Packit Service 82fcde
change the parameters in the congruential formula.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun void lcong48 (unsigned short int @var{param}[7])
Packit Service 82fcde
@standards{SVID, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:drand48}}@asunsafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
The @code{lcong48} function allows the user to change the complete state
Packit Service 82fcde
of the random number generator.  Unlike @code{srand48} and
Packit Service 82fcde
@code{seed48}, this function also changes the constants in the
Packit Service 82fcde
congruential formula.
Packit Service 82fcde
Packit Service 82fcde
From the seven elements in the array @var{param} the least significant
Packit Service 82fcde
16 bits of the entries @code{@var{param}[0]} to @code{@var{param}[2]}
Packit Service 82fcde
determine the initial state, the least significant 16 bits of
Packit Service 82fcde
@code{@var{param}[3]} to @code{@var{param}[5]} determine the 48 bit
Packit Service 82fcde
constant @code{a} and @code{@var{param}[6]} determines the 16-bit value
Packit Service 82fcde
@code{c}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
All the above functions have in common that they use the global
Packit Service 82fcde
parameters for the congruential formula.  In multi-threaded programs it
Packit Service 82fcde
might sometimes be useful to have different parameters in different
Packit Service 82fcde
threads.  For this reason all the above functions have a counterpart
Packit Service 82fcde
which works on a description of the random number generator in the
Packit Service 82fcde
user-supplied buffer instead of the global state.
Packit Service 82fcde
Packit Service 82fcde
Please note that it is no problem if several threads use the global
Packit Service 82fcde
state if all threads use the functions which take a pointer to an array
Packit Service 82fcde
containing the state.  The random numbers are computed following the
Packit Service 82fcde
same loop but if the state in the array is different all threads will
Packit Service 82fcde
obtain an individual random number generator.
Packit Service 82fcde
Packit Service 82fcde
The user-supplied buffer must be of type @code{struct drand48_data}.
Packit Service 82fcde
This type should be regarded as opaque and not manipulated directly.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int drand48_r (struct drand48_data *@var{buffer}, double *@var{result})
Packit Service 82fcde
@standards{GNU, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{@mtsrace{:buffer}}@assafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
This function is equivalent to the @code{drand48} function with the
Packit Service 82fcde
difference that it does not modify the global random number generator
Packit Service 82fcde
parameters but instead the parameters in the buffer supplied through the
Packit Service 82fcde
pointer @var{buffer}.  The random number is returned in the variable
Packit Service 82fcde
pointed to by @var{result}.
Packit Service 82fcde
Packit Service 82fcde
The return value of the function indicates whether the call succeeded.
Packit Service 82fcde
If the value is less than @code{0} an error occurred and @var{errno} is
Packit Service 82fcde
set to indicate the problem.
Packit Service 82fcde
Packit Service 82fcde
This function is a GNU extension and should not be used in portable
Packit Service 82fcde
programs.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int erand48_r (unsigned short int @var{xsubi}[3], struct drand48_data *@var{buffer}, double *@var{result})
Packit Service 82fcde
@standards{GNU, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{@mtsrace{:buffer}}@assafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
The @code{erand48_r} function works like @code{erand48}, but in addition
Packit Service 82fcde
it takes an argument @var{buffer} which describes the random number
Packit Service 82fcde
generator.  The state of the random number generator is taken from the
Packit Service 82fcde
@code{xsubi} array, the parameters for the congruential formula from the
Packit Service 82fcde
global random number generator data.  The random number is returned in
Packit Service 82fcde
the variable pointed to by @var{result}.
Packit Service 82fcde
Packit Service 82fcde
The return value is non-negative if the call succeeded.
Packit Service 82fcde
Packit Service 82fcde
This function is a GNU extension and should not be used in portable
Packit Service 82fcde
programs.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int lrand48_r (struct drand48_data *@var{buffer}, long int *@var{result})
Packit Service 82fcde
@standards{GNU, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{@mtsrace{:buffer}}@assafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
This function is similar to @code{lrand48}, but in addition it takes a
Packit Service 82fcde
pointer to a buffer describing the state of the random number generator
Packit Service 82fcde
just like @code{drand48}.
Packit Service 82fcde
Packit Service 82fcde
If the return value of the function is non-negative the variable pointed
Packit Service 82fcde
to by @var{result} contains the result.  Otherwise an error occurred.
Packit Service 82fcde
Packit Service 82fcde
This function is a GNU extension and should not be used in portable
Packit Service 82fcde
programs.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int nrand48_r (unsigned short int @var{xsubi}[3], struct drand48_data *@var{buffer}, long int *@var{result})
Packit Service 82fcde
@standards{GNU, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{@mtsrace{:buffer}}@assafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
The @code{nrand48_r} function works like @code{nrand48} in that it
Packit Service 82fcde
produces a random number in the range @code{0} to @code{2^31}.  But instead
Packit Service 82fcde
of using the global parameters for the congruential formula it uses the
Packit Service 82fcde
information from the buffer pointed to by @var{buffer}.  The state is
Packit Service 82fcde
described by the values in @var{xsubi}.
Packit Service 82fcde
Packit Service 82fcde
If the return value is non-negative the variable pointed to by
Packit Service 82fcde
@var{result} contains the result.
Packit Service 82fcde
Packit Service 82fcde
This function is a GNU extension and should not be used in portable
Packit Service 82fcde
programs.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int mrand48_r (struct drand48_data *@var{buffer}, long int *@var{result})
Packit Service 82fcde
@standards{GNU, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{@mtsrace{:buffer}}@assafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
This function is similar to @code{mrand48} but like the other reentrant
Packit Service 82fcde
functions it uses the random number generator described by the value in
Packit Service 82fcde
the buffer pointed to by @var{buffer}.
Packit Service 82fcde
Packit Service 82fcde
If the return value is non-negative the variable pointed to by
Packit Service 82fcde
@var{result} contains the result.
Packit Service 82fcde
Packit Service 82fcde
This function is a GNU extension and should not be used in portable
Packit Service 82fcde
programs.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int jrand48_r (unsigned short int @var{xsubi}[3], struct drand48_data *@var{buffer}, long int *@var{result})
Packit Service 82fcde
@standards{GNU, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{@mtsrace{:buffer}}@assafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
The @code{jrand48_r} function is similar to @code{jrand48}.  Like the
Packit Service 82fcde
other reentrant functions of this function family it uses the
Packit Service 82fcde
congruential formula parameters from the buffer pointed to by
Packit Service 82fcde
@var{buffer}.
Packit Service 82fcde
Packit Service 82fcde
If the return value is non-negative the variable pointed to by
Packit Service 82fcde
@var{result} contains the result.
Packit Service 82fcde
Packit Service 82fcde
This function is a GNU extension and should not be used in portable
Packit Service 82fcde
programs.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
Before any of the above functions are used the buffer of type
Packit Service 82fcde
@code{struct drand48_data} should be initialized.  The easiest way to do
Packit Service 82fcde
this is to fill the whole buffer with null bytes, e.g. by
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
memset (buffer, '\0', sizeof (struct drand48_data));
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@noindent
Packit Service 82fcde
Using any of the reentrant functions of this family now will
Packit Service 82fcde
automatically initialize the random number generator to the default
Packit Service 82fcde
values for the state and the parameters of the congruential formula.
Packit Service 82fcde
Packit Service 82fcde
The other possibility is to use any of the functions which explicitly
Packit Service 82fcde
initialize the buffer.  Though it might be obvious how to initialize the
Packit Service 82fcde
buffer from looking at the parameter to the function, it is highly
Packit Service 82fcde
recommended to use these functions since the result might not always be
Packit Service 82fcde
what you expect.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int srand48_r (long int @var{seedval}, struct drand48_data *@var{buffer})
Packit Service 82fcde
@standards{GNU, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{@mtsrace{:buffer}}@assafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
The description of the random number generator represented by the
Packit Service 82fcde
information in @var{buffer} is initialized similarly to what the function
Packit Service 82fcde
@code{srand48} does.  The state is initialized from the parameter
Packit Service 82fcde
@var{seedval} and the parameters for the congruential formula are
Packit Service 82fcde
initialized to their default values.
Packit Service 82fcde
Packit Service 82fcde
If the return value is non-negative the function call succeeded.
Packit Service 82fcde
Packit Service 82fcde
This function is a GNU extension and should not be used in portable
Packit Service 82fcde
programs.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int seed48_r (unsigned short int @var{seed16v}[3], struct drand48_data *@var{buffer})
Packit Service 82fcde
@standards{GNU, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{@mtsrace{:buffer}}@assafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
This function is similar to @code{srand48_r} but like @code{seed48} it
Packit Service 82fcde
initializes all 48 bits of the state from the parameter @var{seed16v}.
Packit Service 82fcde
Packit Service 82fcde
If the return value is non-negative the function call succeeded.  It
Packit Service 82fcde
does not return a pointer to the previous state of the random number
Packit Service 82fcde
generator like the @code{seed48} function does.  If the user wants to
Packit Service 82fcde
preserve the state for a later re-run s/he can copy the whole buffer
Packit Service 82fcde
pointed to by @var{buffer}.
Packit Service 82fcde
Packit Service 82fcde
This function is a GNU extension and should not be used in portable
Packit Service 82fcde
programs.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int lcong48_r (unsigned short int @var{param}[7], struct drand48_data *@var{buffer})
Packit Service 82fcde
@standards{GNU, stdlib.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{@mtsrace{:buffer}}@assafe{}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
This function initializes all aspects of the random number generator
Packit Service 82fcde
described in @var{buffer} with the data in @var{param}.  Here it is
Packit Service 82fcde
especially true that the function does more than just copying the
Packit Service 82fcde
contents of @var{param} and @var{buffer}.  More work is required and
Packit Service 82fcde
therefore it is important to use this function rather than initializing
Packit Service 82fcde
the random number generator directly.
Packit Service 82fcde
Packit Service 82fcde
If the return value is non-negative the function call succeeded.
Packit Service 82fcde
Packit Service 82fcde
This function is a GNU extension and should not be used in portable
Packit Service 82fcde
programs.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@node FP Function Optimizations
Packit Service 82fcde
@section Is Fast Code or Small Code preferred?
Packit Service 82fcde
@cindex Optimization
Packit Service 82fcde
Packit Service 82fcde
If an application uses many floating point functions it is often the case
Packit Service 82fcde
that the cost of the function calls themselves is not negligible.
Packit Service 82fcde
Modern processors can often execute the operations themselves
Packit Service 82fcde
very fast, but the function call disrupts the instruction pipeline.
Packit Service 82fcde
Packit Service 82fcde
For this reason @theglibc{} provides optimizations for many of the
Packit Service 82fcde
frequently-used math functions.  When GNU CC is used and the user
Packit Service 82fcde
activates the optimizer, several new inline functions and macros are
Packit Service 82fcde
defined.  These new functions and macros have the same names as the
Packit Service 82fcde
library functions and so are used instead of the latter.  In the case of
Packit Service 82fcde
inline functions the compiler will decide whether it is reasonable to
Packit Service 82fcde
use them, and this decision is usually correct.
Packit Service 82fcde
Packit Service 82fcde
This means that no calls to the library functions may be necessary, and
Packit Service 82fcde
can increase the speed of generated code significantly.  The drawback is
Packit Service 82fcde
that code size will increase, and the increase is not always negligible.
Packit Service 82fcde
Packit Service 82fcde
There are two kinds of inline functions: those that give the same result
Packit Service 82fcde
as the library functions and others that might not set @code{errno} and
Packit Service 82fcde
might have a reduced precision and/or argument range in comparison with
Packit Service 82fcde
the library functions.  The latter inline functions are only available
Packit Service 82fcde
if the flag @code{-ffast-math} is given to GNU CC.
Packit Service 82fcde
Packit Service 82fcde
In cases where the inline functions and macros are not wanted the symbol
Packit Service 82fcde
@code{__NO_MATH_INLINES} should be defined before any system header is
Packit Service 82fcde
included.  This will ensure that only library functions are used.  Of
Packit Service 82fcde
course, it can be determined for each file in the project whether
Packit Service 82fcde
giving this option is preferable or not.
Packit Service 82fcde
Packit Service 82fcde
Not all hardware implements the entire @w{IEEE 754} standard, and even
Packit Service 82fcde
if it does there may be a substantial performance penalty for using some
Packit Service 82fcde
of its features.  For example, enabling traps on some processors forces
Packit Service 82fcde
the FPU to run un-pipelined, which can more than double calculation time.
Packit Service 82fcde
@c ***Add explanation of -lieee, -mieee.