math.abs
Shared
Returns the absolute value of a number
Syntax
local result = math.abs(
value
)Parameters
| Type | Name | Description |
|---|---|---|
number | value | Number to get the absolute value of |
Returns
| Type | Name | Description |
|---|---|---|
number | result | Absolute (non-negative) value of the input |
Examples
local result = math.abs(-5)
engine.print("info", result) -- 5local result = math.abs(42)
engine.print("info", result) -- 42local result = math.abs(0)
engine.print("info", result) -- 0local result = math.abs(-3.14)
engine.print("info", result) -- 3.14local a = 10
local b = 35
local distance = math.abs(a - b)
engine.print("info", distance) -- 25local delta = -0.75
local speed = math.abs(delta) * 10
engine.print("info", speed) -- 7.5local value = -0.0001
local tolerance = 0.001
if math.abs(value) < tolerance then
engine.print("info", "Within tolerance")
end