Skip to content

Commit f9fd9a7

Browse files
committed
Remove evil impls
1 parent facb424 commit f9fd9a7

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

src/lib.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,10 +1227,7 @@ impl<T: FloatCore + Num> Num for OrderedFloat<T> {
12271227
/// ```
12281228
/// use ordered_float::NotNan;
12291229
///
1230-
/// let mut v = [
1231-
/// NotNan::new(2.0).unwrap(),
1232-
/// NotNan::new(1.0).unwrap(),
1233-
/// ];
1230+
/// let mut v = [NotNan::new(2.0).unwrap(), NotNan::new(1.0).unwrap()];
12341231
/// v.sort();
12351232
/// assert_eq!(v, [1.0, 2.0]);
12361233
/// ```
@@ -1270,7 +1267,6 @@ impl<T: FloatCore + Num> Num for OrderedFloat<T> {
12701267
/// [transmute](core::mem::transmute) or pointer casts to convert between any type `T` and
12711268
/// `NotNan<T>`, as long as this does not create a NaN value.
12721269
/// However, consider using [`bytemuck`] as a safe alternative if possible.
1273-
///
12741270
#[cfg_attr(
12751271
not(feature = "bytemuck"),
12761272
doc = "[`bytemuck`]: https://docs.rs/bytemuck/1/"
@@ -1384,9 +1380,10 @@ impl NotNan<f64> {
13841380
/// Note: For the reverse conversion (from `NotNan<f32>` to `NotNan<f64>`), you can use
13851381
/// `.into()`.
13861382
pub fn as_f32(self) -> NotNan<f32> {
1387-
// This is not destroying invariants, as it is a pure rounding operation. The only two special
1388-
// cases are where f32 would be overflowing, then the operation yields Infinity, or where
1389-
// the input is already NaN, in which case the invariant is already broken elsewhere.
1383+
// This is not destroying invariants, as it is a pure rounding operation. The only two
1384+
// special cases are where f32 would be overflowing, then the operation yields
1385+
// Infinity, or where the input is already NaN, in which case the invariant is
1386+
// already broken elsewhere.
13901387
NotNan(self.0 as f32)
13911388
}
13921389
}
@@ -1473,14 +1470,14 @@ impl<T: FloatCore> PartialEq<T> for NotNan<T> {
14731470
/// Adds a float directly.
14741471
///
14751472
/// Panics if the provided value is NaN or the computation results in NaN
1476-
impl<T: FloatCore> Add<T> for NotNan<T> {
1473+
/*impl<T: FloatCore> Add<T> for NotNan<T> {
14771474
type Output = Self;
14781475
14791476
#[inline]
14801477
fn add(self, other: T) -> Self {
14811478
NotNan::new(self.0 + other).expect("Addition resulted in NaN")
14821479
}
1483-
}
1480+
}*/
14841481

14851482
/// Adds a float directly.
14861483
///
@@ -1501,26 +1498,26 @@ impl<'a, T: FloatCore + Sum + 'a> Sum<&'a NotNan<T>> for NotNan<T> {
15011498
/// Subtracts a float directly.
15021499
///
15031500
/// Panics if the provided value is NaN or the computation results in NaN
1504-
impl<T: FloatCore> Sub<T> for NotNan<T> {
1501+
/*impl<T: FloatCore> Sub<T> for NotNan<T> {
15051502
type Output = Self;
15061503
15071504
#[inline]
15081505
fn sub(self, other: T) -> Self {
15091506
NotNan::new(self.0 - other).expect("Subtraction resulted in NaN")
15101507
}
1511-
}
1508+
}*/
15121509

15131510
/// Multiplies a float directly.
15141511
///
15151512
/// Panics if the provided value is NaN or the computation results in NaN
1516-
impl<T: FloatCore> Mul<T> for NotNan<T> {
1513+
/*impl<T: FloatCore> Mul<T> for NotNan<T> {
15171514
type Output = Self;
15181515
15191516
#[inline]
15201517
fn mul(self, other: T) -> Self {
15211518
NotNan::new(self.0 * other).expect("Multiplication resulted in NaN")
15221519
}
1523-
}
1520+
}*/
15241521

15251522
impl<T: FloatCore + Product> Product for NotNan<T> {
15261523
fn product<I: Iterator<Item = NotNan<T>>>(iter: I) -> Self {
@@ -1535,6 +1532,7 @@ impl<'a, T: FloatCore + Product + 'a> Product<&'a NotNan<T>> for NotNan<T> {
15351532
}
15361533
}
15371534

1535+
/*
15381536
/// Divides a float directly.
15391537
///
15401538
/// Panics if the provided value is NaN or the computation results in NaN
@@ -1557,7 +1555,7 @@ impl<T: FloatCore> Rem<T> for NotNan<T> {
15571555
fn rem(self, other: T) -> Self {
15581556
NotNan::new(self.0 % other).expect("Rem resulted in NaN")
15591557
}
1560-
}
1558+
}*/
15611559

15621560
macro_rules! impl_not_nan_binop {
15631561
($imp:ident, $method:ident, $assign_imp:ident, $assign_method:ident) => {
@@ -1566,25 +1564,26 @@ macro_rules! impl_not_nan_binop {
15661564

15671565
#[inline]
15681566
fn $method(self, other: Self) -> Self {
1569-
self.$method(other.0)
1567+
NotNan::new(self.0.$method(other.0))
1568+
.expect("Operation on two NotNan resulted in NaN")
15701569
}
15711570
}
15721571

1573-
impl<T: FloatCore> $imp<&T> for NotNan<T> {
1572+
/*impl<T: FloatCore> $imp<&T> for NotNan<T> {
15741573
type Output = NotNan<T>;
15751574
15761575
#[inline]
15771576
fn $method(self, other: &T) -> Self::Output {
15781577
self.$method(*other)
15791578
}
1580-
}
1579+
}*/
15811580

15821581
impl<T: FloatCore> $imp<&Self> for NotNan<T> {
15831582
type Output = NotNan<T>;
15841583

15851584
#[inline]
15861585
fn $method(self, other: &Self) -> Self::Output {
1587-
self.$method(other.0)
1586+
self.$method(*other)
15881587
}
15891588
}
15901589

@@ -1593,7 +1592,7 @@ macro_rules! impl_not_nan_binop {
15931592

15941593
#[inline]
15951594
fn $method(self, other: Self) -> Self::Output {
1596-
(*self).$method(other.0)
1595+
(*self).$method(*other)
15971596
}
15981597
}
15991598

@@ -1602,11 +1601,11 @@ macro_rules! impl_not_nan_binop {
16021601

16031602
#[inline]
16041603
fn $method(self, other: NotNan<T>) -> Self::Output {
1605-
(*self).$method(other.0)
1604+
(*self).$method(other)
16061605
}
16071606
}
16081607

1609-
impl<T: FloatCore> $imp<T> for &NotNan<T> {
1608+
/*impl<T: FloatCore> $imp<T> for &NotNan<T> {
16101609
type Output = NotNan<T>;
16111610
16121611
#[inline]
@@ -1636,19 +1635,19 @@ macro_rules! impl_not_nan_binop {
16361635
fn $assign_method(&mut self, other: &T) {
16371636
*self = (*self).$method(*other);
16381637
}
1639-
}
1638+
}*/
16401639

16411640
impl<T: FloatCore + $assign_imp> $assign_imp for NotNan<T> {
16421641
#[inline]
16431642
fn $assign_method(&mut self, other: Self) {
1644-
(*self).$assign_method(other.0);
1643+
*self = (*self).$method(other);
16451644
}
16461645
}
16471646

16481647
impl<T: FloatCore + $assign_imp> $assign_imp<&Self> for NotNan<T> {
16491648
#[inline]
16501649
fn $assign_method(&mut self, other: &Self) {
1651-
(*self).$assign_method(other.0);
1650+
*self = (*self).$method(*other);
16521651
}
16531652
}
16541653
};

0 commit comments

Comments
 (0)