use round_to_nearest_ties_to_even to implement round
[vector-math.git] / src / prim.rs
index 41eca19ae8bbef3e6b0568ea4037832ec3770d5d..93c79400857899351c1ecb192ecb5f21380fed2f 100644 (file)
@@ -160,6 +160,8 @@ pub trait PrimFloat:
     }
     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;
 }
 
@@ -222,6 +224,13 @@ macro_rules! impl_float {
                 #[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);