DWScript provides a rich set of mathematical tools, from basic arithmetic to advanced 3D vectors.
Most basic math functions are available globally. These include Abs, Sqr, Sqrt, Round, and Trunc.
var x := -10.5;
PrintLn(Abs(x).ToString); // 10.5
PrintLn(Sqr(4).ToString); // 16
PrintLn(Sqrt(16).ToString); // 4
PrintLn(Round(x).ToString); // -10 10.5 16 4 -10
Trigonometric functions like Sin, Cos, and Tan expect angles in radians. Use DegToRad and RadToDeg for conversions.
var angle := 45.0;
var rad := DegToRad(angle);
PrintLn('Sin(45): ' + Sin(rad).ToString); Sin(45): 0.707106781186547
For general-purpose simulation and games, use the Random and RandomInt functions. For security-related tasks (tokens, keys), use the Crypto library instead.
// Random float between 0 and 1
var f := Random;
// Random integer between 0 and 99
var i := RandomInt(100); For a complete list of all available math functions, constants, and advanced libraries, see the reference documentation: