add round_to_nearest_ties_to_even
[vector-math.git] / src / prim.rs
index 7f9fa30fd163464a29185c494292cb8d5787611e..41eca19ae8bbef3e6b0568ea4037832ec3770d5d 100644 (file)
@@ -86,6 +86,10 @@ pub trait PrimInt:
     + ops::ShlAssign
     + ops::ShrAssign
 {
+    const ZERO: Self;
+    const ONE: Self;
+    const MIN: Self;
+    const MAX: Self;
 }
 
 pub trait PrimUInt: PrimInt + ConvertFrom<Self::SignedType> {
@@ -100,8 +104,18 @@ macro_rules! impl_int {
     ($uint:ident, $sint:ident) => {
         impl PrimBase for $uint {}
         impl PrimBase for $sint {}
-        impl PrimInt for $uint {}
-        impl PrimInt for $sint {}
+        impl PrimInt for $uint {
+            const ZERO: Self = 0;
+            const ONE: Self = 1;
+            const MIN: Self = 0;
+            const MAX: Self = !0;
+        }
+        impl PrimInt for $sint {
+            const ZERO: Self = 0;
+            const ONE: Self = 1;
+            const MIN: Self = $sint::MIN;
+            const MAX: Self = $sint::MAX;
+        }
         impl PrimUInt for $uint {
             type SignedType = $sint;
         }
@@ -146,6 +160,7 @@ pub trait PrimFloat:
     }
     fn is_finite(self) -> bool;
     fn trunc(self) -> Self;
+    fn copy_sign(self, sign: Self) -> Self;
 }
 
 macro_rules! impl_float {
@@ -207,6 +222,12 @@ macro_rules! impl_float {
                 #[cfg(not(feature = "std"))]
                 return crate::algorithms::base::trunc(Scalar, Value(self)).0;
             }
+            fn copy_sign(self, sign: Self) -> Self {
+                #[cfg(feature = "std")]
+                return $float::copysign(self);
+                #[cfg(not(feature = "std"))]
+                return crate::algorithms::base::copy_sign(Scalar, Value(self), Value(sign)).0;
+            }
         }
     };
 }