1994-08-19 09:40:01 +00:00
|
|
|
.\" Copyright (c) 1985 Regents of the University of California.
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the University of
|
|
|
|
.\" California, Berkeley and its contributors.
|
|
|
|
.\" 4. Neither the name of the University nor the names of its contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" from: @(#)math.3 6.10 (Berkeley) 5/6/91
|
1999-08-28 00:22:10 +00:00
|
|
|
.\" $FreeBSD$
|
1994-08-19 09:40:01 +00:00
|
|
|
.\"
|
2005-04-05 02:57:28 +00:00
|
|
|
.Dd April 5, 2005
|
2004-06-19 03:25:28 +00:00
|
|
|
.Dt MATH 3
|
|
|
|
.Os
|
2005-01-11 20:16:03 +00:00
|
|
|
.if n \{\
|
|
|
|
.char \[sr] "sqrt
|
|
|
|
.\}
|
2004-06-19 03:25:28 +00:00
|
|
|
.Sh NAME
|
2005-01-11 20:16:03 +00:00
|
|
|
.Nm math
|
|
|
|
.Nd "floating-point mathematical library"
|
2004-10-11 20:13:52 +00:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libm
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.In math.h
|
2004-06-19 03:25:28 +00:00
|
|
|
.Sh DESCRIPTION
|
2004-10-11 20:13:52 +00:00
|
|
|
These functions constitute the C math library.
|
2004-06-19 03:25:28 +00:00
|
|
|
.Sh "LIST OF FUNCTIONS"
|
|
|
|
Each of the following
|
|
|
|
.Vt double
|
|
|
|
functions has a
|
|
|
|
.Vt float
|
|
|
|
counterpart with an
|
|
|
|
.Ql f
|
|
|
|
appended to the name and a
|
2005-01-11 20:16:03 +00:00
|
|
|
.Vt "long double"
|
2004-06-19 03:25:28 +00:00
|
|
|
counterpart with an
|
|
|
|
.Ql l
|
|
|
|
appended.
|
|
|
|
As an example, the
|
|
|
|
.Vt float
|
|
|
|
and
|
2005-01-11 20:16:03 +00:00
|
|
|
.Vt "long double"
|
2004-06-19 03:25:28 +00:00
|
|
|
counterparts of
|
|
|
|
.Ft double
|
|
|
|
.Fn acos "double x"
|
|
|
|
are
|
|
|
|
.Ft float
|
|
|
|
.Fn acosf "float x"
|
|
|
|
and
|
2005-01-11 20:16:03 +00:00
|
|
|
.Ft "long double"
|
2004-06-19 03:25:28 +00:00
|
|
|
.Fn acosl "long double x" ,
|
|
|
|
respectively.
|
2005-01-23 22:05:33 +00:00
|
|
|
.de Cl
|
2005-06-16 21:56:03 +00:00
|
|
|
.Bl -column "isgreaterequal" "bessel function of the second kind of the order 0"
|
2005-01-23 22:05:33 +00:00
|
|
|
.Em "Name Description"
|
|
|
|
..
|
|
|
|
.Ss Algebraic Functions
|
|
|
|
.Cl
|
|
|
|
cbrt cube root
|
|
|
|
fma fused multiply-add
|
|
|
|
hypot Euclidean distance
|
|
|
|
sqrt square root
|
|
|
|
.El
|
|
|
|
.Ss Classification Functions
|
|
|
|
.Cl
|
|
|
|
fpclassify classify a floating-point value
|
|
|
|
isfinite determine whether a value is finite
|
|
|
|
isinf determine whether a value is infinite
|
|
|
|
isnan determine whether a value is \*(Na
|
|
|
|
isnormal determine whether a value is normalized
|
|
|
|
.El
|
|
|
|
.Ss Exponent Manipulation Functions
|
|
|
|
.Cl
|
|
|
|
frexp extract exponent and mantissa
|
|
|
|
ilogb extract exponent
|
|
|
|
ldexp multiply by power of 2
|
|
|
|
scalbln adjust exponent
|
|
|
|
scalbn adjust exponent
|
|
|
|
.El
|
|
|
|
.Ss Extremum- and Sign-Related Functions
|
|
|
|
.Cl
|
|
|
|
copysign copy sign bit
|
|
|
|
fabs absolute value
|
|
|
|
fdim positive difference
|
|
|
|
fmax maximum function
|
|
|
|
fmin minimum function
|
|
|
|
signbit extract sign bit
|
|
|
|
.El
|
|
|
|
.\" .Ss Not a Number
|
|
|
|
.\" .Cl
|
2004-06-19 03:25:28 +00:00
|
|
|
.\" nan return quiet \*(Na) 0
|
2005-01-23 22:05:33 +00:00
|
|
|
.\" .El
|
|
|
|
.Ss Residue and Rounding Functions
|
|
|
|
.Cl
|
|
|
|
ceil integer no less than
|
|
|
|
floor integer no greater than
|
|
|
|
fmod positive remainder
|
|
|
|
llrint round to integer in fixed-point format
|
|
|
|
llround round to nearest integer in fixed-point format
|
|
|
|
lrint round to integer in fixed-point format
|
|
|
|
lround round to nearest integer in fixed-point format
|
|
|
|
modf extract integer and fractional parts
|
|
|
|
nearbyint round to integer (silent)
|
|
|
|
nextafter next representable value
|
2005-03-07 04:59:53 +00:00
|
|
|
nexttoward next representable value
|
2005-01-23 22:05:33 +00:00
|
|
|
remainder remainder
|
2005-03-25 04:40:44 +00:00
|
|
|
remquo remainder with partial quotient
|
2005-01-23 22:05:33 +00:00
|
|
|
rint round to integer
|
|
|
|
round round to nearest integer
|
|
|
|
trunc integer no greater in magnitude than
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn ceil ,
|
|
|
|
.Fn floor ,
|
|
|
|
.Fn llround ,
|
|
|
|
.Fn lround ,
|
|
|
|
.Fn round ,
|
|
|
|
and
|
|
|
|
.Fn trunc
|
|
|
|
functions round in predetermined directions, whereas
|
|
|
|
.Fn llrint ,
|
|
|
|
.Fn lrint ,
|
|
|
|
and
|
|
|
|
.Fn rint
|
|
|
|
round according to the current (dynamic) rounding mode.
|
|
|
|
For more information on controlling the dynamic rounding mode, see
|
|
|
|
.Xr fenv 3
|
|
|
|
and
|
|
|
|
.Xr fesetround 3 .
|
|
|
|
.Ss Silent Order Predicates
|
|
|
|
.Cl
|
|
|
|
isgreater greater than relation
|
|
|
|
isgreaterequal greater than or equal to relation
|
|
|
|
isless less than relation
|
|
|
|
islessequal less than or equal to relation
|
|
|
|
islessgreater less than or greater than relation
|
|
|
|
isunordered unordered relation
|
2005-01-11 20:16:03 +00:00
|
|
|
.El
|
2005-01-23 22:05:33 +00:00
|
|
|
.Ss Transcendental Functions
|
|
|
|
.Cl
|
|
|
|
acos inverse cosine
|
|
|
|
acosh inverse hyperbolic cosine
|
|
|
|
asin inverse sine
|
|
|
|
asinh inverse hyperbolic sine
|
|
|
|
atan inverse tangent
|
|
|
|
atanh inverse hyperbolic tangent
|
|
|
|
atan2 atan(y/x); complex argument
|
|
|
|
cos cosine
|
|
|
|
cosh hyperbolic cosine
|
|
|
|
erf error function
|
|
|
|
erfc complementary error function
|
|
|
|
exp exponential base e
|
2005-04-05 02:57:28 +00:00
|
|
|
exp2 exponential base 2
|
2005-01-23 22:05:33 +00:00
|
|
|
expm1 exp(x)\-1
|
|
|
|
j0 Bessel function of the first kind of the order 0
|
|
|
|
j1 Bessel function of the first kind of the order 1
|
|
|
|
jn Bessel function of the first kind of the order n
|
|
|
|
lgamma log gamma function
|
|
|
|
log natural logarithm
|
|
|
|
log10 logarithm to base 10
|
|
|
|
log1p log(1+x)
|
|
|
|
.\" log2 base 2 logarithm
|
|
|
|
pow exponential x**y
|
|
|
|
sin trigonometric function
|
|
|
|
sinh hyperbolic function
|
|
|
|
tan trigonometric function
|
|
|
|
tanh hyperbolic function
|
|
|
|
tgamma gamma function
|
|
|
|
y0 Bessel function of the second kind of the order 0
|
|
|
|
y1 Bessel function of the second kind of the order 1
|
|
|
|
yn Bessel function of the second kind of the order n
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
Unlike the algebraic functions listed earlier, the routines
|
2005-04-05 02:57:28 +00:00
|
|
|
in this section may not produce a result that is correctly rounded,
|
|
|
|
so reproducible results cannot be guaranteed across platforms.
|
|
|
|
For most of these functions, however, incorrect rounding occurs
|
|
|
|
rarely, and then only in very-close-to-halfway cases.
|
2004-06-19 03:25:28 +00:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr fenv 3 ,
|
|
|
|
.Xr ieee 3
|
|
|
|
.Sh HISTORY
|
|
|
|
A math library with many of the present functions appeared in
|
2005-01-11 20:16:03 +00:00
|
|
|
.At v7 .
|
|
|
|
The library was substantially rewritten for
|
|
|
|
.Bx 4.3
|
|
|
|
to provide
|
2004-06-19 03:25:28 +00:00
|
|
|
better accuracy and speed on machines supporting either VAX
|
|
|
|
or IEEE 754 floating-point.
|
|
|
|
Most of this library was replaced with FDLIBM, developed at Sun
|
|
|
|
Microsystems, in
|
|
|
|
.Fx 1.1.5 .
|
2005-01-23 22:05:33 +00:00
|
|
|
Additional routines, including ones for
|
|
|
|
.Vt float
|
|
|
|
and
|
|
|
|
.Vt long double
|
|
|
|
values, were written for or imported into subsequent versions of FreeBSD.
|
2005-01-20 09:17:07 +00:00
|
|
|
.Sh BUGS
|
2005-03-07 04:59:53 +00:00
|
|
|
The
|
2005-04-05 02:57:28 +00:00
|
|
|
.Fn log2
|
2005-03-07 04:59:53 +00:00
|
|
|
and
|
2005-03-25 04:40:44 +00:00
|
|
|
.Fn nan
|
2005-03-07 04:59:53 +00:00
|
|
|
functions are missing, and many functions are not available in their
|
2005-01-20 09:17:07 +00:00
|
|
|
.Vt "long double"
|
|
|
|
variants.
|
|
|
|
.Pp
|
2005-04-05 02:57:28 +00:00
|
|
|
Many of the routines to compute transcendental functions produce
|
|
|
|
inaccurate results in other than the default rounding mode.
|
|
|
|
.Pp
|
2005-01-20 09:17:07 +00:00
|
|
|
On some architectures, trigonometric argument reduction is not
|
|
|
|
performed accurately, resulting in errors greater than 1
|
|
|
|
.Em ulp
|
|
|
|
for large arguments to
|
|
|
|
.Fn cos ,
|
|
|
|
.Fn sin ,
|
|
|
|
and
|
|
|
|
.Fn tan .
|