World of Warcraft Forever API · math.md, for your AI
math
11 functions, as Blizzard documents them for Forever 1.60.1 (70959).
Making an addon with an AI? Tell it: Read https://wowaddons.gg/agents.md, then make me a World of Warcraft Forever addon that …, try it with me in the game, and publish it. It checks every call against this API before you try it in the game, then publishes it here. How it works.
Functions
math.clamp
clampedValue = math.clamp(value, minimum, maximum)
Clamps a value to the inclusive range defined by the minimum and maximum values.
Arguments
value | number | The value to clamp. |
|---|---|---|
minimum | number | The inclusive lower bound. |
maximum | number | The inclusive upper bound. |
Returns
clampedValue | number | The clamped value. |
|---|
math.isfinite
finite = math.isfinite(value)
Returns whether a value is finite.
Arguments
value | number | The value to inspect. |
|---|
Returns
finite | bool | True if the value is neither infinite nor NaN; otherwise false. |
|---|
math.isinf
infinite = math.isinf(value)
Returns whether a value is positive or negative infinity.
Arguments
value | number | The value to inspect. |
|---|
Returns
infinite | bool | True if the value is positive or negative infinity; otherwise false. |
|---|
math.isnan
nan = math.isnan(value)
Returns whether a value is NaN.
Arguments
value | number | The value to inspect. |
|---|
Returns
nan | bool | True if the value is NaN; otherwise false. |
|---|
math.lerp
interpolatedValue = math.lerp(startValue, endValue, amount)
Linearly interpolates between two values.
Arguments
startValue | number | The value returned when the interpolation amount is 0. |
|---|---|---|
endValue | number | The value returned when the interpolation amount is 1. |
amount | number | The interpolation amount. Values outside [0, 1] extrapolate beyond the two values. |
Returns
interpolatedValue | number | The interpolated value. |
|---|
math.normalize
normalizedValue = math.normalize(value, minimum, maximum)
Returns the relative position of a value within a range, where the minimum maps to 0 and the maximum maps to 1.
Arguments
value | number | The value to normalize. |
|---|---|---|
minimum | number | The value that maps to 0. |
maximum | number | The value that maps to 1. |
Returns
normalizedValue | number | The normalized value. Values outside the input range produce results outside [0, 1]. |
|---|
math.remap
remappedValue = math.remap(value, sourceMinimum, sourceMaximum, destinationMinimum, destinationMaximum)
Maps a value from one range to the corresponding position in another range.
Arguments
value | number | The value to map. |
|---|---|---|
sourceMinimum | number | The lower endpoint of the source range. |
sourceMaximum | number | The upper endpoint of the source range. |
destinationMinimum | number | The lower endpoint of the destination range. |
destinationMaximum | number | The upper endpoint of the destination range. |
Returns
remappedValue | number | The mapped value. Values outside the source range are extrapolated beyond the destination range. |
|---|
math.round
roundedValue = math.round(value, [decimalPlaces])
Rounds a value to the specified number of decimal places, with halfway values rounded away from zero.
Arguments
value | number | The value to round. |
|---|---|---|
decimalPlaces | number default 0 | The number of decimal places to preserve. Negative values round to positions left of the decimal point. |
Returns
roundedValue | number | The rounded value. |
|---|
math.saturate
saturatedValue = math.saturate(value)
Clamps a value to the inclusive range [0, 1].
Arguments
value | number | The value to clamp. |
|---|
Returns
saturatedValue | number | The value clamped to the inclusive range [0, 1]. |
|---|
math.sign
sign = math.sign(value)
Returns -1 for negative values, 0 for zero, and 1 for positive values.
Arguments
value | number | The value whose sign will be returned. |
|---|
Returns
sign | number | The sign of the value. |
|---|
math.wrap
wrapped = math.wrap(value, minimum, maximum)
Wraps a value into the half-open range [minimum, maximum).
Arguments
value | number | The value to wrap. |
|---|---|---|
minimum | number | The inclusive lower bound of the range. |
maximum | number | The exclusive upper bound of the range. |
Returns
wrapped | number | The wrapped value, greater than or equal to minimum and less than maximum. If minimum equals maximum, returns minimum. |
|---|