extern crate serde; extern crate zlo; use zlo::Infinite; use zlo::deserialize; use zlo::serialize; /// Per-part integer subtraction of two f32s used for diffing. fn f32_diff(a: f32, b: f32) -> f32 { let sign_23 = |x| x | if (x & (1 << 22)) != 0 { 0xff800000 } else { 0 }; let frac_mask = (1 << 23) - 1; let a = a.to_bits(); let b = b.to_bits(); let sign = ((a >> 31) != 0) ^ ((b >> 31) != 0); let exp = ((a >> 23) as u8).wrapping_sub((b >> 23) as u8); let frac = sign_23(a & frac_mask) .wrapping_sub(sign_23(b & frac_mask)) & frac_mask; let bits = ((sign as u32) << 31) | ((exp as u32) << 23) | frac; f32::from_bits(bits) } /// Per-part integer subtraction of two f64s used for diffing. fn f64_diff(a: f64, b: f64) -> f64 { let sign_11 = |x| x | if (x & (1 << 10)) != 0 { 0xf800 } else { 0 }; let sign_52 = |x| x | if (x & (1 << 51)) != 0 { 0xfff0000000000000 } else { 0 }; let exp_mask = (1 << 11) - 1; let frac_mask = (1 << 52) - 1; let a = a.to_bits(); let b = b.to_bits(); let sign = ((a >> 63) != 0) ^ ((b >> 63) != 0); let exp = sign_11((a >> 52) as u16 & exp_mask) .wrapping_sub(sign_11((b >> 52) as u16 & exp_mask)) & exp_mask; let frac = sign_52(a & frac_mask) .wrapping_sub(sign_52(b & frac_mask)) & frac_mask; let bits = ((sign as u64) << 63) | ((exp as u64) << 52) | frac; f64::from_bits(bits) } fn main() { }