Skip to content

Commit 9dbcd5b

Browse files
committed
Fix bug where MIN_POSITIVE should be used instead of MIN
1 parent 1b99941 commit 9dbcd5b

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/math/float.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub trait Float:
5151
+ for<'a> std::iter::Sum<&'a Self>
5252
+ Sealed {
5353
const MIN: Self;
54+
const MIN_POSITIVE: Self;
5455
const MAX: Self;
5556
const ZERO: Self;
5657
const ONE: Self;
@@ -80,6 +81,7 @@ macro_rules! impl_float {
8081
$(
8182
impl Float for $ty {
8283
const MIN: Self = <$ty>::MIN;
84+
const MIN_POSITIVE: Self = <$ty>::MIN_POSITIVE;
8385
const MAX: Self = <$ty>::MAX;
8486
const ZERO: Self = 0.0;
8587
const ONE: Self = 1.0;
@@ -153,10 +155,10 @@ where
153155
if a == b {
154156
// shortcut, handles infinities
155157
true
156-
} else if a == zero || b == zero || (abs_a + abs_b < Self::MIN) {
158+
} else if a == zero || b == zero || (abs_a + abs_b < Self::MIN_POSITIVE) {
157159
// a or b is zero or both are extremely close to it
158160
// relative error is less meaningful here
159-
diff < eps * Self::MIN
161+
diff < eps * Self::MIN_POSITIVE
160162
} else {
161163
// use relative error
162164
diff / (abs_a + abs_b).min(Self::MAX) < eps

0 commit comments

Comments
 (0)