Boost Users :
Subject: Re: [Boost-users] [Rational] "r.den > zero" assertion failure
From: Pierre Cagne (pierre.cagne_at_[hidden])
Date: 2011-07-18 05:03:28
I somehow solved my problem here :
> 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.
I fixed the problem by editing the rational file of boost. It doesn't really fit my issues but it's another problem.
I'm still wondering why the problem doesn't occur with the type int. If someone could explain it, I'm interesting.
-- Pierre Cagne pierre.cagne_at_[hidden]
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net