Name a constant better.

This commit is contained in:
Nathan Vegdahl 2023-08-04 00:51:02 +02:00
parent 79b9bd5f49
commit a9c2fb1d01

View File

@ -8,16 +8,16 @@
/// - If either number is NaN, returns `u32::MAX`.
#[inline(always)]
pub fn ulp_diff(a: f32, b: f32) -> u32 {
const TOP_BIT: u32 = 1 << 31;
const SIGN_BIT: u32 = 1 << 31;
const INFINITY: u32 = 0x7f800000;
let a = a.to_bits();
let b = b.to_bits();
let a_sign = a & TOP_BIT;
let b_sign = b & TOP_BIT;
let a_abs = a & !TOP_BIT;
let b_abs = b & !TOP_BIT;
let a_sign = a & SIGN_BIT;
let b_sign = b & SIGN_BIT;
let a_abs = a & !SIGN_BIT;
let b_abs = b & !SIGN_BIT;
if a_abs > INFINITY || b_abs > INFINITY {
// NaNs always return maximum ulps apart.