math.fmod
Shared
Returns the remainder of a division between two numbers
Syntax
local result = math.fmod(
dividend,
divisor
)Parameters
| Type | Name | Description |
|---|---|---|
number | dividend | Number to be divided |
number | divisor | Number to divide by |
Returns
| Type | Name | Description |
|---|---|---|
number | result | Remainder of dividend / divisor with the same sign as dividend |
Examples
local result = math.fmod(10, 3)
engine.print("info", result) -- 1.0local result = math.fmod(5.5, 2.0)
engine.print("info", result) -- 1.5local result = math.fmod(-10, 3)
engine.print("info", result) -- -1.0local result = math.fmod(7, 7)
engine.print("info", result) -- 0.0local angle = 450.0
local wrapped = math.fmod(angle, 360)
engine.print("info", wrapped) -- 90.0local elapsed = 7.3
local period = 2.0
local phase = math.fmod(elapsed, period)
engine.print("info", phase) -- 1.3local a, b = 7.5, 2.5
engine.print("info", math.fmod(a, b)) -- 0.0