1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
---@meta
-- Copyright (c) 2018. tangzx(love.tangzx@qq.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License"); you may not
-- use this file except in compliance with the License. You may obtain a copy of
-- the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-- License for the specific language governing permissions and limitations under
-- the License.
---@class mathlib
math =
---
--- Returns the maximum value between `x` and `-x`. (integer/float)
---@overload fun(x:integer):integer
---@param x number
---@return number
---
--- Returns the arc cosine of `x` (in radians).
---@param x number
---@return number
---
--- Returns the arc sine of `x` (in radians).
---@param x number
---@return number
---
--- Returns the arc tangent of `y/x` (in radians), but uses the signs of both
--- parameters to find the quadrant of the result. (It also handles correctly
--- the case of `x` being zero.)
---
--- The default value for `x` is 1, so that the call `math.atan(y)`` returns the
--- arc tangent of `y`.
---@param y number
---@param x? number
---@return number
---
--- Returns the smallest integer larger than or equal to `x`.
---@param x number
---@return integer
---
--- Returns the cosine of `x` (assumed to be in radians).
---@param x number
---@return number
---
--- Converts the angle `x` from radians to degrees.
---@param x number
---@return number
---
--- Returns the value *e^x* (where e is the base of natural logarithms).
---@param x number
---@return number
---
--- Returns the largest integer smaller than or equal to `x`.
---@param x number
---@return integer
---
--- Returns the remainder of the division of `x` by `y` that rounds the
--- quotient towards zero. (integer/float)
---@param x number
---@param y number
---@return number
---
--- The float value `HUGE_VAL`, a value larger than any other numeric value.
--- it is INF value, more than math.maxinteger.
---@type number
math. = nil
---
--- Returns the logarithm of `x` in the given base. The default for `base` is
--- *e* (so that the function returns the natural logarithm of `x`).
---@param x number
---@param base? number
---@return number
---
--- Returns the argument with the maximum value, according to the Lua operator
--- `<`. (integer/float)
---@overload fun(x:integer, ...:integer):integer
---@param x number
---@param ... number
---@return number
---@version >5.3
---
--- An integer with the maximum value for an integer.
---@type integer
math. = nil
---
--- Returns the argument with the minimum value, according to the Lua operator
--- `<`. (integer/float)
---@overload fun(x:integer, ...:integer):integer
---@param x number
---@param ... number
---@return number
---@version >5.3
---
--- An integer with the minimum value for an integer.
---@type integer
math. = nil
---
--- Returns the integral part of `x` and the fractional part of `x`. Its second
--- result is always a float.
---@param x number
---@return integer
---@return number
---
--- The value of π.
math. = 3.1415
---
--- Converts the angle `x` from degrees to radians.
---@param x number
---@return number
---
--- When called without arguments, returns a pseudo-random float with uniform
--- distribution in the range *[0,1)*. When called with two integers `m` and
--- `n`, `math.random` returns a pseudo-random integer with uniform distribution
--- in the range *[m, n]*. The call `math.random(n)` is equivalent to `math
--- .random`(1,n).
---@overload fun():number
---@overload fun(m:integer):integer
---@param m integer
---@param n integer
---@return integer
---@version 5.1, 5.2, 5.3
---
--- Sets `x` as the "seed" for the pseudo-random generator: equal seeds
--- produce equal sequences of numbers.
---@param x integer
---@version > 5.4
---
--- When called with at least one argument, the integer parameters `x` and `y`
--- are joined into a 128-bit seed that is used to reinitialize the pseudo-random
--- generator; equal seeds produce equal sequences of numbers. The default for
--- `y` is zero.
---
--- When called with no arguments, Lua generates a seed with a weak attempt
--- for randomness.
---
--- This function returns the two seed components that were effectively used,
--- so that setting them again repeats the sequence.
---@param x? integer
---@param y? integer
---@return integer, integer
---
--- Returns the sine of `x` (assumed to be in radians).
---@param x number
---@return number
---
--- Returns the square root of `x`. (You can also use the expression `x^0.5` to
--- compute this value.)
---@param x number
---@return number
---
--- Returns the tangent of `x` (assumed to be in radians).
---@param x number
---@return number
---@version >5.3
---
--- If the value `x` is convertible to an integer, returns that integer.
--- Otherwise, returns `nil`.
---@param x any
---@return integer?
---@version >5.3
---
--- Returns "`integer`" if `x` is an integer, "`float`" if it is a float, or
--- **nil** if `x` is not a number.
---@param x any
---@return 'integer'|'float'|nil
---@version >5.3
---
--- Returns a boolean, true if and only if integer `m` is below integer `n` when
--- they are compared as unsigned integers.
---@param m number
---@param n number
---@return boolean
---@version 5.1, 5.2, JIT
---
--- Returns the value of `x` raised to the power `y`. (x^y)
---@param x number The base
---@param y number The exponent
---@return number
---@version 5.1, 5.2, JIT
---
--- Returns the arc tangent of `y/x` (in radians), but uses the signs of both
--- parameters to find the quadrant of the result. (It also handles correctly
--- the case of `x` being zero.)
---
--- Note: In some Lua implementations, this function is equivalent to `math.atan(y, x)`.
---@param y number
---@param x number
---@return number
---@version 5.1, JIT
---
--- Returns the base-10 logarithm of `x`.
---@param x number
---@return number
---@version 5.1, 5.2, JIT
---
--- Returns the hyperbolic cosine of `x`.
---@param x number
---@return number
---@version 5.1, 5.2, JIT
---
--- Returns the hyperbolic sine of `x`.
---@param x number
---@return number
---@version 5.1, 5.2, JIT
---
--- Returns the hyperbolic tangent of `x`.
---@param x number
---@return number
---@version 5.1, 5.2, JIT
---
--- Returns `m` and `e` such that *x = m2^e*, `e` is an integer and the absolute
--- value of `m` is in the range *[0.5, 1)* (or zero when `x` is zero).
---@param x number
---@return number, integer
---@version 5.1, 5.2, JIT
---
--- Returns *m2e* (`e` should be an integer).
---@param m number
---@param e integer
---@return number
return math