xref: /netbsd-src/share/man/man3lua/libm.3lua (revision ae082add65442546470c0ba499a860ee89eed305)
1.\"
2.\" Copyright (c) 2022 The NetBSD Foundation, Inc.
3.\" All rights reserved.
4.\"
5.\" This code is derived from software contributed to The NetBSD Foundation
6.\" by Phillip Rulon
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27.\" POSSIBILITY OF SUCH DAMAGE.
28.\"
29.Dd November 2, 2022
30.Dt LIBM 3lua
31.Os
32.Sh NAME
33.Nm libm
34.Nd Lua interface to the
35.Xr math 3
36library
37.Sh SYNOPSIS
38.Cd "local lm = require 'libm'"
39.Sh DESCRIPTION
40The
41.Nm
42Lua binding provides access to the
43.Xr math 3
44library.  If these functions are given an argument outside the domain
45of the function the return value will be NaN.  This can be checked with
46lm.isnan().
47.Pp
48Many of these functions have native equivalents in the Lua math library.
49Others, like
50.Xr round 3 ,
51.Xr cbrt 3 ,
52and the hyperbolic trigonometry functions, are not provided without an
53auxiliary module.  The functions that are redundant are provided for
54completeness.
55.Pp
56Since these functions map quite closely to the functions in the math
57library, detailed information about their behavior can be found in the
58man pages for each function in section 3 of the manual.
59.Ss List of Functions
60.Bl -column "copysignX" "gammaX3XX" "inverse trigonometric funcX"
61.It Sy Name Ta Sy Man page Ta Sy Description Ta
62.It lm.acos Ta Xr acos 3 Ta inverse trigonometric function Ta
63.It lm.acosh Ta Xr acosh 3 Ta inverse hyperbolic function Ta
64.It lm.asin Ta Xr asin 3 Ta inverse trigonometric function Ta
65.It lm.asinh Ta Xr asinh 3 Ta inverse hyperbolic function Ta
66.It lm.atan Ta Xr atan 3 Ta inverse trigonometric function Ta
67.It lm.atanh Ta Xr atanh 3 Ta inverse hyperbolic function Ta
68.It lm.atan2 Ta Xr atan2 3 Ta inverse trigonometric function Ta
69.It lm.cbrt Ta Xr sqrt 3 Ta cube root Ta
70.It lm.ceil Ta Xr ceil 3 Ta integer no less than Ta
71.It lm.copysign Ta Xr copysign 3 Ta copy sign bit Ta
72.It lm.cos Ta Xr cos 3 Ta trigonometric function Ta
73.It lm.cosh Ta Xr cosh 3 Ta hyperbolic function Ta
74.It lm.erf Ta Xr erf 3 Ta error function Ta
75.It lm.erfc Ta Xr erf 3 Ta complementary error function Ta
76.It lm.exp Ta Xr exp 3 Ta base e exponential Ta
77.It lm.exp2 Ta Xr exp2 3 Ta base 2 exponential Ta
78.It lm.expm1 Ta Xr expm1 3 Ta exp(x)\-1 Ta
79.It lm.fabs Ta Xr fabs 3 Ta absolute value Ta
80.It lm.fdim Ta Xr erf 3 Ta positive difference Ta
81.It lm.finite Ta Xr finite 3 Ta test for finity Ta
82.It lm.floor Ta Xr floor 3 Ta integer no greater than Ta
83.It lm.fma Ta Xr fmod 3 Ta fused multiply-add Ta
84.It lm.fmax Ta Xr fmax 3 Ta maximum Ta
85.It lm.fmin Ta Xr fmin 3 Ta minimum Ta
86.It lm.fmod Ta Xr fmod 3 Ta remainder Ta
87.It lm.hypot Ta Xr hypot 3 Ta Euclidean distance Ta
88.It lm.ilogb Ta Xr ilogb 3 Ta exponent extraction Ta
89.It lm.isinf Ta Xr isinf 3 Ta test for infinity Ta
90.It lm.isnan Ta Xr isnan 3 Ta test for not-a-number Ta
91.It lm.j0 Ta Xr j0 3 Ta Bessel function Ta
92.It lm.j1 Ta Xr j0 3 Ta Bessel function Ta
93.It lm.jn Ta Xr j0 3 Ta Bessel function Ta
94.It lm.lgamma Ta Xr lgamma 3 Ta log gamma function Ta
95.It lm.log Ta Xr log 3 Ta natural logarithm Ta
96.It lm.log10 Ta Xr log 3 Ta logarithm to base 10 Ta
97.It lm.log1p Ta Xr log 3 Ta log(1+x) Ta
98.It lm.nan Ta Xr nan 3 Ta return quiet \*(Na Ta
99.It lm.nextafter Ta Xr nextafter 3 Ta next representable number Ta
100.It lm.pow Ta Xr pow 3 Ta exponential x**y Ta
101.It lm.remainder Ta Xr remainder 3 Ta remainder Ta
102.It lm.rint Ta Xr rint 3 Ta round to nearest integer Ta
103.It lm.scalbn Ta Xr scalbn 3 Ta exponent adjustment Ta
104.It lm.sin Ta Xr sin 3 Ta trigonometric function Ta
105.It lm.sinh Ta Xr sinh 3 Ta hyperbolic function Ta
106.It lm.sqrt Ta Xr sqrt 3 Ta square root Ta
107.It lm.tan Ta Xr tan 3 Ta trigonometric function Ta
108.It lm.tanh Ta Xr tanh 3 Ta hyperbolic function Ta
109.It lm.trunc Ta Xr trunc 3 Ta nearest integral value Ta
110.It lm.y0 Ta Xr j0 3 Ta Bessel function Ta
111.It lm.y1 Ta Xr j0 3 Ta Bessel function Ta
112.It lm.yn Ta Xr j0 3 Ta Bessel function Ta
113.El
114.Ss List of Defined Values
115.Bl -column "M_2_SQRTPIXX" "1.12837916709551257390XX" "2/sqrt(pi)XXX"
116.It Sy Name Ta Sy Value Ta Sy Description
117.It lm.M_E	2.7182818284590452354	e
118.It lm.M_LOG2E	1.4426950408889634074	log 2e
119.It lm.M_LOG10E	0.43429448190325182765	log 10e
120.It lm.M_LN2	0.69314718055994530942	log e2
121.It lm.M_LN10	2.30258509299404568402	log e10
122.It lm.M_PI	3.14159265358979323846	pi
123.It lm.M_PI_2	1.57079632679489661923	pi/2
124.It lm.M_PI_4	0.78539816339744830962	pi/4
125.It lm.M_1_PI	0.31830988618379067154	1/pi
126.It lm.M_2_PI	0.63661977236758134308	2/pi
127.It lm.M_2_SQRTPI	1.12837916709551257390	2/sqrt(pi)
128.It lm.M_SQRT2	1.41421356237309504880	sqrt(2)
129.It lm.M_SQRT1_2	0.70710678118654752440	1/sqrt(2)
130.El
131.Sh NOTES
132The functions finite, isfinite, isinf, and isnan return integers in
133the math library, the results are converted to lua boolean values by
134this interface.
135.Sh BUGS
136The single precision float, and long double data types, implemented in
137several of the libm routines, are not supported by this interface.
138.Pp
139The math library has a long development history, but if a bug exists
140there, it will certainly exist in this interface as well.
141.Sh HISTORY
142A
143.Nm
144Lua binding appeared in
145.Nx 9.4 .
146.Sh AUTHORS
147.An -nosplit
148The
149.Nm
150Lua binding was written by
151.An Phillip Rulon .
152