std/math

March 14, 2026 ยท View on GitHub

The Math module provides a core set of standard mathematical constants and functions. It acts as a Zen-C wrapper around the standard floating-point mathematical operations.

Overview

  • Static Methods: All methods are called on the Math struct directly.
  • Precision: Uses double for high-precision floating-point arithmetic.
  • Comprehensive: Covers trigonometry, exponentials, logarithms, and rounding.
  • Efficient: Directly wraps optimized C library functions.

Usage

import "std/math.zc"

fn main() {
    let radius = 5.0;
    let area = Math::PI() * Math::pow(radius, 2.0);
    println "Area of circle: {area}";
}

Constants

All constants are static functions returning a double.

ConstantDescription
Math::PI()Archimedes' constant (approximately 3.14159).
Math::E()Euler's number (approximately 2.71828).

Methods

Arithmetic

MethodSignatureDescription
absabs(x: double) -> doubleReturns the absolute value of x.
sqrtsqrt(x: double) -> doubleReturns the square root of x.
powpow(base: double, exp: double) -> doubleReturns base raised to the power of exp.
expexp(x: double) -> doubleReturns e raised to the power of x.
loglog(x: double) -> doubleReturns the natural logarithm (base-e) of x.
log10log10(x: double) -> doubleReturns the base-10 logarithm of x.

Trigonometry

MethodSignatureDescription
sinsin(x: double) -> doubleReturns the sine of x (radians).
coscos(x: double) -> doubleReturns the cosine of x (radians).
tantan(x: double) -> doubleReturns the tangent of x (radians).
asinasin(x: double) -> doubleReturns the arcsine of x.
acosacos(x: double) -> doubleReturns the arccosine of x.
atanatan(x: double) -> doubleReturns the arctangent of x.
atan2atan2(y: double, x: double) -> doubleReturns the arctangent of y/x.

Rounding & Remainder

MethodSignatureDescription
ceilceil(x: double) -> doubleRounds up to the nearest integer.
floorfloor(x: double) -> doubleRounds down to the nearest integer.
roundround(x: double) -> doubleRounds to the closest integer.
modmod(x: double, y: double) -> doubleComputes the floating-point remainder of x / y.

Min / Max

MethodSignatureDescription
maxmax(a: double, b: double) -> doubleReturns the larger of two values.
minmin(a: double, b: double) -> doubleReturns the smaller of two values.