1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Canonical float normalization functions
/// Canonical quiet NaN bit pattern for f64.
pub const CANONICAL_NAN_F64: u64 = 0x7ff8_0000_0000_0000;
/// Canonical quiet NaN bit pattern for f32.
pub const CANONICAL_NAN_F32: u32 = 0x7fc0_0000;
const ABS_MASK_F64: u64 = 0x7fff_ffff_ffff_ffff;
const EXP_MASK_F64: u64 = 0x7ff0_0000_0000_0000;
const ABS_MASK_F32: u32 = 0x7fff_ffff;
const EXP_MASK_F32: u32 = 0x7f80_0000;
/// Normalize an f64 value to canonical form for comparison.
///
/// Ensures that:
/// - All NaN variants map to the same canonical quiet NaN
/// - Negative zero (-0.0) maps to positive zero (+0.0)
/// - All other values are preserved exactly
///
/// The implementation is branchless and intended to lower to predictable
/// mask/`setcc`/`cmov` style code on modern CPUs.
/// Normalize an f32 value to canonical form for comparison.
///
/// Ensures that:
/// - All NaN variants map to the same canonical quiet NaN
/// - Negative zero (-0.0) maps to positive zero (+0.0)
/// - All other values are preserved exactly