WowAddons

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

valuenumberThe value to clamp.
minimumnumberThe inclusive lower bound.
maximumnumberThe inclusive upper bound.

Returns

clampedValuenumberThe clamped value.

math.isfinite

finite = math.isfinite(value)

Returns whether a value is finite.

Arguments

valuenumberThe value to inspect.

Returns

finiteboolTrue 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

valuenumberThe value to inspect.

Returns

infiniteboolTrue if the value is positive or negative infinity; otherwise false.

math.isnan

nan = math.isnan(value)

Returns whether a value is NaN.

Arguments

valuenumberThe value to inspect.

Returns

nanboolTrue if the value is NaN; otherwise false.

math.lerp

interpolatedValue = math.lerp(startValue, endValue, amount)

Linearly interpolates between two values.

Arguments

startValuenumberThe value returned when the interpolation amount is 0.
endValuenumberThe value returned when the interpolation amount is 1.
amountnumberThe interpolation amount. Values outside [0, 1] extrapolate beyond the two values.

Returns

interpolatedValuenumberThe 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

valuenumberThe value to normalize.
minimumnumberThe value that maps to 0.
maximumnumberThe value that maps to 1.

Returns

normalizedValuenumberThe 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

valuenumberThe value to map.
sourceMinimumnumberThe lower endpoint of the source range.
sourceMaximumnumberThe upper endpoint of the source range.
destinationMinimumnumberThe lower endpoint of the destination range.
destinationMaximumnumberThe upper endpoint of the destination range.

Returns

remappedValuenumberThe 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

valuenumberThe value to round.
decimalPlacesnumber default 0The number of decimal places to preserve. Negative values round to positions left of the decimal point.

Returns

roundedValuenumberThe rounded value.

math.saturate

saturatedValue = math.saturate(value)

Clamps a value to the inclusive range [0, 1].

Arguments

valuenumberThe value to clamp.

Returns

saturatedValuenumberThe 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

valuenumberThe value whose sign will be returned.

Returns

signnumberThe sign of the value.

math.wrap

wrapped = math.wrap(value, minimum, maximum)

Wraps a value into the half-open range [minimum, maximum).

Arguments

valuenumberThe value to wrap.
minimumnumberThe inclusive lower bound of the range.
maximumnumberThe exclusive upper bound of the range.

Returns

wrappednumberThe wrapped value, greater than or equal to minimum and less than maximum. If minimum equals maximum, returns minimum.

It takes WowAddons

Free, for Windows, macOS and Linux: it puts the addon in your game in one click and keeps it up to date. Open it once, then press Install again.

WowAddons runs on your computer: open wowaddons.gg there.

Download for Windows