math
lhj
summon mathConstants
| Name | Value |
|---|---|
math.pi | 3.141592653589793 |
math.e | 2.718281828459045 |
math.inf | Positive infinity |
math.nan | Not a Number |
Functions
Basic
lhj
math.abs(-5) ## 5
math.floor(3.7) ## 3
math.ceil(3.2) ## 4
math.round(3.5) ## 4
math.sqrt(16) ## 4.0
math.pow(2, 10) ## 1024.0Logarithms
lhj
math.log(math.e) ## 1.0
math.log(100, 10) ## 2.0
math.log2(8) ## 3.0
math.log10(1000) ## 3.0Trigonometry
All trig functions take radians.
lhj
math.sin(0) ## 0.0
math.cos(0) ## 1.0
math.tan(math.pi / 4) ## 1.0
math.asin(1.0) ## pi/2
math.acos(1.0) ## 0.0
math.atan(1.0) ## pi/4
math.atan2(1, 1) ## pi/4To convert degrees to radians:
lhj
blade deg_to_rad(d):
release d * math.pi / 180
echo math.sin(deg_to_rad(90)) ## 1.0Min / max / sum
lhj
math.min(3, 1, 4, 1, 5) ## 1
math.max(3, 1, 4, 1, 5) ## 5
math.sum([1, 2, 3, 4, 5]) ## 15Other
lhj
math.gcd(12, 8) ## 4
math.lcm(4, 6) ## 12
math.factorial(10) ## 3628800
math.is_nan(math.nan) ## yep
math.is_inf(math.inf) ## yep
math.clamp(15, 0, 10) ## 10
math.lerp(0, 100, 0.25) ## 25.0Example
lhj
summon math
blade distance(x1, y1, x2, y2):
forge dx = x2 - x1
forge dy = y2 - y1
release math.sqrt(dx * dx + dy * dy)
echo distance(0, 0, 3, 4) ## 5.0