Skip to content

Commit dc3b2a2

Browse files
committed
Merge branch 'alexheretic-master'
2 parents dddd3d8 + 7ce968f commit dc3b2a2

File tree

4 files changed

+1013
-606
lines changed

4 files changed

+1013
-606
lines changed

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[package]
2-
32
name = "ordered-float"
43
version = "0.5.0"
54
authors = ["Jonathan Reem <jonathan.reem@gmail.com>"]
@@ -8,10 +7,9 @@ description = "Wrappers for total ordering on floats."
87
repository = "https://github.com/reem/rust-ordered-float"
98

109
[dependencies]
11-
num-traits = { version = "0.1", default_features = false }
10+
num-traits = "0.2"
1211
serde = { version = "1.0", optional = true }
13-
unreachable = "0.1"
12+
unreachable = "1"
1413

1514
[dev-dependencies]
16-
stainless = "0.1"
1715
serde_test = "1.0"

src/lib.rs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ impl<T: Float> AsMut<T> for OrderedFloat<T> {
6666
}
6767
}
6868

69-
impl<T: Float + PartialOrd> PartialOrd for OrderedFloat<T> {
69+
impl<T: Float> PartialOrd for OrderedFloat<T> {
7070
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
7171
Some(self.cmp(other))
7272
}
7373
}
7474

75-
impl<T: Float + PartialOrd> Ord for OrderedFloat<T> {
75+
impl<T: Float> Ord for OrderedFloat<T> {
7676
fn cmp(&self, other: &Self) -> Ordering {
7777
let lhs = self.as_ref();
7878
let rhs = other.as_ref();
@@ -96,7 +96,7 @@ impl<T: Float + PartialOrd> Ord for OrderedFloat<T> {
9696
impl<T: Float + PartialEq> PartialEq for OrderedFloat<T> {
9797
fn eq(&self, other: &OrderedFloat<T>) -> bool {
9898
if self.as_ref().is_nan() {
99-
if other.as_ref().is_nan() { true } else { false }
99+
other.as_ref().is_nan()
100100
} else if other.as_ref().is_nan() {
101101
false
102102
} else {
@@ -195,7 +195,7 @@ impl<T: Float> AsRef<T> for NotNan<T> {
195195
}
196196
}
197197

198-
impl<T: Float + PartialOrd> Ord for NotNan<T> {
198+
impl<T: Float> Ord for NotNan<T> {
199199
fn cmp(&self, other: &NotNan<T>) -> Ordering {
200200
match self.partial_cmp(&other) {
201201
Some(ord) => ord,
@@ -541,7 +541,7 @@ pub struct FloatIsNan;
541541

542542
impl Error for FloatIsNan {
543543
fn description(&self) -> &str {
544-
return "NotNan constructed with NaN";
544+
"NotNan constructed with NaN"
545545
}
546546
}
547547

@@ -578,43 +578,43 @@ fn raw_double_bits<F: Float>(f: &F) -> u64 {
578578
(man & MAN_MASK) | ((exp_u64 << 52) & EXP_MASK) | ((sign_u64 << 63) & SIGN_MASK)
579579
}
580580

581-
impl<T: Float + Zero> Zero for NotNaN<T> {
582-
fn zero() -> Self { NotNaN(T::zero()) }
581+
impl<T: Float + Zero> Zero for NotNan<T> {
582+
fn zero() -> Self { NotNan(T::zero()) }
583583

584584
fn is_zero(&self) -> bool { self.0.is_zero() }
585585
}
586586

587-
impl<T: Float + One> One for NotNaN<T> {
588-
fn one() -> Self { NotNaN(T::one()) }
587+
impl<T: Float + One> One for NotNan<T> {
588+
fn one() -> Self { NotNan(T::one()) }
589589
}
590590

591-
impl<T: Float + Bounded> Bounded for NotNaN<T> {
591+
impl<T: Float + Bounded> Bounded for NotNan<T> {
592592
fn min_value() -> Self {
593-
NotNaN(Bounded::min_value())
593+
NotNan(Bounded::min_value())
594594
}
595595

596596
fn max_value() -> Self {
597-
NotNaN(Bounded::max_value())
597+
NotNan(Bounded::max_value())
598598
}
599599
}
600600

601-
impl<T: Float + FromPrimitive> FromPrimitive for NotNaN<T> {
602-
fn from_i64(n: i64) -> Option<Self> { T::from_i64(n).and_then(|n| NotNaN::new(n).ok()) }
603-
fn from_u64(n: u64) -> Option<Self> { T::from_u64(n).and_then(|n| NotNaN::new(n).ok()) }
601+
impl<T: Float + FromPrimitive> FromPrimitive for NotNan<T> {
602+
fn from_i64(n: i64) -> Option<Self> { T::from_i64(n).and_then(|n| NotNan::new(n).ok()) }
603+
fn from_u64(n: u64) -> Option<Self> { T::from_u64(n).and_then(|n| NotNan::new(n).ok()) }
604604

605-
fn from_isize(n: isize) -> Option<Self> { T::from_isize(n).and_then(|n| NotNaN::new(n).ok()) }
606-
fn from_i8(n: i8) -> Option<Self> { T::from_i8(n).and_then(|n| NotNaN::new(n).ok()) }
607-
fn from_i16(n: i16) -> Option<Self> { T::from_i16(n).and_then(|n| NotNaN::new(n).ok()) }
608-
fn from_i32(n: i32) -> Option<Self> { T::from_i32(n).and_then(|n| NotNaN::new(n).ok()) }
609-
fn from_usize(n: usize) -> Option<Self> { T::from_usize(n).and_then(|n| NotNaN::new(n).ok()) }
610-
fn from_u8(n: u8) -> Option<Self> { T::from_u8(n).and_then(|n| NotNaN::new(n).ok()) }
611-
fn from_u16(n: u16) -> Option<Self> { T::from_u16(n).and_then(|n| NotNaN::new(n).ok()) }
612-
fn from_u32(n: u32) -> Option<Self> { T::from_u32(n).and_then(|n| NotNaN::new(n).ok()) }
613-
fn from_f32(n: f32) -> Option<Self> { T::from_f32(n).and_then(|n| NotNaN::new(n).ok()) }
614-
fn from_f64(n: f64) -> Option<Self> { T::from_f64(n).and_then(|n| NotNaN::new(n).ok()) }
605+
fn from_isize(n: isize) -> Option<Self> { T::from_isize(n).and_then(|n| NotNan::new(n).ok()) }
606+
fn from_i8(n: i8) -> Option<Self> { T::from_i8(n).and_then(|n| NotNan::new(n).ok()) }
607+
fn from_i16(n: i16) -> Option<Self> { T::from_i16(n).and_then(|n| NotNan::new(n).ok()) }
608+
fn from_i32(n: i32) -> Option<Self> { T::from_i32(n).and_then(|n| NotNan::new(n).ok()) }
609+
fn from_usize(n: usize) -> Option<Self> { T::from_usize(n).and_then(|n| NotNan::new(n).ok()) }
610+
fn from_u8(n: u8) -> Option<Self> { T::from_u8(n).and_then(|n| NotNan::new(n).ok()) }
611+
fn from_u16(n: u16) -> Option<Self> { T::from_u16(n).and_then(|n| NotNan::new(n).ok()) }
612+
fn from_u32(n: u32) -> Option<Self> { T::from_u32(n).and_then(|n| NotNan::new(n).ok()) }
613+
fn from_f32(n: f32) -> Option<Self> { T::from_f32(n).and_then(|n| NotNan::new(n).ok()) }
614+
fn from_f64(n: f64) -> Option<Self> { T::from_f64(n).and_then(|n| NotNan::new(n).ok()) }
615615
}
616616

617-
impl<T: Float + ToPrimitive> ToPrimitive for NotNaN<T> {
617+
impl<T: Float + ToPrimitive> ToPrimitive for NotNan<T> {
618618
fn to_i64(&self) -> Option<i64> { self.0.to_i64() }
619619
fn to_u64(&self) -> Option<u64> { self.0.to_u64() }
620620

@@ -630,52 +630,52 @@ impl<T: Float + ToPrimitive> ToPrimitive for NotNaN<T> {
630630
fn to_f64(&self) -> Option<f64> { self.0.to_f64() }
631631
}
632632

633-
/// An error indicating a parse error from a string for `NotNaN`.
633+
/// An error indicating a parse error from a string for `NotNan`.
634634
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
635-
pub enum ParseNotNaNError<E> {
635+
pub enum ParseNotNanError<E> {
636636
/// A plain parse error from the underlying float type.
637637
ParseFloatError(E),
638638
/// The parsed float value resulted in a NaN.
639639
IsNaN,
640640
}
641641

642-
impl<E: fmt::Debug> Error for ParseNotNaNError<E> {
642+
impl<E: fmt::Debug> Error for ParseNotNanError<E> {
643643
fn description(&self) -> &str {
644644
return "Error parsing a not-NaN floating point value";
645645
}
646646
}
647647

648-
impl<E: fmt::Debug> fmt::Display for ParseNotNaNError<E> {
648+
impl<E: fmt::Debug> fmt::Display for ParseNotNanError<E> {
649649
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
650650
<Self as fmt::Debug>::fmt(self, f)
651651
}
652652
}
653653

654-
impl<T: Float + Num> Num for NotNaN<T> {
655-
type FromStrRadixErr = ParseNotNaNError<T::FromStrRadixErr>;
654+
impl<T: Float + Num> Num for NotNan<T> {
655+
type FromStrRadixErr = ParseNotNanError<T::FromStrRadixErr>;
656656

657657
fn from_str_radix(src: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> {
658658
T::from_str_radix(src, radix)
659-
.map_err(|err| ParseNotNaNError::ParseFloatError(err))
660-
.and_then(|n| NotNaN::new(n).map_err(|_| ParseNotNaNError::IsNaN))
659+
.map_err(|err| ParseNotNanError::ParseFloatError(err))
660+
.and_then(|n| NotNan::new(n).map_err(|_| ParseNotNanError::IsNaN))
661661
}
662662
}
663663

664-
impl<T: Float + Signed> Signed for NotNaN<T> {
665-
fn abs(&self) -> Self { NotNaN(self.0.abs()) }
664+
impl<T: Float + Signed> Signed for NotNan<T> {
665+
fn abs(&self) -> Self { NotNan(self.0.abs()) }
666666

667667
fn abs_sub(&self, other: &Self) -> Self {
668-
NotNaN::new(self.0.abs_sub(other.0)).expect("Subtraction resulted in NaN")
668+
NotNan::new(self.0.abs_sub(other.0)).expect("Subtraction resulted in NaN")
669669
}
670670

671-
fn signum(&self) -> Self { NotNaN(self.0.signum()) }
671+
fn signum(&self) -> Self { NotNan(self.0.signum()) }
672672
fn is_positive(&self) -> bool { self.0.is_positive() }
673673
fn is_negative(&self) -> bool { self.0.is_negative() }
674674
}
675675

676-
impl<T: Float + NumCast> NumCast for NotNaN<T> {
676+
impl<T: Float + NumCast> NumCast for NotNan<T> {
677677
fn from<F: ToPrimitive>(n: F) -> Option<Self> {
678-
T::from(n).and_then(|n| NotNaN::new(n).ok())
678+
T::from(n).and_then(|n| NotNan::new(n).ok())
679679
}
680680
}
681681

0 commit comments

Comments
 (0)