Skip to content

Commit 0188046

Browse files
committed
math.trunc, math.cbrt, math.hypot
1 parent 3df3657 commit 0188046

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

docs/Runtime Environment/Math.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ local x = 0 / 0
1010
print(x ~= x) -- Lua way: Prove the variable is NaN because it is not equal to itself. Works, but unintuitive.
1111
print(math.isnan(x))
1212
```
13+
1314
---
1415
### `math.round`
1516
Rounds a number to the nearest integer.
@@ -19,6 +20,37 @@ Rounds a number to the nearest integer.
1920
print(math.round(2.4)) --> 2
2021
print(math.round(2.5)) --> 3
2122
```
23+
24+
---
25+
### `math.trunc`
26+
Truncates the fractional part of a number, returning the integer portion toward zero.
27+
#### Parameters
28+
1. The number to truncate.
29+
```pluto
30+
print(math.trunc(10.5)) --> 10
31+
print(math.trunc(-10.5)) --> -10
32+
```
33+
34+
---
35+
### `math.cbrt`
36+
Returns the cube root of a number.
37+
#### Parameters
38+
1. The number to take the cube root of.
39+
```pluto
40+
print(math.cbrt(27)) --> 3
41+
print(math.cbrt(-27)) --> -3
42+
```
43+
44+
---
45+
### `math.hypot`
46+
Returns the square root of the sum of squares of its arguments.
47+
#### Parameters
48+
1. Two numbers representing orthogonal components.
49+
```pluto
50+
print(math.hypot(3, 4)) --> 5
51+
print(math.hypot(1e155, 1e155)) --> 1.41421e155
52+
```
53+
2254
---
2355
### `math.atan2`
2456
An alias for the `math.atan` function.

0 commit comments

Comments
 (0)