Skip to content

Commit b6fe120

Browse files
committed
impl Bounded for OrderedFloat, NotNaN
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
1 parent b27bbd4 commit b6fe120

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::fmt;
1515
use std::io;
1616
use std::mem;
1717
use unreachable::unreachable;
18-
use num_traits::Float;
18+
use num_traits::{Bounded, Float};
1919

2020
// masks for the parts of the IEEE 754 float
2121
const SIGN_MASK: u64 = 0x8000000000000000u64;
@@ -137,6 +137,16 @@ impl<T: Float> DerefMut for OrderedFloat<T> {
137137

138138
impl<T: Float + PartialEq> Eq for OrderedFloat<T> {}
139139

140+
impl<T: Float> Bounded for OrderedFloat<T> {
141+
fn min_value() -> Self {
142+
OrderedFloat(T::min_value())
143+
}
144+
145+
fn max_value() -> Self {
146+
OrderedFloat(T::max_value())
147+
}
148+
}
149+
140150
/// A wrapper around Floats providing an implementation of Ord and Hash.
141151
///
142152
/// A NaN value cannot be stored in this type.
@@ -516,6 +526,16 @@ impl<T: Float> Neg for NotNaN<T> {
516526
}
517527
}
518528

529+
impl<T: Float> Bounded for NotNaN<T> {
530+
fn min_value() -> Self {
531+
NotNaN(T::min_value())
532+
}
533+
534+
fn max_value() -> Self {
535+
NotNaN(T::max_value())
536+
}
537+
}
538+
519539
/// An error indicating an attempt to construct NotNaN from a NaN
520540
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
521541
pub struct FloatIsNaN;

0 commit comments

Comments
 (0)