瀏覽代碼

Impl MulAdd+MulAssign with libm fallback

Yoan Lecoq 6 年之前
父節點
當前提交
4d3cb0a4ba
共有 1 個文件被更改,包括 38 次插入0 次删除
  1. 38 0
      src/ops/mul_add.rs

+ 38 - 0
src/ops/mul_add.rs

@@ -54,6 +54,27 @@ impl MulAdd<f64, f64> for f64 {
     }
 }
 
+#[cfg(all(not(feature = "std"), feature = "libm"))]
+impl MulAdd<f32, f32> for f32 {
+    type Output = Self;
+
+    #[inline]
+    fn mul_add(self, a: Self, b: Self) -> Self::Output {
+        <f32 as ::libm::F32Ext>::mul_add(self, a, b)
+    }
+}
+
+#[cfg(all(not(feature = "std"), feature = "libm"))]
+impl MulAdd<f64, f64> for f64 {
+    type Output = Self;
+
+    #[inline]
+    fn mul_add(self, a: Self, b: Self) -> Self::Output {
+        <f64 as ::libm::F64Ext>::mul_add(self, a, b)
+    }
+}
+
+
 macro_rules! mul_add_impl {
     ($trait_name:ident for $($t:ty)*) => {$(
         impl $trait_name for $t {
@@ -87,6 +108,23 @@ impl MulAddAssign<f64, f64> for f64 {
     }
 }
 
+#[cfg(all(not(feature = "std"), feature = "libm"))]
+impl MulAddAssign<f32, f32> for f32 {
+    #[inline]
+    fn mul_add_assign(&mut self, a: Self, b: Self) {
+        *self = <f32 as ::libm::F32Ext>::mul_add(*self, a, b)
+    }
+}
+
+#[cfg(all(not(feature = "std"), feature = "libm"))]
+impl MulAddAssign<f64, f64> for f64 {
+    #[inline]
+    fn mul_add_assign(&mut self, a: Self, b: Self) {
+        *self = <f64 as ::libm::F64Ext>::mul_add(*self, a, b)
+    }
+}
+
+
 macro_rules! mul_add_assign_impl {
     ($trait_name:ident for $($t:ty)*) => {$(
         impl $trait_name for $t {