add trunc implementation
[vector-math.git] / src / prim.rs
index 19f4270b2185d9099d3741e23be9f8b88a8326f5..7f9fa30fd163464a29185c494292cb8d5787611e 100644 (file)
@@ -1,5 +1,6 @@
 use crate::{
     f16::F16,
+    scalar::{Scalar, Value},
     traits::{ConvertFrom, ConvertTo},
 };
 use core::{fmt, hash, ops};
@@ -140,6 +141,11 @@ pub trait PrimFloat:
     fn from_bits(bits: Self::BitsType) -> Self;
     fn to_bits(self) -> Self::BitsType;
     fn abs(self) -> Self;
+    fn max_contiguous_integer() -> Self {
+        (Self::BitsType::cvt_from(1) << (Self::MANTISSA_FIELD_WIDTH + 1.to())).to()
+    }
+    fn is_finite(self) -> bool;
+    fn trunc(self) -> Self;
 }
 
 macro_rules! impl_float {
@@ -190,7 +196,16 @@ macro_rules! impl_float {
                 #[cfg(feature = "std")]
                 return $float::abs(self);
                 #[cfg(not(feature = "std"))]
-                todo!();
+                return crate::algorithms::base::abs(Scalar, Value(self)).0;
+            }
+            fn is_finite(self) -> bool {
+                $float::is_finite(self)
+            }
+            fn trunc(self) -> Self {
+                #[cfg(feature = "std")]
+                return $float::trunc(self);
+                #[cfg(not(feature = "std"))]
+                return crate::algorithms::base::trunc(Scalar, Value(self)).0;
             }
         }
     };