Fix behaviour of fmod for negative divisor.

And add more tests, see https://svn.boost.org/trac/boost/ticket/11641.
This commit is contained in:
jzmaddock
2015-09-11 17:13:34 +01:00
parent 8a84894715
commit fdbeedc609
2 changed files with 26 additions and 1 deletions

View File

@@ -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);

View File

@@ -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);