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

fma in boost/units/cmath.hpp? #55

Open
NAThompson opened this issue May 29, 2023 · 0 comments
Open

fma in boost/units/cmath.hpp? #55

NAThompson opened this issue May 29, 2023 · 0 comments

Comments

@NAThompson
Copy link

NAThompson commented May 29, 2023

I've recently had a compile fail with fma on boost::units types. However, it appears this has been implemented in boost/units/cmath.hpp, but it has been explicitly disabled using an #if 0.

 git show e634a7c6 
commit e634a7c6bef7180ec34387fd7bb7c0236c17a990
Author: Steven Watanabe <[email protected]>
Date:   Sat Jun 7 17:15:24 2008 +0000

    Remove compiler specific code from cmath.  Disable functions which cannot be implemented easily using Boost.Math

    [SVN r46217]

Is there any reason why we can't re-enable these code paths today?

Edit: I enabled those code paths, and it appears to be working. However, I had to add a couple other overloads:

template<class Unit, class Y>
inline 
BOOST_CONSTEXPR
quantity<Unit,Y>
fma BOOST_PREVENT_MACRO_SUBSTITUTION (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 BOOST_PREVENT_MACRO_SUBSTITUTION (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()));
}

I imagine the case where a and x have "inverse units" and a*x+b is dimensionless could also be supported.

Patchfile: units_patch.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant