this repo has no description
1.\" Copyright (c) 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" from: @(#)acos.3 5.1 (Berkeley) 5/2/91
33.\" $Id: math.3,v 1.2 2003/08/17 20:36:47 scp Exp $
34.\"
35.Dd June 11, 2008
36.Dt MATH 3
37.Os
38.Sh NAME
39.Nm math
40.Nd mathematical library functions
41.Sh SYNOPSIS
42.Fd #include <math.h>
43.Sh DESCRIPTION
44The header file math.h provides function prototypes and macros for working with
45C99 floating point values.
46.Pp
47Each math.h function is provided in three variants: single, double and extended precision.
48The single and double precision variants operate on IEEE-754 single and double precision
49values, which correspond to the C types
50.Ft float
51and
52.Ft double ,
53respectively.
54.Pp
55On Intel Macs, the C type
56.Ft long double
57corresponds to 80-bit IEEE-754 double extended precision. On PowerPC Macs, the C type
58.Ft long double
59corresponds by default to ordinary double precision, but a 128-bit non-IEEE-754 long double
60type is also available via the compiler flag
61.Ft -mlong-double-128
62and linker flag
63.Ft -lmx .
64.Pp
65Details of the floating point formats can be found via "man float".
66.Pp
67Users who need to repeatedly perform the same calculation on a large set of data will
68probably find that the vector math library (composed of vMathLib and vForce) yields
69better performance for their needs than sequential calls to the libm.
70.Pp
71Users who need to perform mathematical operations on complex floating-point numbers should
72consult the man pages for the complex portion of the math library, via "man complex".
73.Sh LIST OF FUNCTIONS
74Each of the functions that use floating-point values are provided in single, double,
75and extended precision; the double precision prototypes are listed here. The man
76pages for the individual functions provide more details on their use, special cases, and
77prototypes for their single and extended precision versions.
78.Pp
79.Ft int
80.Fn fpclassify "double"
81.br
82.Ft int
83.Fn isfinite "double"
84.br
85.Ft int
86.Fn isinf "double"
87.br
88.Ft int
89.Fn isnan "double"
90.br
91.Ft int
92.Fn isnormal "double"
93.br
94.Ft int
95.Fn signbit "double"
96.Pp
97These function-like macros are used to classify a single floating-point argument.
98.Pp
99.Ft double
100.Fn copysign "double, double"
101.br
102.Ft double
103.Fn nextafter "double, double"
104.Pp
105.Fn copysign "x, y"
106returns the value equal in magnitude to
107.Fa x
108with the sign of
109.Fa y .
110.Fn nextafter "x, y"
111returns the next floating-point number after
112.Fa x
113in the direction of
114.Fa y .
115Both are correctly-rounded.
116.Pp
117.Ft double
118.Fn nan "const char *tag"
119.Pp
120The
121.Fn nan
122function returns a quiet NaN, without raising the invalid flag.
123.Pp
124.Ft double
125.Fn ceil "double"
126.br
127.Ft double
128.Fn floor "double"
129.br
130.Ft double
131.Fn nearbyint "double"
132.br
133.Ft double
134.Fn rint "double"
135.br
136.Ft double
137.Fn round "double"
138.br
139.Ft long int
140.Fn lrint "double"
141.br
142.Ft long int
143.Fn lround "double"
144.br
145.Ft long long int
146.Fn llrint "double"
147.br
148.Ft long long int
149.Fn llround "double"
150.br
151.Ft double
152.Fn trunc "double"
153.Pp
154These functions provide various means to round floating-point values to integral values. They are correctly rounded.
155.Pp
156.Ft double
157.Fn fmod "double, double"
158.br
159.Ft double
160.Fn remainder "double, double"
161.br
162.Ft double
163.Fn remquo "double x, double y, int *"
164.Pp
165These return a remainder of the division of x by y with an integral quotient.
166.Fn remquo
167additionally provides access to a few lower bits of the quotient. They are correctly rounded.
168.Pp
169.Ft double
170.Fn fdim "double, double"
171.br
172.Ft double
173.Fn fmax "double, double"
174.br
175.Ft double
176.Fn fmin "double, double"
177.Pp
178.Fn fmax "x, y"
179and
180.Fn fmin "x, y"
181return the maximum and minimum of
182.Fa x
183and
184.Fa y ,
185respectively.
186.Fn fdim "x, y"
187returns the positive difference of
188.Fa x
189and
190.Fa y . All are correctly rounded.
191.Pp
192.Ft double
193.Fn fma "double x, double y, double z"
194.Pp
195.Fn fma "x, y, z"
196computes the value (x*y) + z as though without intermediate rounding. It is correctly rounded.
197.Pp
198.Ft double
199.Fn fabs "double"
200.br
201.Ft double
202.Fn sqrt "double"
203.br
204.Ft double
205.Fn cbrt "double"
206.br
207.Ft double
208.Fn hypot "double, double"
209.Pp
210.Fn fabs "x",
211.Fn sqrt "x",
212and
213.Fn cbrt "x"
214return the absolute value, square root, and cube root of
215.Fa x ,
216respectively.
217.Fn hypot "x, y"
218returns sqrt(x*x + y*y).
219.Fn fabs
220and
221.Fn sqrt
222are correctly rounded.
223.Pp
224.Ft double
225.Fn exp "double"
226.br
227.Ft double
228.Fn exp2 "double"
229.br
230.Ft double
231.Fn expm1 "double"
232.Pp
233.Fn exp "x" ,
234.Fn exp2 "x" ,
235and
236.Fn expm1 "x"
237return e**x, 2**x, and e**x - 1, respectively.
238.Pp
239.Ft double
240.Fn log "double"
241.br
242.Ft double
243.Fn log2 "double"
244.br
245.Ft double
246.Fn log10 "double"
247.br
248.Ft double
249.Fn log1p "double"
250.Pp
251.Fn log "x" ,
252.Fn log2 "x" ,
253and
254.Fn log10 "x"
255return the natural, base-2, and base-10 logarithms of
256.Fa x ,
257respectively.
258.Fn log1p "x"
259returns the natural log of 1+x.
260.Pp
261.Ft double
262.Fn logb "double"
263.br
264.Ft int
265.Fn ilogb "double"
266.Pp
267.Fn logb "x"
268and
269.Fn ilogb "x"
270return the exponent of
271.Fa x .
272.Pp
273.Ft double
274.Fn modf "double, double *"
275.br
276.Ft double
277.Fn frexp "double, int *"
278.Pp
279.Fn modf "x, &y"
280returns the fractional part of
281.Fa x
282and stores the integral part in
283.Fa y .
284.Fn frexp "x, &n"
285returns the mantissa of
286.Fa x
287and stores the exponent in
288.Fa n . They are correctly rounded.
289.Pp
290.Ft double
291.Fn ldexp "double, int"
292.br
293.Ft double
294.Fn scalbn "double, int"
295.br
296.Ft double
297.Fn scalbln "double, long int"
298.Pp
299.Fn ldexp "x, n" ,
300.Fn scalbn "x, n" ,
301and
302.Fn scalbln "x, n"
303return x*2**n. They are correctly rounded.
304.Pp
305.Ft double
306.Fn pow "double, double"
307.Pp
308.Fn pow "x,y"
309returns x raised to the power y.
310.Pp
311.Ft double
312.Fn cos "double"
313.br
314.Ft double
315.Fn sin "double"
316.br
317.Ft double
318.Fn tan "double"
319.Pp
320.Fn cos "x" ,
321.Fn sin "x" ,
322and
323.Fn tan "x"
324return the cosine, sine and tangent of
325.Fa x ,
326respectively.
327.Pp
328.Ft double
329.Fn cosh "double"
330.br
331.Ft double
332.Fn sinh "double"
333.br
334.Ft double
335.Fn tanh "double"
336.Pp
337.Fn cosh "x" ,
338.Fn sinh "x" ,
339and
340.Fn tanh "x"
341return the hyperbolic cosine, hyperbolic sine and hyperbolic tangent of
342.Fa x ,
343respectively.
344.Pp
345.Ft double
346.Fn acos "double"
347.br
348.Ft double
349.Fn asin "double"
350.br
351.Ft double
352.Fn atan "double"
353.br
354.Ft double
355.Fn atan2 "double, double"
356.Pp
357.Fn acos "x" ,
358.Fn asin "x" ,
359and
360.Fn atan "x"
361return the inverse cosine, inverse sine and inverse tangent of
362.Fa x ,
363respectively.
364.Fn atan2 "y, x"
365returns the inverse tangent of y/x, with sign chosen according to the quadrant of (x,y).
366.Pp
367.Ft double
368.Fn acosh "double"
369.br
370.Ft double
371.Fn asinh "double"
372.br
373.Ft double
374.Fn atanh "double"
375.Pp
376.Fn acosh "x" ,
377.Fn asinh "x" ,
378and
379.Fn atanh "x"
380return the inverse hyperbolic cosine, inverse hyperbolic sine and inverse hyperbolic tangent of
381.Fa x ,
382respectively.
383.Pp
384.Ft double
385.Fn tgamma "double"
386.br
387.Ft double
388.Fn lgamma "double"
389.Pp
390.Fn tgamma "x"
391and
392.Fn lgamma "x"
393return the values of the gamma function and its logarithm evalutated at
394.Fa x ,
395respectively.
396.Pp
397.Ft double
398.Fn j0 "double"
399.br
400.Ft double
401.Fn j1 "double"
402.br
403.Ft double
404.Fn jn "int" "double"
405.br
406.Ft double
407.Fn y0 "double"
408.br
409.Ft double
410.Fn y1 "double"
411.br
412.Ft double
413.Fn yn "int" "double"
414.Pp
415.Fn j0 "x" ,
416.Fn j1 "x" ,
417and
418.Fn jn "x"
419return the values of the zeroth, first, and nth Bessel function of the first kind evaluated at
420.Fa x ,
421respectively.
422.Fn y0 "x" ,
423.Fn y1 "x" ,
424and
425.Fn yn "x"
426return the values of the zeroth, first, and nth Bessel function of the second kind evaluated at
427.Fa x ,
428respectively.
429.Pp
430.Ft double
431.Fn erf "double"
432.br
433.Ft double
434.Fn erfc "double"
435.Pp
436.Fn erf "x"
437and
438.Fn erfc "x"
439return the values of the error function and the complementary error function evaluated at
440.Fa x ,
441respectively.
442.Sh MATHEMATICAL CONSTANTS
443In addition to the functions listed above, math.h defines a number of useful constants,
444listed below. All are defined as C99 floating-point constants.
445.nf
446.ta \w'M_2_SQRTPI'u+6
447.sp 1
448CONSTANT VALUE
449M_E base of natural logarithm, e
450M_LOG2E log2(e)
451M_LOG10E log10(e)
452M_LN2 ln(2)
453M_LN10 ln(10)
454M_PI pi
455M_PI_2 pi / 2
456M_PI_4 pi / 4
457M_1_PI 1 / pi
458M_2_PI 2 / pi
459M_2_SQRTPI 2 / sqrt(pi)
460M_SQRT2 sqrt(2)
461M_SQRT1_2 sqrt(1/2)
462.ta
463.fi
464.Sh IEEE STANDARD 754 FLOATING\-POINT ARITHMETIC
465The libm functions declared in math.h provide mathematical library functions in
466single-, double-, and extended-precision IEEE-754 floating-point formats on Intel macs,
467and in single- and double-precision IEEE-754 floating-point formats on PowerPC macs.
468.Sh SEE ALSO
469.Xr float 3 ,
470.Xr complex 3
471.Sh STANDARDS
472The <math.h> functions conform to the ISO/IEC 9899:1999(E) standard.