Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reenable fma #56

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions include/boost/units/cmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ fdim BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit,Y>& q1,
return quantity_type::from_value(fdim BOOST_PREVENT_MACRO_SUBSTITUTION (q1.value(),q2.value()));
}

#if 0

template<class Unit1,class Unit2,class Unit3,class Y>
inline
Expand All @@ -240,10 +239,11 @@ typename add_typeof_helper<
typename multiply_typeof_helper<quantity<Unit1,Y>,
quantity<Unit2,Y> >::type,
quantity<Unit3,Y> >::type
fma BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit1,Y>& q1,
const quantity<Unit2,Y>& q2,
const quantity<Unit3,Y>& q3)
fma (const quantity<Unit1,Y>& q1,
const quantity<Unit2,Y>& q2,
const quantity<Unit3,Y>& q3)
{
using std::fma;
using namespace detail;

typedef quantity<Unit1,Y> type1;
Expand All @@ -253,10 +253,33 @@ fma BOOST_PREVENT_MACRO_SUBSTITUTION (const quantity<Unit1,Y>& q1,
typedef typename multiply_typeof_helper<type1,type2>::type prod_type;
typedef typename add_typeof_helper<prod_type,type3>::type quantity_type;

return quantity_type::from_value(fma BOOST_PREVENT_MACRO_SUBSTITUTION (q1.value(),q2.value(),q3.value()));
return quantity_type::from_value(fma(q1.value(),q2.value(),q3.value()));
}

template<class Unit, class Y>
inline
BOOST_CONSTEXPR
quantity<Unit,Y>
fma(const Y& q1,
const quantity<Unit,Y>& q2,
const quantity<Unit,Y>& q3)
{
using std::fma;
return quantity<Unit,Y>::from_value(fma(q1,q2.value(),q3.value()));
}

template<class Unit, class Y>
inline
BOOST_CONSTEXPR
quantity<Unit,Y>
fma(const quantity<Unit, Y>& q1,
const Y& q2,
const quantity<Unit,Y>& q3)
{
using std::fma;
return quantity<Unit,Y>::from_value(fma(q1.value(),q2,q3.value()));
}

#endif

template<class Unit,class Y>
inline
Expand Down
6 changes: 3 additions & 3 deletions test/test_cmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ int main()
BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::area> A1(4.0*bu::square_meters),
A2(L1*L2+A1);

#if 0
BOOST_TEST((bu::fma)(L1,L2,A1) == A2);
#endif
BOOST_TEST(bu::fma(L1,L2,A1) == A2);
BOOST_TEST(bu::fma(2.0, L1, L2) == 2.0*L1 + L2);
BOOST_TEST(bu::fma(L1, 2.0, L2) == 2.0*L1 + L2);

BOOST_TEST((bu::fmax)(E4,E5) == E5);
BOOST_TEST((bu::fmin)(E4,E5) == E4);
Expand Down