use round_to_nearest_ties_to_even to implement round
authorJacob Lifshay <programmerjake@gmail.com>
Fri, 14 May 2021 01:20:34 +0000 (18:20 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Fri, 14 May 2021 01:20:34 +0000 (18:20 -0700)
src/f16.rs
src/prim.rs
src/scalar.rs

index 4609c58264a7979bd4aa01f4b76501de553c874b..1ed978d25c59fcddaee617d04a3f179164a5633a 100644 (file)
@@ -226,11 +226,9 @@ impl F16 {
         #[cfg(not(feature = "std"))]
         todo!();
     }
         #[cfg(not(feature = "std"))]
         todo!();
     }
+    /// round to nearest, ties to unspecified
     pub fn round(self) -> Self {
     pub fn round(self) -> Self {
-        #[cfg(feature = "std")]
-        return f32::from(self).round().to();
-        #[cfg(not(feature = "std"))]
-        todo!();
+        return PrimFloat::round(f32::from(self)).to();
     }
     #[cfg(feature = "fma")]
     pub fn fma(self, a: Self, b: Self) -> Self {
     }
     #[cfg(feature = "fma")]
     pub fn fma(self, a: Self, b: Self) -> Self {
index 41eca19ae8bbef3e6b0568ea4037832ec3770d5d..93c79400857899351c1ecb192ecb5f21380fed2f 100644 (file)
@@ -160,6 +160,8 @@ pub trait PrimFloat:
     }
     fn is_finite(self) -> bool;
     fn trunc(self) -> Self;
     }
     fn is_finite(self) -> bool;
     fn trunc(self) -> Self;
+    /// round to nearest, ties to unspecified
+    fn round(self) -> Self;
     fn copy_sign(self, sign: Self) -> Self;
 }
 
     fn copy_sign(self, sign: Self) -> Self;
 }
 
@@ -222,6 +224,13 @@ macro_rules! impl_float {
                 #[cfg(not(feature = "std"))]
                 return crate::algorithms::base::trunc(Scalar, Value(self)).0;
             }
                 #[cfg(not(feature = "std"))]
                 return crate::algorithms::base::trunc(Scalar, Value(self)).0;
             }
+            fn round(self) -> Self {
+                #[cfg(feature = "std")]
+                return $float::round(self);
+                #[cfg(not(feature = "std"))]
+                return crate::algorithms::base::round_to_nearest_ties_to_even(Scalar, Value(self))
+                    .0;
+            }
             fn copy_sign(self, sign: Self) -> Self {
                 #[cfg(feature = "std")]
                 return $float::copysign(self);
             fn copy_sign(self, sign: Self) -> Self {
                 #[cfg(feature = "std")]
                 return $float::copysign(self);
index c1a1ec94c2b59608d8bd40476670185aa5734434..3011df707fc97c6e31cdcb430d504652c7cea0d5 100644 (file)
@@ -380,7 +380,7 @@ macro_rules! impl_float {
                 #[cfg(feature = "std")]
                 return Value(self.0.round());
                 #[cfg(not(feature = "std"))]
                 #[cfg(feature = "std")]
                 return Value(self.0.round());
                 #[cfg(not(feature = "std"))]
-                todo!();
+                return crate::algorithms::base::round_to_nearest_ties_to_even(Scalar, self);
             }
             #[cfg(feature = "fma")]
             fn fma(self, a: Self, b: Self) -> Self {
             }
             #[cfg(feature = "fma")]
             fn fma(self, a: Self, b: Self) -> Self {