I'm having a weird dynamic failure using Boost.Rational.
Using some rationals and doing a calculus, i'm ending with a rational with a negative denominator, and so unusable for comparison (hence the r.den > 0 assertion failure during the execution).
More precisely, here is a piece of code : (with typedef boost::rational<mpz_class> rat)
std::cout << xa << " " << ya << " "
<< xb << " " << yb << " "
<< xc << " " << yc << " "
<< xd << " " << yd << std::endl;
// determinant
rat delta = (xb - xa)*(yc - yd) - (yb - ya)*(xc - xd);
std::cout << "Delta : " << delta << std::endl;
/* ... some comparisons on delta ...*/
For the following result :
0/1 1/4 1/2 0/1 0/1 0/1 1/1 0/1
Delta : 1/-4
Assertion failed: (r.den > zero), function operator<, file /usr/local/include/boost/rational.hpp, line 388.
How does it come that Boost does not maintain the assertion correct ? I precise that the same code with the type boost::rational<int> does not produce the failure.