MathThe public stdlib math APIs route through runtime/libm-backed helpers where available. The LLVM backend may lower the internal __* helpers to LLVM intrinsics for maximum performance:

Math

Basic Functions

FunctionSignatureDescription
abs(x: Float) r: FloatAbsolute value (float)
absInt(x: Int) r: IntAbsolute value (integer)
min(a: Float, b: Float) r: FloatMinimum of two floats
max(a: Float, b: Float) r: FloatMaximum of two floats
minInt(a: Int, b: Int) r: IntMinimum of two integers
maxInt(a: Int, b: Int) r: IntMaximum of two integers
clamp(x: Float, lo: Float, hi: Float) r: FloatClamp to range
clampInt(x: Int, lo: Int, hi: Int) r: IntClamp integer to range
clamp01(x: Float) r: FloatClamp to [0, 1]
sign(x: Float) r: FloatSign (-1, 0, or 1)
approxEqual(a: Float, b: Float) r: BoolApproximate equality

Trigonometric Functions

FunctionSignatureDescription
sin(x: Float) r: FloatSine
cos(x: Float) r: FloatCosine
tan(x: Float) r: FloatTangent
asin(x: Float) r: FloatArcsine
acos(x: Float) r: FloatArccosine
atan(x: Float) r: FloatArctangent
atan2(y: Float, x: Float) r: FloatTwo-argument arctangent

Hyperbolic Functions

FunctionSignatureDescription
sinh(x: Float) r: FloatHyperbolic sine
cosh(x: Float) r: FloatHyperbolic cosine
tanh(x: Float) r: FloatHyperbolic tangent
asinh(x: Float) r: FloatInverse hyperbolic sine
acosh(x: Float) r: FloatInverse hyperbolic cosine
atanh(x: Float) r: FloatInverse hyperbolic tangent

Exponential and Logarithmic

FunctionSignatureDescription
exp(x: Float) r: Floate^x
exp2(x: Float) r: Float2^x
ln / log(x: Float) r: FloatNatural logarithm
log2(x: Float) r: FloatBase-2 logarithm
log10(x: Float) r: FloatBase-10 logarithm
pow(x: Float, y: Float) r: FloatPower (x^y)
sqrt(x: Float) r: FloatSquare root

Rounding

FunctionSignatureDescription
floor(x: Float) r: FloatRound down
ceil(x: Float) r: FloatRound up
round(x: Float) r: FloatRound to nearest
copysign(x: Float, y: Float) r: FloatMagnitude of x with sign of y

Integer Bit Operations

FunctionSignatureDescription
popcount(x: Int) r: IntCount set bits
countLeadingZeros(x: Int) r: IntCount leading zero bits, returning 64 for zero
countTrailingZeros(x: Int) r: IntCount trailing zero bits, returning 64 for zero
rotateLeft(x: Int, shift: Int) r: IntRotate bits left modulo 64
rotateRight(x: Int, shift: Int) r: IntRotate bits right modulo 64
byteswap(x: Int) r: IntReverse byte order

Angle Conversion

FunctionSignatureDescription
degToRad(deg: Float) r: FloatDegrees to radians
radToDeg(rad: Float) r: FloatRadians to degrees

Runtime Math Functions

The public stdlib math APIs route through runtime/libm-backed helpers where available. The LLVM backend may lower the internal __* helpers to LLVM intrinsics for maximum performance:

Runtime FunctionLLVM Intrinsic
__Sqrt(x)llvm.sqrt.f64
__Sin(x)llvm.sin.f64
__Cos(x)llvm.cos.f64
__Exp(x)llvm.exp.f64
__Log(x)llvm.log.f64
__Log10(x)llvm.log10.f64
__Fabs(x)llvm.fabs.f64
__Pow(x, y)llvm.pow.f64

Additional runtime functions:

FunctionDescription
__Asin(x)Arcsine
__Acos(x)Arccosine
__Atan(x)Arctangent
__Atan2(y, x)Two-argument arctangent
__Sinh(x)Hyperbolic sine
__Cosh(x)Hyperbolic cosine
__Tanh(x)Hyperbolic tangent
seen_math_round(x)Runtime/libm round
seen_math_asinh(x)Inverse hyperbolic sine
seen_math_acosh(x)Inverse hyperbolic cosine
seen_math_atanh(x)Inverse hyperbolic tangent
seen_math_copysign(x, y)Copy sign

The stdlib also exposes C ABI wrappers named seen_math_* for source-level modules that need stable runtime dispatch without depending on compiler intrinsic names directly.

Time

FunctionSignatureDescription
__GetTime()r: FloatCurrent time in seconds since epoch
nowSeconds()r: IntCurrent time in seconds
nowMillis()r: IntCurrent time in milliseconds
nowNanos()r: IntCurrent time in nanoseconds

Integer Bounds

FunctionReturn
Int_min()Minimum Int value (-2^63)
Int_max()Maximum Int value (2^63 - 1)

Example

fun main() {
    let angle = 45.0
    let rad = degToRad(angle)
    println("sin(45) = {sin(rad)}")
    println("cos(45) = {cos(rad)}")
    println("sqrt(2) = {sqrt(2.0)}")
    println("2^10 = {pow(2.0, 10.0)}")
    println("clamp(15, 0, 10) = {clamp(15.0, 0.0, 10.0)}")
}
Architected in Kotlin. Rendered with Materia. Powered by Aether.
© 2026 Yousef.