diff --git a/include/boost/multiprecision/detail/default_ops.hpp b/include/boost/multiprecision/detail/default_ops.hpp index 01fbe181..e3f38fc2 100644 --- a/include/boost/multiprecision/detail/default_ops.hpp +++ b/include/boost/multiprecision/detail/default_ops.hpp @@ -930,7 +930,7 @@ inline void eval_fmod(T& result, const T& a, const T& b) } T n; eval_divide(result, a, b); - if(eval_get_sign(a) < 0) + if(eval_get_sign(result) < 0) eval_ceil(n, result); else eval_floor(n, result); diff --git a/test/test_arithmetic.hpp b/test/test_arithmetic.hpp index 4f68b807..edb379c9 100644 --- a/test/test_arithmetic.hpp +++ b/test/test_arithmetic.hpp @@ -742,6 +742,7 @@ void test_float_funcs(const boost::mpl::true_&) a = 0.5; a = tanh(a); BOOST_CHECK_CLOSE_FRACTION(a, Real(tanh(Real(0.5))), tol); + // fmod, need to check all the sign permutations: a = 4; b = 2; a = fmod(a, b); @@ -749,6 +750,30 @@ void test_float_funcs(const boost::mpl::true_&) a = 4; b = fmod(a, b); BOOST_CHECK_CLOSE_FRACTION(b, Real(fmod(Real(4), Real(2))), tol); + a = 4; + b = 2; + a = fmod(-a, b); + BOOST_CHECK_CLOSE_FRACTION(a, Real(fmod(-Real(4), Real(2))), tol); + a = 4; + b = fmod(-a, b); + BOOST_CHECK_CLOSE_FRACTION(b, Real(-fmod(Real(4), Real(2))), tol); + a = 4; + b = 2; + a = fmod(a, -b); + BOOST_CHECK_CLOSE_FRACTION(a, Real(fmod(Real(4), -Real(2))), tol); + a = 4; + b = fmod(a, -b); + BOOST_CHECK_CLOSE_FRACTION(b, Real(fmod(Real(4), -Real(2))), tol); + a = 4; + b = 2; + a = fmod(-a, -b); + BOOST_CHECK_CLOSE_FRACTION(a, Real(fmod(-Real(4), -Real(2))), tol); + a = 4; + b = fmod(-a, -b); + BOOST_CHECK_CLOSE_FRACTION(b, Real(fmod(-Real(4), -Real(2))), tol); + + + b = 2; a = atan2(a, b); BOOST_CHECK_CLOSE_FRACTION(a, Real(atan2(Real(4), Real(2))), tol);