Name a constant better.
This commit is contained in:
parent
79b9bd5f49
commit
a9c2fb1d01
|
@ -8,16 +8,16 @@
|
||||||
/// - If either number is NaN, returns `u32::MAX`.
|
/// - If either number is NaN, returns `u32::MAX`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn ulp_diff(a: f32, b: f32) -> u32 {
|
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;
|
const INFINITY: u32 = 0x7f800000;
|
||||||
|
|
||||||
let a = a.to_bits();
|
let a = a.to_bits();
|
||||||
let b = b.to_bits();
|
let b = b.to_bits();
|
||||||
|
|
||||||
let a_sign = a & TOP_BIT;
|
let a_sign = a & SIGN_BIT;
|
||||||
let b_sign = b & TOP_BIT;
|
let b_sign = b & SIGN_BIT;
|
||||||
let a_abs = a & !TOP_BIT;
|
let a_abs = a & !SIGN_BIT;
|
||||||
let b_abs = b & !TOP_BIT;
|
let b_abs = b & !SIGN_BIT;
|
||||||
|
|
||||||
if a_abs > INFINITY || b_abs > INFINITY {
|
if a_abs > INFINITY || b_abs > INFINITY {
|
||||||
// NaNs always return maximum ulps apart.
|
// NaNs always return maximum ulps apart.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user