Skip to main content
← PSoXide SDK guides and examples · SDK f2fec1c301f1 · All Cargo features enabled; check feature gates before use.

normalize_classic_q12_scheduled

Function normalize_classic_q12_scheduled 

Source
pub fn normalize_classic_q12_scheduled(
    input: Vec3I32,
) -> ClassicNormalizedVector
Expand description

Scale a Q12 direction to length 4096 with a 192-entry reciprocal square root table, the classic fixed-point way.

Each component is floored to whole units (>> 12) and kept as 16 bits. With s the sum of their squares (wrapping i32):

  1. L = leading zero bits of s, rounded down to even.
  2. s shifted by L - 24 lands in 64..=255; the table gives r = floor(4096 * sqrt(64 / that)).
  3. Each component becomes (c * r) >> ((31 - L) / 2).

Because L is even, the table entry equals 4096 * 2^(15 - L/2) / sqrt(s), and the shift in step 3 removes that power of two exactly, leaving 4096 * c / sqrt(s) up to the table’s truncation. A zero or wrapped (negative) s gives a zero vector. Pure integer work: no GTE state is used.