Geometry and numeric utilities
| Function | Signature | Description |
|---|---|---|
hypot | (x: f64, y: f64) => f64 | Euclidean 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) => f64 | Copy sign of y to x |
fmod | (x: f64, y: f64) => f64 | Floating-point remainder of x / y |
logBase | (x: f64, base: f64) => f64 | Logarithm of x with given base |
powi | (x: f64, exp: i32) => f64 | x raised to integer power exp |
hypot()
Returns the Euclidean norm (hypotenuse) sqrt(x^2 + y^2) without intermediate overflow.
Signature
hypot(x: f64, y: f64): f64tyrus
const x: f64 = 3.0;
const y: f64 = 4.0;
const result: f64 = hypot(x, y);
print(result); // 5.0toPolar()
Converts Cartesian coordinates (x, y) to polar coordinates (r, theta).
Signature
toPolar(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).
Signature
toCartesian(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.
Signature
copysign(x: f64, y: f64): f64tyrus
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.
Signature
fmod(x: f64, y: f64): f64tyrus
const x: f64 = 5.5;
const y: f64 = 2.0;
const result: f64 = fmod(x, y);
print(result); // 1.5logBase()
Returns the logarithm of x with the given base.
Signature
logBase(x: f64, base: f64): f64tyrus
const x: f64 = 8.0;
const base: f64 = 2.0;
const result: f64 = logBase(x, base);
print(result); // 3.0powi()
Returns x raised to an integer power exp.
Signature
powi(x: f64, exp: i32): f64tyrus
const x: f64 = 2.0;
const exp: i32 = 3;
const result: f64 = powi(x, exp);
print(result); // 8.0