aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / zmij / tests / ryu_comparison.rs
| 1 | use rand::rngs::{SmallRng, SysRng}; |
| 2 | use rand::{Rng as _, SeedableRng as _}; |
| 3 | |
| 4 | const N: usize = if cfg!(miri) { |
| 5 | 500 |
| 6 | } else if let b"0" = opt_level::OPT_LEVEL.as_bytes() { |
| 7 | 1_000_000 |
| 8 | } else { |
| 9 | 100_000_000 |
| 10 | }; |
| 11 | |
| 12 | #[test] |
| 13 | fn ryu_comparison() { |
| 14 | let mut ryu_buffer = ryu::Buffer::new(); |
| 15 | let mut zmij_buffer = zmij::Buffer::new(); |
| 16 | let mut rng = SmallRng::try_from_rng(&mut SysRng).unwrap(); |
| 17 | let mut fail = 0; |
| 18 | |
| 19 | for _ in 0..N { |
| 20 | let bits = rng.next_u64(); |
| 21 | let float = f64::from_bits(bits); |
| 22 | let ryu = ryu_buffer.format(float); |
| 23 | let zmij = zmij_buffer.format(float); |
| 24 | let matches = if ryu.contains('e') && !ryu.contains("e-") { |
| 25 | ryu.split_once('e') == zmij.split_once("e+") |
| 26 | } else { |
| 27 | ryu == zmij |
| 28 | }; |
| 29 | if !matches { |
| 30 | eprintln!("RYU={ryu} ZMIJ={zmij}"); |
| 31 | fail += 1; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | assert!(fail == 0, "{fail} mismatches"); |
| 36 | } |