Error Handling
Maths.js validates inputs for safety and predictability.
Error types
Section titled “Error types”TypeError: Thrown for invalid types, non-finite values, or non-integers where integers are required.RangeError: Thrown for empty collections where values are required, out-of-range parameters, or invalid bounds.
Common cases
Section titled “Common cases”Maths.avg()throwsRangeErrorbecause at least one value is required.Maths.factorial(2.5)throwsTypeErrorbecausenmust be an integer.Maths.factorial(-1)throwsRangeErrorbecausenmust be non-negative.Maths.percentile([1, 2, 3], 101)throwsRangeErrorbecausepmust be between 0 and 100.Maths.clamp(1, 10, 0)throwsRangeErrorbecauseminmust be less than or equal tomax.