Prev: Module bigint: Arbitrarily Large Integers
Module math: Mathematical Functions
This module provides standard mathematical functions.
math.abs
• function abs(x) → Number
Returns the absolute value of x.
math.acos
• function acos(x) → Number
Returns the arcus cosine (in radians) of x.
Throws ErrArgument if abs(x) > 1.
math.asin
• function asin(x) → Number
Returns the arcus sine (in radians) of x.
Throws ErrArgument if abs(x) > 1.
math.atan
• function atan(x) → Number
Returns the arcus tangent (in radians) of x.
math.ceil
• function ceil(x) → Number
Returns the smallest integer greater than or equal to x.
print math.ceil(3)
→ 3
print math.ceil(3.4)
→ 4
print math.ceil(-3.4)
→ -3
|
math.cos
• function cos(x) → Number
Returns the cosine of x (in radians).
math.exp
• function exp(x) → Number
Returns ex
math.floor
• function floor(x) → Number
Returns the largest integer less than or equal to x.
print math.floor(3)
→ 3
print math.floor(3.4)
→ 3
print math.floor(-3.4)
→ -4
|
math.isinf
• function isinf(x) → Boolean
Returns true if x is (positive or negative) infinity, false otherwise.
math.isnan
• function isnan(x) → Boolean
Returns true if x is not-a-number, false otherwise.
math.log
• function log(x) → Number
Returns the natural logarithm of x.
math.pow
• function pow(x, y) → Number
Returns xy.
Throws ErrArgument if x < 0 and y is not an integer.
Throws ErrOverflow if x = 0 and y < 0.
print math.pow(2, 0.5)
→ 1.4142135624
print math.pow(-5, 3);
→ -125
|
math.random
• function random() → Number
• function random(seed) → Number
Returns a random number uniformely distributed in the interval 0 (inclusive) to 1 (exclusive). With an argument, initializes the sequence of random numbers with seed. seed can be any number.
The default initialization is based on the current time.
math.random(0);
for i=1 to 3 do
print math.random()
end
→ 0.0038488093
0.6952766137
0.2338878537
|
math.round
• function round(x, decimals=0) → Number
Rounds x to decimals decimal digits.
print math.round(4.5)
→ 5
print math.round(math.pi, 4)
→ 3.1416
|
math.sin
• function sin(x) → Number
Returns the cosine of x (in radians).
math.sqrt
• function sqrt(x) → Number
Returns the square root of x.
Throws ErrArgument if x < 0.
math.tan
• function tan(x) → Number
Returns the tangent of x (in radians).
math.trunc
• function trunc(x) → Number
Returns the integral part of x.
print math.trunc(3)
→ 3
print math.trunc(3.4)
→ 3
print math.trunc(-3.4)
→ -3
|
math Constants
• const e = 2.718281828459045
Euler constant.
• const inf = Inf
(positive) "infinity".
• const nan = NaN
"not-a-number".
• const pi = 3.141592653589793
π.
Next: Personal Data© 2004-2011 airbit AG, CH-8008 Zürich
Document AB-M-LIB-888