Reference index · Official Lua 5.2 math library · C Lua 5.2.4 source · Implementation
Install with state.OpenMathLibrary(). Numbers are .NET doubles. Most operations call System.Math; decomposition/scaling use managed helpers. Transcendental rounding and exceptional-value details can vary with the .NET runtime/platform, just as C math libraries vary between Lua builds. No C math library or mutable C locale is used.
Angles are radians unless an API explicitly converts degrees. The numeric text policy affects printing results, not the calculations.
| API / official reference | Inputs and result | Lua-CSharp implementation notes and differences |
|---|---|---|
math.abs(x) |
Absolute value. | Math.Abs. |
math.acos(x) |
Inverse cosine. | Math.Acos; managed floating-point behavior applies. |
math.asin(x) |
Inverse sine. | Math.Asin. |
math.atan(x) |
Inverse tangent. | One argument, as in Lua 5.2; use atan2 for two coordinates. |
math.atan2(y, x) |
Quadrant-aware inverse tangent for (y, x). |
Math.Atan2. |
math.ceil(x) |
Smallest integral double at least x. |
|
math.cos(x) |
Cosine. | Math.Cos. |
math.cosh(x) |
Hyperbolic cosine. | Math.Cosh. |
math.deg(x) |
Radians to degrees. | Multiplies by 180 / Math.PI. |
math.exp(x) |
Exponential with base e. | Math.Exp. |
math.floor(x) |
Largest integral double at most x. |
|
math.fmod(x, y) |
Remainder using a quotient truncated toward zero. | Uses the C# double remainder operator. This differs from Lua's % operator for some negative inputs, as fmod should. |
math.frexp(x) |
Returns mantissa and binary exponent, including subnormal decomposition. | Implemented by a managed double-bit helper rather than C frexp. |
math.huge |
Positive infinity. | Backed by double.PositiveInfinity. |
math.ldexp(m, e) |
Scales m by a power of two; exponent is converted to an integer. |
Uses Math.ScaleB on newer targets and a managed fallback on .NET Standard 2.1. |
math.log(x [, base]) |
Natural log, or log in the specified base. | Uses Math.Log, a base-10 specialization, or the ratio of natural logs. |
math.max(x, ...) |
Maximum of at least one numeric argument. | Uses ordered comparisons, preserving Lua 5.2's argument-order behavior for NaN/equal values. |
math.min(x, ...) |
Minimum of at least one numeric argument. | Uses ordered comparisons rather than a different NaN-selecting aggregate. |
math.modf(x) |
Returns integral and fractional parts. | Managed helper preserves signed zero and handles infinities. |
math.pi |
The double approximation of pi. | Backed by Math.PI. |
math.pow(x, y) |
x raised to y. |
Math.Pow. |
math.rad(x) |
Degrees to radians. | Multiplies by Math.PI / 180. |
math.random([m [, n]]) |
Without bounds, a value in [0,1). With bounds, uses Lua 5.2's floor-based interval formula. |
Uses System.Random; sequences differ from C Lua's C-runtime generator. For fractional bounds, the Lua 5.2 formula is retained; integer-only checks from newer Lua versions are not imposed. The generator is stored in the shared global environment, so coroutines in that state share it. |
math.randomseed(seed) |
Replaces the generator using the converted seed; returns no values. | Uses a 32-bit seed and System.Random. Repeatability is tied to the .NET generator/runtime, not C Lua's srand/rand sequence. |
math.sin(x) |
Sine. | Math.Sin. |
math.sinh(x) |
Hyperbolic sine. | Math.Sinh. |
math.sqrt(x) |
Square root. | Math.Sqrt. |
math.tan(x) |
Tangent. | Math.Tan. |
math.tanh(x) |
Hyperbolic tangent. | Math.Tanh. |
The deprecated math.log10 alias is absent; use math.log(x, 10). See official library changes. Integer-subtype APIs such as math.type, math.tointeger, and math.maxinteger belong to later Lua versions and are not installed.