Skip to main content

Math

Holds utilty math functions not available on Roblox's math library.

Functions

map

Math.map(
numnumber,
min0number,
max0number,
min1number,
max1number
) → number

Maps a number from one range to another.

note

Note the mapped value can be outside of the initial range, which is very useful for linear interpolation.

print(Math.map(0.1, 0, 1, 1, 0)) --> 0.9

jitter

Math.jitter(
averagenumber,
spreadnumber?,--

Defaults to 50% of the average number which is pretty standard for industry

randomValuenumber?
) → number

Returns jittered value at the average value, with the spread being random.

isNaN

Math.isNaN(numnumber) → boolean

Returns true if a number is NaN

isFinite

Math.isFinite(numnumber) → boolean

Returns true if a number is finite

lerp

Math.lerp(
num0number,--

Number

num1number,--

Second number

percentnumber--

The percent

) → number--

The interpolated

Interpolates betweeen two numbers, given an percent. The percent is a number in the range that will be used to define how interpolated it is between num0 and num1.

print(Math.lerp(-1000, 1000, 0.75)) --> 500

lawOfCosines

Math.lawOfCosines(
anumber,
bnumber,
cnumber
) → number?--

Returns nil if this cannot be solved for

Solving for angle across from c

round

Math.round(
numbernumber,
precisionnumber?--

Defaults to 1

) → number

Round the given number to given precision

print(Math.round(72.1, 5)) --> 75

roundUp

Math.roundUp(
numbernumber,
precisionnumber
) → number

Rounds up to the given precision

roundDown

Math.roundDown(
numbernumber,
precisionnumber
) → number

Rounds down to the given precision

Show raw api
{
    "functions": [
        {
            "name": "map",
            "desc": "Maps a number from one range to another.\n\n:::note\nNote the mapped value can be outside of the initial range,\nwhich is very useful for linear interpolation.\n:::\n\n```lua\nprint(Math.map(0.1, 0, 1, 1, 0)) --> 0.9\n```",
            "params": [
                {
                    "name": "num",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "min0",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "max0",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "min1",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "max1",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 27,
                "path": "src/math/src/Shared/Math.lua"
            }
        },
        {
            "name": "jitter",
            "desc": "Returns jittered value at the average value, with the spread being\nrandom.",
            "params": [
                {
                    "name": "average",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "spread",
                    "desc": "Defaults to 50% of the average number which is pretty standard for industry",
                    "lua_type": "number?"
                },
                {
                    "name": "randomValue",
                    "desc": "",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 44,
                "path": "src/math/src/Shared/Math.lua"
            }
        },
        {
            "name": "isNaN",
            "desc": "Returns true if a number is NaN",
            "params": [
                {
                    "name": "num",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 56,
                "path": "src/math/src/Shared/Math.lua"
            }
        },
        {
            "name": "isFinite",
            "desc": "Returns true if a number is finite",
            "params": [
                {
                    "name": "num",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 65,
                "path": "src/math/src/Shared/Math.lua"
            }
        },
        {
            "name": "lerp",
            "desc": "Interpolates betweeen two numbers, given an percent. The percent is\na number in the range that will be used to define how interpolated\nit is between num0 and num1.\n\n```lua\nprint(Math.lerp(-1000, 1000, 0.75)) --> 500\n```",
            "params": [
                {
                    "name": "num0",
                    "desc": "Number",
                    "lua_type": "number"
                },
                {
                    "name": "num1",
                    "desc": "Second number",
                    "lua_type": "number"
                },
                {
                    "name": "percent",
                    "desc": "The percent",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "The interpolated",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 83,
                "path": "src/math/src/Shared/Math.lua"
            }
        },
        {
            "name": "lawOfCosines",
            "desc": "Solving for angle across from c",
            "params": [
                {
                    "name": "a",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "b",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "c",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "Returns nil if this cannot be solved for",
                    "lua_type": "number?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 95,
                "path": "src/math/src/Shared/Math.lua"
            }
        },
        {
            "name": "round",
            "desc": "Round the given number to given precision\n\n```lua\nprint(Math.round(72.1, 5)) --> 75\n```",
            "params": [
                {
                    "name": "number",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "precision",
                    "desc": "Defaults to 1",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 115,
                "path": "src/math/src/Shared/Math.lua"
            }
        },
        {
            "name": "roundUp",
            "desc": "Rounds up to the given precision",
            "params": [
                {
                    "name": "number",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "precision",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 130,
                "path": "src/math/src/Shared/Math.lua"
            }
        },
        {
            "name": "roundDown",
            "desc": "Rounds down to the given precision",
            "params": [
                {
                    "name": "number",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "precision",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 141,
                "path": "src/math/src/Shared/Math.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "Math",
    "desc": "Holds utilty math functions not available on Roblox's math library.",
    "source": {
        "line": 5,
        "path": "src/math/src/Shared/Math.lua"
    }
}