Namespace: math Stay organized with collections Save and categorize content based on your preferences.
rules. math
Globally available mathematical functions. These functions are accessed using themath. prefix and operate on numerical values.
Methods
abs
abs(num) returns number
Absolute value of a numeric value.
Parameter | |
|---|---|
num | number Numeric value. |
- Returns
non-null numberthe absolute numeric value of the input.
Example
math.abs(-1) == 1math.abs(1) == 1ceil
ceil(num) returns rules.Integer
Ceiling of the numeric value.
Parameter | |
|---|---|
num | number Numeric value. |
- Returns
non-nullrules.Integerthe ceiling of the given value.
Example
math.ceil(2.0) == 2math.ceil(2.1) == 3math.ceil(2.7) == 3floor
floor(num) returns rules.Integer
Floor of the numeric value.
Parameter | |
|---|---|
num | number Numeric value. |
- Returns
non-nullrules.Integerthe floor of the given value.
Example
math.floor(1.9) == 1math.floor(2.0) == 2math.floor(2.7) == 2isInfinite
isInfinite(num) returns rules.Boolean
Test whether the value is ±∞.
Parameter | |
|---|---|
num | number Numeric value. |
- Returns
non-nullrules.Booleantrue if the number is positive or negative infinity.
Example
math.isInfinite(∞) == truemath.isInfinite(100) == falseisNaN
isNaN(num) returns rules.Boolean
Test whether the value is ±∞.
Parameter | |
|---|---|
num | number Numeric value. |
- Returns
non-nullrules.Booleantrue if the value is not a number.
Example
math.isNaN(NaN) == truemath.isNaN(100) == falsepow
pow(base, exponent) returns rules.Float
Return the value of the first argument raised to the power of the second argument.
Parameter | |
|---|---|
base | number Numeric base value. |
exponent | number Numeric exponent value. |
- Returns
non-nullrules.Floatthe value of the first argument raised to the power of the second argument.
Example
math.pow(2, 2) == 4math.pow(1.5, 2) == 2.25math.pow(4, 0.5) == 2round
round(num) returns rules.Integer
Round the input value to the nearest int.
Parameter | |
|---|---|
num | number Numeric value. |
- Returns
non-nullrules.Integerthe nearest int to the given value.
Example
math.round(1.9) == 2math.round(2.4) == 2math.round(2.5) == 3sqrt
sqrt(num) returns rules.Float
Square root of the input value.
Parameter | |
|---|---|
num | number Numeric value. |
- Returns
non-nullrules.Floatthe square root of the input value.
Example
math.sqrt(4) == 2.0math.sqrt(2.25) == 1.5Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-02-06 UTC.