@@ -1469,15 +1469,15 @@ impl<T: FloatCore> PartialEq<T> for NotNan<T> {
14691469
14701470/// Adds a float directly.
14711471///
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 ;
14751475
14761476 #[ 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
14791479 }
1480- }*/
1480+ }
14811481
14821482/// Adds a float directly.
14831483///
@@ -1497,27 +1497,29 @@ impl<'a, T: FloatCore + Sum + 'a> Sum<&'a NotNan<T>> for NotNan<T> {
14971497
14981498/// Subtracts a float directly.
14991499///
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 ;
15031504
15041505 #[ 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
15071508 }
1508- }*/
1509+ }
15091510
15101511/// Multiplies a float directly.
15111512///
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 ;
15151517
15161518 #[ 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
15191521 }
1520- }*/
1522+ }
15211523
15221524impl < T : FloatCore + Product > Product for NotNan < T > {
15231525 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> {
15321534 }
15331535}
15341536
1535- /*
15361537/// Divides a float directly.
15371538///
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
15391541impl < T : FloatCore > Div < T > for NotNan < T > {
1540- type Output = Self ;
1542+ type Output = T ;
15411543
15421544 #[ 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
15451547 }
15461548}
15471549
15481550/// Calculates `%` with a float directly.
15491551///
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
15511553impl < T : FloatCore > Rem < T > for NotNan < T > {
1552- type Output = Self ;
1554+ type Output = T ;
15531555
15541556 #[ 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
15571559 }
1558- }*/
1560+ }
15591561
15601562macro_rules! impl_not_nan_binop {
15611563 ( $imp: ident, $method: ident, $assign_imp: ident, $assign_method: ident) => {
@@ -1569,14 +1571,14 @@ macro_rules! impl_not_nan_binop {
15691571 }
15701572 }
15711573
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 ;
15741576
15751577 #[ inline]
15761578 fn $method( self , other: & T ) -> Self :: Output {
15771579 self . $method( * other)
15781580 }
1579- }*/
1581+ }
15801582
15811583 impl <T : FloatCore > $imp<& Self > for NotNan <T > {
15821584 type Output = NotNan <T >;
@@ -1605,8 +1607,8 @@ macro_rules! impl_not_nan_binop {
16051607 }
16061608 }
16071609
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 ;
16101612
16111613 #[ inline]
16121614 fn $method( self , other: T ) -> Self :: Output {
@@ -1615,28 +1617,14 @@ macro_rules! impl_not_nan_binop {
16151617 }
16161618
16171619 impl <T : FloatCore > $imp<& T > for & NotNan <T > {
1618- type Output = NotNan<T> ;
1620+ type Output = T ;
16191621
16201622 #[ inline]
16211623 fn $method( self , other: & T ) -> Self :: Output {
16221624 ( * self ) . $method( * other)
16231625 }
16241626 }
16251627
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-
16401628 impl <T : FloatCore + $assign_imp> $assign_imp for NotNan <T > {
16411629 #[ inline]
16421630 fn $assign_method( & mut self , other: Self ) {
0 commit comments