diff --git a/src/cpp/pffdtd/double.hpp b/src/cpp/pffdtd/double.hpp index 7f931d1..e7ca933 100644 --- a/src/cpp/pffdtd/double.hpp +++ b/src/cpp/pffdtd/double.hpp @@ -9,7 +9,7 @@ namespace pffdtd { /// https://github.com/sukop/doubledouble/blob/master/doubledouble.py -template +template struct Double { constexpr Double() = default; @@ -19,12 +19,12 @@ struct Double { [[nodiscard]] constexpr auto low() const noexcept -> Real { return _low; } - template + template explicit constexpr operator OtherReal() const noexcept { return static_cast(high()); } - template + template explicit constexpr operator Double() const noexcept { return Double{ static_cast(high()), @@ -104,8 +104,16 @@ struct Double { [[nodiscard]] static constexpr auto twoProduct(Real x, Real y) noexcept -> Double { auto r = x * y; - auto e = std::fma(x, y, -r); - return Double{r, e}; +#if defined(__APPLE__) + if constexpr (std::same_as) { + auto e = static_cast<_Float16>(std::fma(float{x}, float{y}, float{-r})); + return Double{r, e}; + } else +#endif + { + auto e = std::fma(x, y, -r); + return Double{r, e}; + } } Real _high{static_cast(0)}; @@ -114,5 +122,5 @@ struct Double { } // namespace pffdtd -template +template struct std::numeric_limits> : std::numeric_limits {};