Selection and low-level
| Function | Signature | Description |
|---|---|---|
max | (a: f64, b: f64) => f64 | Maximum |
min | (a: f64, b: f64) => f64 | Minimum |
clamp | (value: f64, min: f64, max: f64) => f64 | Clamp value to range |
clampMin | (value: f64, min: f64) => f64 | Enforce minimum |
clampMax | (value: f64, max: f64) => f64 | Enforce maximum |
imul | (a: i32, b: i32) => i32 | C-style 32-bit multiplication |
clz32 | (x: i32) => i32 | Count leading zeros in 32-bit integer |
max()
Returns the larger of two numbers.
Signature
max(a: f64, b: f64): f64tyrus
const a: f64 = 10.0;
const b: f64 = 20.0;
const result: f64 = max(a, b);
print(result); // 20.0min()
Returns the smaller of two numbers.
Signature
min(a: f64, b: f64): f64tyrus
const a: f64 = 10.0;
const b: f64 = 20.0;
const result: f64 = min(a, b);
print(result); // 10.0clamp()
Restricts a value to a given range.
Signature
clamp(value: f64, min: f64, max: f64): f64tyrus
const value: f64 = 15.0;
const result: f64 = clamp(value, 0.0, 10.0);
print(result); // 10.0clampMin()
Enforces a minimum value.
Signature
clampMin(value: f64, min: f64): f64tyrus
const value: f64 = -5.0;
const result: f64 = clampMin(value, 0.0);
print(result); // 0.0clampMax()
Enforces a maximum value.
Signature
clampMax(value: f64, max: f64): f64tyrus
const value: f64 = 15.0;
const result: f64 = clampMax(value, 10.0);
print(result); // 10.0imul()
Performs C-style 32-bit integer multiplication, truncating overflow.
Signature
imul(a: i32, b: i32): i32tyrus
const a: i32 = 2000000000;
const b: i32 = 2;
const result: i32 = imul(a, b);
print(result); // -294967296 (C-style 32-bit overflow)clz32()
Counts the leading zero bits in a 32-bit integer.
Signature
clz32(x: i32): i32tyrus
const value: i32 = 8; // 0b1000
const result: i32 = clz32(value);
print(result); // 28 (28 leading zeros in 32-bit)