Skip to content

Math

Overview

The Math module provides standard mathematical functions and constants. Functions operate on float unless otherwise noted.

Constants

Math.PI // 3.141592653589793
Math.E // 2.718281828459045

Basic Functions

Math.Abs(-5.0) // 5.0
Math.AbsInt(-3) // 3
Math.Sqrt(9.0) // 3.0
Math.Pow(2.0, 10.0) // 1024.0
Math.PowInt(2, 10) // 1024

Rounding

Math.Floor(3.7) // 3.0
Math.Ceil(3.2) // 4.0
Math.Round(3.5) // 4.0

Min and Max

Math.Min(3.0, 7.0) // 3.0
Math.Max(3.0, 7.0) // 7.0
Math.MinInt(3, 7) // 3
Math.MaxInt(3, 7) // 7

Trigonometry

All angles are in radians:

Math.Sin(Math.PI / 2.0) // 1.0
Math.Cos(0.0) // 1.0

Example

float Hypotenuse(float a, float b)
{
return Math.Sqrt(Math.Pow(a, 2.0) + Math.Pow(b, 2.0));
}
float h = Hypotenuse(3.0, 4.0);
Console.WriteLine($"Hypotenuse: {h}");