pub(crate) struct Rng(pub(crate) u64);
impl Rng {
pub(crate) fn next(&mut self) -> u64 {
self.0 ^= self.0 << 13;
self.0 ^= self.0 >> 7;
self.0 ^= self.0 << 17;
self.0
}
pub(crate) fn f32(&mut self) -> f32 {
(self.next() >> 40) as f32 / (1u64 << 23) as f32 - 1.0
}
pub(crate) fn vec(&mut self, n: usize) -> Vec<f32> {
(0..n).map(|_| self.f32()).collect()
}
}
pub(crate) fn close(got: &[f32], want: &[f32], tol: f32, what: &str) {
assert_eq!(got.len(), want.len(), "{what}: lengths");
for (i, (g, w)) in got.iter().zip(want).enumerate() {
assert!((g - w).abs() <= tol * w.abs().max(1.0), "{what}[{i}]: {g} against {w}");
}
}