Math
The Math library consists of many math constants and functions that are extremely important
for things such as games, apps, etc.
Import it into your projects like so:
using Std::Math
println(Math.abs(-5)) # prints 5println(Math.pi) # prints 3.14159...Summary
Section titled “Summary”Constants
Section titled “Constants”A few global constants used heavily in mathematics:
pi:
number e:
number tau:
number Methods
Section titled “Methods”The following are mathematic functions. All of them (as of writing) take in numbers as arguments. You can convert
values to numbers using the number(value) built-in function.
abs(
x:
number ,
): number sin(
x:
number ,
): number cos(
x:
number ,
): number tan(
x:
number ,
): number asin(
x:
number ,
): number acos(
x:
number ,
): number atan(
x:
number ,
): number asinh(
x:
number ,
): number acosh(
x:
number ,
): number atanh(
x:
number ,
): number atan2(
x:
number , y:
number ,
): number floor(
x:
number ,
): number ceil(
x:
number ,
): number round(
x:
number ,
): number pow(
base:
number , exponent:
number ,
): number sqrt(
x:
number ,
): number max(
a:
number , b:
number ,
): number min(
a:
number , b:
number ,
): number clamp(
value:
number , min:
number , max:
number ,
): number Constants
Section titled “Constants”The ratio of any circle’s circumference to its diameter.
An irrational number that keeps going but never repeats.
Approximately equal to 3.14159265359.
# Area = πr²let r = 3let area = Math.pi * r * rprintln($"The area of a circle with radius {r} is {area}")The mathematical constant ‘e’, also known as Euler’s number, an irrational, non-repeating decimal
fundamental to natural growth, decay, and logarithms (base e or ln)
Approximately equal to 2.718281828459.
The number tau (τ) is a mathematical constant that is the
ratio of a circle’s circumference to its radius.
It is approximately equal to 6.2831853 and exactly equal to 2π
Methods
Section titled “Methods”Returns the absolute (positive) value of a number. Or the positive distance of it from zero. Useful for converting negative values to positive ones.
abs(
x:
number ,
): number println(Math.abs(-5))# prints 5Trigonometric sine of angle x in radians. Can be used to create a sin-wave
or for calculating proper distance based on angles.
abs(
x:
number ,
): number Math.sin(x)Returns the cosine of angle x in radians. Useful for trigonometry and calculating distances or projections.
cos(
x:
number ,
): number Returns the tangent of angle x in radians. Useful for slope calculations or angle-based math.
tan(
x:
number ,
): number Returns the inverse sine (arc-sine) of x. The result is in radians.
asin(
x:
number ,
): number Returns the inverse cosine (arc-cosine) of x. Result is in radians.
acos(
x:
number ,
): number Returns the inverse tangent (arc-tangent) of x. Result is in radians.
atan(
x:
number ,
): number Returns the inverse hyperbolic sine of x.
asinh(
x:
number ,
): number Returns the inverse hyperbolic cosine of x.
acosh(
x:
number ,
): number Returns the inverse hyperbolic tangent of x.
atanh(
x:
number ,
): number Returns the arc-tangent of y / x, considering the signs of both arguments to determine the correct quadrant.
atan2(
y:
number , x:
number ,
): number Rounds x down to the nearest smaller integer.
floor(
x:
number ,
): number Rounds x up to the nearest larger integer.
ceil(
x:
number ,
): number Rounds x to the nearest integer.
round(
x:
number ,
): number Returns e raised to the power of x.
exp(
x:
number ,
): number Raises base to the power of exponent.
pow(
base:
number , exponent:
number ,
): number Returns the square root of x.
sqrt(
x:
number ,
): number Returns the larger of a or b.
max(
a:
number , b:
number ,
): number Returns the smaller of a or b.
min(
a:
number , b:
number ,
): number Clamps value between min and max. Useful for restricting a number to a specific range.
clamp(
value:
number , min:
number , max:
number ,
): number