From the reference libraryRedM

Math <BadgeShared/>

jo_libs/modules/math/shared.md

Math <BadgeShared/>

Math is a module to extend Lua's standard mathematical library with additional utility functions for common calculations and operations needed in game development. It provides helpful functions for interpolation, rounding with precision, and other mathematical operations that aren't available in the base Lua math library.

Math Functions > math.clamp()

<!-- @include: ./slots/headers.md#shared|math.clamp -->

Clamps a number between a minimum and maximum value. <br>

<!-- @include: ./slots/descriptions.md#shared|math.clamp -->

Math Functions > math.clamp() > Syntax

math.clamp(x, min, max)

Math Functions > math.clamp() > Parameters

x : number

The number to clamp

min : number

The minimum value

max : number

The maximum value

Math Functions > math.clamp() > Return Value

Type : number

The clamped number

<!-- @include: ./slots/examples.md#shared|math.clamp -->

<!-- @include: ./slots/footers.md#shared|math.clamp -->


Math Functions > math.fromHex()

<!-- @include: ./slots/headers.md#shared|math.fromHex -->

Converts a hexadecimal string to an integer. <br>

<!-- @include: ./slots/descriptions.md#shared|math.fromHex -->

Math Functions > math.fromHex() > Syntax

math.fromHex(hex)

Math Functions > math.fromHex() > Parameters

hex : string

The hexadecimal string to convert, with or without "0x" prefix

Math Functions > math.fromHex() > Return Value

Type : integer

The integer representation

<!-- @include: ./slots/examples.md#shared|math.fromHex -->

<!-- @include: ./slots/footers.md#shared|math.fromHex -->


Math Functions > math.lerp()

<!-- @include: ./slots/headers.md#shared|math.lerp -->

Performs linear interpolation between two values. <br>

<!-- @include: ./slots/descriptions.md#shared|math.lerp -->

Math Functions > math.lerp() > Syntax

math.lerp(a, b, t)

Math Functions > math.lerp() > Parameters

a : number

The starting value

b : number

The ending value

t : number

The interpolation factor, usually between 0 and 1

Math Functions > math.lerp() > Return Value

Type : number

The interpolated value between a and b

<!-- @include: ./slots/examples.md#shared|math.lerp -->

<!-- @include: ./slots/footers.md#shared|math.lerp -->


Math Functions > math.round()

<!-- @include: ./slots/headers.md#shared|math.round -->

Rounds a number to the specified decimal precision. <br>

<!-- @include: ./slots/descriptions.md#shared|math.round -->

Math Functions > math.round() > Syntax

math.round(number, precision)

Math Functions > math.round() > Parameters

number : number

The number to round

precision : number <BadgeOptional />

The number of decimal places to round to <br> default:0

Math Functions > math.round() > Return Value

Type : number

The rounded number

<!-- @include: ./slots/examples.md#shared|math.round -->

<!-- @include: ./slots/footers.md#shared|math.round -->


Math Functions > math.toHex()

<!-- @include: ./slots/headers.md#shared|math.toHex -->

Converts a number to hexadecimal string representation. <br>

<!-- @include: ./slots/descriptions.md#shared|math.toHex -->

Math Functions > math.toHex() > Syntax

math.toHex(n, prefix)

Math Functions > math.toHex() > Parameters

n : integer

The integer to convert

prefix : boolean <BadgeOptional />

Add "0x" prefix, default: false

Math Functions > math.toHex() > Return Value

Type : string

The hexadecimal string representation

<!-- @include: ./slots/examples.md#shared|math.toHex -->

<!-- @include: ./slots/footers.md#shared|math.toHex -->


Math Functions > math.toSigned()

<!-- @include: ./slots/headers.md#shared|math.toSigned -->

<!-- @include: ./slots/descriptions.md#shared|math.toSigned -->

Math Functions > math.toSigned() > Syntax

math.toSigned(n)

<!-- @include: ./slots/examples.md#shared|math.toSigned -->

<!-- @include: ./slots/footers.md#shared|math.toSigned -->

Back to documentation