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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const TWO_COMPLEMENT: u32 = 0x8000_0000_u32;
const TWO_COMPLEMENT_CI: i32 = TWO_COMPLEMENT as i32;
// Compares two f32 values for approximate equality
// Use ULP (Units in the Last Place) comparison.
pub const FLOAT_INT_EPS: u32 = 10;
/// Compares two f32 values for equality using ULP-based comparison.
/// This is needed for backwards compatibility and mixed precision scenarios.
// #[doc(hidden)]
// #[inline]
// #[must_use]
// pub fn float_equal(a: f32, b: f32) -> bool {
// almost_equal_as_int(a, b, FLOAT_INT_EPS)
// }
// ULP-based functions deprecated in favor of FloatInterval
// Commented out for now to preserve existing functionality
/*
#[doc(hidden)]
#[must_use]
pub fn float_perturbed_as_int(f: f32, c: i32) -> f32 {
debug_assert!(f.is_finite());
if c == 0 {
return f;
}
// Special cases for zero crossings in ULP ordering:
// +0.0 with -1 perturbation should give -0.0
// -0.0 with +1 perturbation should give +0.0
if f == 0.0 && c == -1 {
return -0.0;
}
if f == -0.0 && c == 1 {
return 0.0;
}
// Convert to the same lexicographically ordered space as almost_equal_as_int
let f_bits = f.to_bits();
let f_i = f_bits as i32;
// Convert to lexicographically ordered space (same as almost_equal_as_int)
let lex_value = if f_i < 0 {
TWO_COMPLEMENT_CI - f_i
} else {
f_i
};
// Apply perturbation in lexicographic space
let result_lex = lex_value + c;
// Convert back from lexicographically ordered space to IEEE float bits
let result_bits = if result_lex < 0 {
// Result is negative in lex space, convert back to IEEE negative representation
(TWO_COMPLEMENT_CI - result_lex) as u32
} else {
// Result is positive in lex space, it's already in IEEE positive representation
result_lex as u32
};
f32::from_bits(result_bits)
}
//
// DEPRECATED: Old ULP-based float stepping functions
// Replaced with fixed-step FloatInterval for predictable precision
//
/*
#[must_use]
pub fn float_prev(f: f32) -> f32 {
let eps = -(FLOAT_INT_EPS as i32) - 1;
float_perturbed_as_int(f, eps)
}
#[must_use]
pub fn float_next(f: f32) -> f32 {
let eps = FLOAT_INT_EPS as i32 + 1;
float_perturbed_as_int(f, eps)
}
*/
*/
// // Transform float interval [a,b] to integer range
// let scale = determine_optimal_scale();
// let int_a = (asinh(a / scale) * INT_SCALE) as i32;
// let int_b = (asinh(b / scale) * INT_SCALE) as i32;
// // Create integer variable with range [int_a, int_b]
// // Apply integer constraints
// // Convert back: float_result = scale * sinh(int_result / INT_SCALE)