Skip to main content

Module ops

Module ops 

Source
Expand description

Generic scalar operations over Real.

All functions in this module are generic over the Real trait and work with both f32 and f64.

Functionsยง

abs_sub
Saturating subtraction: max(0, a - b).
bilinear
Bilinear interpolation between four corner values.
cbrt
Cube root of x.
clamp
Clamp x into [lo, hi].
clamp01
Clamp x into [0, 1].
clamp11
Clamp x into [-1, 1].
copysign
Copy the sign of b to the magnitude of a.
cumprod
Cumulative product of a slice. Returns an empty vector for an empty input.
cumsum
Cumulative sum of a slice. Returns an empty vector for an empty input.
deg_to_grad
Convert degrees to gradians.
deg_to_rad
Convert degrees to radians.
distance
Distance between two values: |a - b|.
dot_product
Dot product of two slices. Returns T::zero() if either is empty. Truncates to the shorter length if they differ.
frac
Fractional part toward zero: x - trunc(x).
fract
Fractional part: x - floor(x). Negative inputs give [0, 1).
grad_to_deg
Convert gradians to degrees (1 gradian = 0.9 degrees).
grad_to_rad
Convert gradians to radians.
hypot2
Overflow-safe sqrt(a^2 + b^2), generic over reals.
hypot3
Overflow-safe sqrt(a^2 + b^2 + c^2), generic over reals.
integer_part
Integer part: floor(x).
inv_lerp
Inverse linear interpolation: find t such that lerp(a, b, t) == x.
is_between
Returns true if x is within [lo, hi] (inclusive).
is_sorted
Check if a slice is sorted in non-decreasing order.
lerp
Linear interpolation between a and b.
lerp_angle
Shortest-path angular interpolation between a and b in radians.
lerp_clamped
Linear interpolation with t clamped to [0, 1].
lerp_inv
Inverse linear interpolation: find t such that lerp(a, b, t) == x.
map_range
Map a value from one range to another.
max_value
Maximum value in a slice. Returns None for an empty slice.
mean
Mean (average) of a slice. Returns None for an empty slice.
midpoint
Overflow-safe midpoint: (a + b) / 2 without intermediate overflow.
min_value
Minimum value in a slice. Returns None for an empty slice.
normalize
Normalize a vector (represented as a slice) to unit length.
nth_root
n-th root of x (any real n).
ping_pong
Ping-pong: triangle wave between 0 and length.
product
Product of a slice. Returns T::one() for an empty slice.
rad_to_deg
Convert radians to degrees.
rad_to_grad
Convert radians to gradians.
remap
Remap x from range [in_lo, in_hi] to [out_lo, out_hi].
remap_clamped
Remap x from [in_lo, in_hi] to [out_lo, out_hi] with output clamped.
repeat
Repeat x into [0, length).
sign
Sign as integer: -1, 0, or 1.
smootherstep
Smootherstep: C2 interpolation with zero derivatives at both ends.
smoothstep
Smoothstep: C1 interpolation with zero derivatives at both ends.
smoothstep_between
Parameterized smoothstep: C1 interpolation between edge0 and edge1.
snap
Snap x to the nearest multiple of step.
step
Heaviside step function: 0 if x < edge, 1 if x >= edge.
sum
Sum of a slice. Returns T::zero() for an empty slice.
trunc
Truncate toward zero.
wrap
Wrap x into the half-open interval [lo, hi).
wrap_angle
Normalize an angle in radians to [-pi, pi].
wrap_angle_positive
Wrap angle in radians to [0, 2pi).