Math constants

Summary

Expand the constants provided in the math library.

Motivation

With the introduction of math.isnan, Luau has the opportunity to add a new constant representing NaN (Not a Number). As linting support for Luau continues becoming more robust, we can discourage patterns like 0/0 to generate NaN and instead provide the constant directly through the math library.

Without the math.isnan API, this could have created confusion in the past:

if maybeNan == math.nan do
    print("This line will never be hit: comparing to NaN always returns false.")
end

With the new API, however, this is now easier to use:

local maybeNan = math.nan
if math.isnan(maybeNan) do
    print("This line will be hit!")
end

While adding NaN, we also have an opportunity to modernize the set of constants available through the math library. Some history:

Luau currently only supports math.pi and math.huge. Integer types are not supported in Luau, so math.maxinteger and math.mininteger wouldn’t make much sense, but adding other commonly used constants would be an easy value-add for users of the language.

Design

In addition to math.pi and math.huge, we propose adding the following constants.

Alternatives