def rng_ln_w
import bend-ml-tensor-gpu@0.1.5.1/main.bend as BendMlTensorGpuimport Base
630# ln x for a positive normal x: x = m * 2^ex with m in [sqrt(1/2), sqrt(2)) read from the bits (a mantissa above
631# sqrt(2)'s, 0x3504F3, is halved and the exponent raised by one); ex * ln 2 in two parts, the first exact
632def rng_ln_w(+w: U32) -> F32:
633 +big = U32.is_lt(3474675, U32.and(w, 8388607))
634 +mb = U32.or(U32.and(w, 8388607), Bool.pick(U32, big, 1056964608, 1065353216))
635 rng_ln_m((U32.to_f32(U32.shrn(w, 23n)) - Bool.pick(F32, big, 126.0, 127.0) : F32), rng_f32(mb))