v / vlib / math
Raw file | 12 loc (11 sloc) | 233 bytes | Latest commit hash 1cfc4198f
1module math
2
3[inline]
4pub fn q_rsqrt(x f64) f64 {
5 x_half := 0.5 * x
6 mut i := i64(f64_bits(x))
7 i = 0x5fe6eb50c7b537a9 - (i >> 1)
8 mut j := f64_from_bits(u64(i))
9 j *= (1.5 - x_half * j * j)
10 j *= (1.5 - x_half * j * j)
11 return j
12}