Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/zmij/tests/ryu_comparison.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / zmij / tests / ryu_comparison.rs` 36 lines ยท 946 bytes Raw Blame History 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 }