X-Git-Url: https://git.libre-soc.org/?p=vector-math.git;a=blobdiff_plain;f=src%2Ftraits.rs;h=6555016d98793e1c70b8715fe85e5f3f3a5878cf;hp=ffc766b81007113f57da2355fcba0330cc25b332;hb=ad217eb300ff1d610689c9ebe5b06e94b659a508;hpb=211dd475c41a76b11e4c5b3dcf7fc5b2c0babaf9 diff --git a/src/traits.rs b/src/traits.rs index ffc766b..6555016 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -187,9 +187,18 @@ pub trait Float: Number + Neg { fn trunc(self) -> Self; fn ceil(self) -> Self; fn floor(self) -> Self; + /// round to nearest integer, unspecified which way half-way cases are rounded fn round(self) -> Self; + /// returns `self * a + b` but only rounding once #[cfg(feature = "fma")] fn fma(self, a: Self, b: Self) -> Self; + /// returns `self * a + b` either using `fma` or `self * a + b` + fn mul_add_fast(self, a: Self, b: Self) -> Self { + #[cfg(feature = "fma")] + return self.fma(a, b); + #[cfg(not(feature = "fma"))] + return self * a + b; + } fn is_nan(self) -> Self::Bool { self.ne(self) }