Impl MulAdd+MulAssign with libm fallback

This commit is contained in:
Yoan Lecoq 2019-02-03 15:09:42 +01:00 committed by Josh Stone
parent f523f532e6
commit 4d3cb0a4ba
1 changed files with 38 additions and 0 deletions

View File

@ -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 {