Skip to content

Geometry and numeric utilities ​

FunctionSignatureDescription
hypot(x: f64, y: f64) => f64Euclidean norm sqrt(x^2 + y^2)
toPolar(x: f64, y: f64) => [f64, f64]Convert Cartesian to polar (r, theta)
toCartesian(r: f64, theta: f64) => [f64, f64]Convert polar to Cartesian (x, y)
copysign(x: f64, y: f64) => f64Copy sign of y to x
fmod(x: f64, y: f64) => f64Floating-point remainder of x / y
logBase(x: f64, base: f64) => f64Logarithm of x with given base
powi(x: f64, exp: i32) => f64x raised to integer power exp

hypot() ​

Returns the Euclidean norm (hypotenuse) sqrt(x^2 + y^2) without intermediate overflow.

Signaturehypot(x: f64, y: f64): f64
tyrus
const x: f64 = 3.0;
const y: f64 = 4.0;
const result: f64 = hypot(x, y);
print(result); // 5.0

toPolar() ​

Converts Cartesian coordinates (x, y) to polar coordinates (r, theta).

SignaturetoPolar(x: f64, y: f64): [f64, f64]
tyrus
const x: f64 = 3.0;
const y: f64 = 4.0;
const result: [f64, f64] = toPolar(x, y);
print(result); // [5.0, ~0.9273]

toCartesian() ​

Converts polar coordinates (r, theta) to Cartesian coordinates (x, y).

SignaturetoCartesian(r: f64, theta: f64): [f64, f64]
tyrus
const r: f64 = 5.0;
const theta: f64 = 0.9273;
const result: [f64, f64] = toCartesian(r, theta);
print(result); // [3.0, 4.0]

copysign() ​

Returns a value with the magnitude of x and the sign of y.

Signaturecopysign(x: f64, y: f64): f64
tyrus
const x: f64 = -3.0;
const y: f64 = 2.0;
const result: f64 = copysign(x, y);
print(result); // 3.0 (magnitude of x, sign of y)

fmod() ​

Returns the floating-point remainder of x / y.

Signaturefmod(x: f64, y: f64): f64
tyrus
const x: f64 = 5.5;
const y: f64 = 2.0;
const result: f64 = fmod(x, y);
print(result); // 1.5

logBase() ​

Returns the logarithm of x with the given base.

SignaturelogBase(x: f64, base: f64): f64
tyrus
const x: f64 = 8.0;
const base: f64 = 2.0;
const result: f64 = logBase(x, base);
print(result); // 3.0

powi() ​

Returns x raised to an integer power exp.

Signaturepowi(x: f64, exp: i32): f64
tyrus
const x: f64 = 2.0;
const exp: i32 = 3;
const result: f64 = powi(x, exp);
print(result); // 8.0