Math - AlsoGhostglowDev/Ghost-s-Utilities GitHub Wiki
An addon to Lua's standard math library.
This addon can be declared with the name "math" since it does NOT override the Lua's standard math library.
local math = require 'ghostutil.lua-addons.math'math.epsilon = 1e-12math.equals.
math.max_float = 1.79e308math.max_int = 0x7FFFFFFFmath.min_float = 4.94e-324math.min_int = -0x7FFFFFFFmath.infinity = math.hugemath.negative_infinity = -math.hugemath.infinity.
math.nan = 0/0lerp(a: number, b: number, ratio: number): numberLinear interpolation, a mathematical function that finds a point between two values (a and b) based on a the ratio value; a value between 0 and 1.
Parameters:
-
a: The starting value. -
b: The end value. -
ratio: The interpolation factor, ranges from 0 to 1.
Returns: The end-product calculated.
─────────────────────────
fpslerp(a: number, b: number, ratio: number): numberSimilar to math.lerp, this function instead relies on the current game FPS.
Parameters:
-
a: The starting value. -
b: The end value. -
ratio: The interpolation factor, ranges from 0 to 1.
Returns: The end-product calculated with taking the game's FPS into account.
─────────────────────────
isfinite(n: number): booleanChecks if the given number is finite. Defined through when the passed value is not infinity and Not a Number (NaN).
Parameters:
-
n: The number to check.
Returns: true if the number is finite.
─────────────────────────
isnan(n: number): booleanChecks if the given number is Not a Number (NaN). Defined through if the type itself a number but does not equal to itself.
(Shortcut to util.isnan)
Parameters:
-
n: The number to check.
Returns: true if the number is Not a Number.
─────────────────────────
invert(n: number): numberSwaps out the given number's sign.
Parameters:
-
n: The number to invert.
Returns: The inverted number.
─────────────────────────
ispositive(n: number): booleanChecks if the given number is a positive.
Parameters:
-
n: The number to check.
Returns: If the number is positive.
Information: If the number passed is 0, false is returned.
─────────────────────────
isnegative(n: number): booleanChecks if the given number is negative.
Parameters:
-
n: The number to check.
Returns: If the number is negative.
Information: If the number passed is 0, false is returned.
─────────────────────────
factorial(n: int): booleanReturns the factorial of the given number.
Parameters:
-
n: The integer to compute the factorial of.
Returns: The factorial of the given number.
─────────────────────────
bound(n: number, min: number, max: number): numberBounds the given number in a specific range set by min and max from going less/over the set limit.
(Aliases: math.clamp)
Parameters:
-
n: The number to bound. -
min: The minimum limit. -
max: The maximum limit.
Returns: The bounded number.
─────────────────────────
floordecimal(n: number, ?decimals: number): numberLimits the decimals of the given number to the specified value.
Parameters:
-
n: The number. -
decimals(optional): The decimals the number should have, defaults to2.
Returns: The number.
─────────────────────────
round(n: number): numberRounds the given number to the nearest integer.
Parameters:
-
n: The number to be rounded.
Returns: The rounded number.
─────────────────────────
midpoint(a: number, b: number): numberFinds the midpoint between two points.
Parameters:
-
a: The first point. -
b: The second point.
Returns: The midpoint of the given points.
─────────────────────────
distance(x1: number, y1: number, x2: number, y2: number): numberFinds the distance between two points in a two-dimensional space.
Parameters:
- (
x1,y1): The coordinates of the first point. - (
x2,y2): The coordinates of the second point.
Returns: The distance between two points.
─────────────────────────
distance3(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number): numberFinds the distance between two points in a three-dimensional space.
Parameters:
- (
x1,y1,z1): The coordinates of the first point. - (
x2,y2,z2): The coordinates of the second point.
Returns: The distance between two points.
─────────────────────────
dot(ax: number, ay: number, bx: number, by: number): numberComputes the dot product of two 2D vectors.
Parameters:
- (
ax,ay): Components of the first vector. - (
bx,by): Components of the second vector.
Returns: The dot product of the two vectors.
─────────────────────────
dot3(ax: number, ay: number, az: number, bx: number, by: number, bz: number): numberComputes the dot product of two 3D vectors.
Parameters:
- (
ax,ay,az): Components of the first vector. - (
bx,by,bz): Components of the second vector.
Returns: The dot product of the two vectors.
─────────────────────────
equals(a: number, b: number, ?diff: number): booleanChecks if the two values (a and b) are equal to each other by using epsilon (or diff) for a more loose equal check than a literal equal-to operator.
Parameters:
-
a: The first value. -
b: The second value. -
diff(optional): The minimum difference between the two numbers until it should be considered equal to each other. Defaults tomath.epsilon.
─────────────────────────
area(w: number, h: number): numberThe area of the given dimensions.
Parameters:
-
w: The width. -
h: The height.
Returns: The area based on the given values.
─────────────────────────
volume(w: number, h: number, l: number): numberThe volume of the given dimensions.
Parameters:
-
w: The width. -
h: The height. -
l: The length.
Returns: The volume based on the given values.
─────────────────────────
inbounds(n: number, min: number, max: number): booleanChecks if the given number is in the bounds of the specified limit.
Parameters:
-
n: The number to check. -
min: The minimum bound. -
max: The maximum bound.
Returns: true if the given number is in bounds.
─────────────────────────
iseven(n: number): booleanChecks if the passed number is even.
Parameters:
-
n: The number to check.
Returns: true if even.
─────────────────────────
isodd(n: number): booleanChecks if the passed number is odd
Parameters:
-
n: The number to check.
Returns: true if odd.
─────────────────────────
boundedadd(n: number, a: number, min: number, max: number): numberPerforms an arithmetic addition of n to a while keeping it in the given bounds.
Parameters:
-
n: The number. -
a: The number to add ton. -
min: The minimum limit. -
max: The maximum limit.
Returns: The bounded number.
─────────────────────────
samesign(a: number, b: number): numberChecks if the passed values both use the same sign.
(using math.signof)
Parameters:
-
a: The first value. -
b: The second value to compare.
Returns: true if both values has the same sign.
─────────────────────────
signof(n: number): numberReturns -1 or 1 based on what sign n has.
Parameters:
-
n: The number to check
Returns: -1 if negative, 1 if positive or 0.
GhostUtil 3.0.0 • Docs 3.0.0, Revision 1
a Lua Library made by GhostglowDev; for Psych Engine
© 2025 GhostglowDev — Ghost's Utilities
Licensed under the MIT License.