@@ -1469,15 +1469,15 @@ impl<T: FloatCore> PartialEq<T> for NotNan<T> {
1469
1469
1470
1470
/// Adds a float directly.
1471
1471
///
1472
- /// Panics if the provided value is NaN or the computation results in NaN
1473
- /* impl<T: FloatCore> Add<T> for NotNan<T> {
1474
- type Output = Self ;
1472
+ /// This returns a `T` and not a `NotNan<T>` because if the added value is NaN, this will be NaN
1473
+ impl < T : FloatCore > Add < T > for NotNan < T > {
1474
+ type Output = T ;
1475
1475
1476
1476
#[ inline]
1477
- fn add(self, other: T) -> Self {
1478
- NotNan::new( self.0 + other).expect("Addition resulted in NaN")
1477
+ fn add ( self , other : T ) -> Self :: Output {
1478
+ self . 0 + other
1479
1479
}
1480
- }*/
1480
+ }
1481
1481
1482
1482
/// Adds a float directly.
1483
1483
///
@@ -1497,27 +1497,29 @@ impl<'a, T: FloatCore + Sum + 'a> Sum<&'a NotNan<T>> for NotNan<T> {
1497
1497
1498
1498
/// Subtracts a float directly.
1499
1499
///
1500
- /// Panics if the provided value is NaN or the computation results in NaN
1501
- /*impl<T: FloatCore> Sub<T> for NotNan<T> {
1502
- type Output = Self;
1500
+ /// This returns a `T` and not a `NotNan<T>` because if the substracted value is NaN, this will be
1501
+ /// NaN
1502
+ impl < T : FloatCore > Sub < T > for NotNan < T > {
1503
+ type Output = T ;
1503
1504
1504
1505
#[ inline]
1505
- fn sub(self, other: T) -> Self {
1506
- NotNan::new( self.0 - other).expect("Subtraction resulted in NaN")
1506
+ fn sub ( self , other : T ) -> Self :: Output {
1507
+ self . 0 - other
1507
1508
}
1508
- }*/
1509
+ }
1509
1510
1510
1511
/// Multiplies a float directly.
1511
1512
///
1512
- /// Panics if the provided value is NaN or the computation results in NaN
1513
- /*impl<T: FloatCore> Mul<T> for NotNan<T> {
1514
- type Output = Self;
1513
+ /// This returns a `T` and not a `NotNan<T>` because if the multiplied value is NaN, this will be
1514
+ /// NaN
1515
+ impl < T : FloatCore > Mul < T > for NotNan < T > {
1516
+ type Output = T ;
1515
1517
1516
1518
#[ inline]
1517
- fn mul(self, other: T) -> Self {
1518
- NotNan::new( self.0 * other).expect("Multiplication resulted in NaN")
1519
+ fn mul ( self , other : T ) -> Self :: Output {
1520
+ self . 0 * other
1519
1521
}
1520
- }*/
1522
+ }
1521
1523
1522
1524
impl < T : FloatCore + Product > Product for NotNan < T > {
1523
1525
fn product < I : Iterator < Item = NotNan < T > > > ( iter : I ) -> Self {
@@ -1532,30 +1534,30 @@ impl<'a, T: FloatCore + Product + 'a> Product<&'a NotNan<T>> for NotNan<T> {
1532
1534
}
1533
1535
}
1534
1536
1535
- /*
1536
1537
/// Divides a float directly.
1537
1538
///
1538
- /// Panics if the provided value is NaN or the computation results in NaN
1539
+ /// This returns a `T` and not a `NotNan<T>` because if the divided-by value is NaN, this will be
1540
+ /// NaN
1539
1541
impl < T : FloatCore > Div < T > for NotNan < T > {
1540
- type Output = Self ;
1542
+ type Output = T ;
1541
1543
1542
1544
#[ inline]
1543
- fn div(self, other: T) -> Self {
1544
- NotNan::new( self.0 / other).expect("Division resulted in NaN")
1545
+ fn div ( self , other : T ) -> Self :: Output {
1546
+ self . 0 / other
1545
1547
}
1546
1548
}
1547
1549
1548
1550
/// Calculates `%` with a float directly.
1549
1551
///
1550
- /// Panics if the provided value is NaN or the computation results in NaN
1552
+ /// This returns a `T` and not a `NotNan<T>` because if the RHS is NaN, this will be NaN
1551
1553
impl < T : FloatCore > Rem < T > for NotNan < T > {
1552
- type Output = Self ;
1554
+ type Output = T ;
1553
1555
1554
1556
#[ inline]
1555
- fn rem(self, other: T) -> Self {
1556
- NotNan::new( self.0 % other).expect("Rem resulted in NaN")
1557
+ fn rem ( self , other : T ) -> Self :: Output {
1558
+ self . 0 % other
1557
1559
}
1558
- }*/
1560
+ }
1559
1561
1560
1562
macro_rules! impl_not_nan_binop {
1561
1563
( $imp: ident, $method: ident, $assign_imp: ident, $assign_method: ident) => {
@@ -1569,14 +1571,14 @@ macro_rules! impl_not_nan_binop {
1569
1571
}
1570
1572
}
1571
1573
1572
- /* impl<T: FloatCore> $imp<&T> for NotNan<T> {
1573
- type Output = NotNan<T> ;
1574
+ impl <T : FloatCore > $imp<& T > for NotNan <T > {
1575
+ type Output = T ;
1574
1576
1575
1577
#[ inline]
1576
1578
fn $method( self , other: & T ) -> Self :: Output {
1577
1579
self . $method( * other)
1578
1580
}
1579
- }*/
1581
+ }
1580
1582
1581
1583
impl <T : FloatCore > $imp<& Self > for NotNan <T > {
1582
1584
type Output = NotNan <T >;
@@ -1605,8 +1607,8 @@ macro_rules! impl_not_nan_binop {
1605
1607
}
1606
1608
}
1607
1609
1608
- /* impl<T: FloatCore> $imp<T> for &NotNan<T> {
1609
- type Output = NotNan<T> ;
1610
+ impl <T : FloatCore > $imp<T > for & NotNan <T > {
1611
+ type Output = T ;
1610
1612
1611
1613
#[ inline]
1612
1614
fn $method( self , other: T ) -> Self :: Output {
@@ -1615,28 +1617,14 @@ macro_rules! impl_not_nan_binop {
1615
1617
}
1616
1618
1617
1619
impl <T : FloatCore > $imp<& T > for & NotNan <T > {
1618
- type Output = NotNan<T> ;
1620
+ type Output = T ;
1619
1621
1620
1622
#[ inline]
1621
1623
fn $method( self , other: & T ) -> Self :: Output {
1622
1624
( * self ) . $method( * other)
1623
1625
}
1624
1626
}
1625
1627
1626
- impl<T: FloatCore + $assign_imp> $assign_imp<T> for NotNan<T> {
1627
- #[inline]
1628
- fn $assign_method(&mut self, other: T) {
1629
- *self = (*self).$method(other);
1630
- }
1631
- }
1632
-
1633
- impl<T: FloatCore + $assign_imp> $assign_imp<&T> for NotNan<T> {
1634
- #[inline]
1635
- fn $assign_method(&mut self, other: &T) {
1636
- *self = (*self).$method(*other);
1637
- }
1638
- }*/
1639
-
1640
1628
impl <T : FloatCore + $assign_imp> $assign_imp for NotNan <T > {
1641
1629
#[ inline]
1642
1630
fn $assign_method( & mut self , other: Self ) {
0 commit comments