
Hi,
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

On Jul 13, 2011, at 2:16 AM, Pierre Cagne wrote:
Hi,
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
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.
Thankfully.
P.S. : i'm new on this mailing-list ; does my message match with the common pattern of this list ? -- Pierre Cagne pierre.cagne@gmail.com
My guess is that you are getting an integer overflow of the underlying integer type.

On Jul 13, 2011, at 2:16 AM, Pierre Cagne wrote:
Hi,
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
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.
Thankfully.
P.S. : i'm new on this mailing-list ; does my message match with the common pattern of this list ? -- Pierre Cagne pierre.cagne@gmail.com
My guess is that you are getting an integer overflow of the underlying integer type.
Sorry. I overlooked that the integer type is mpz_class.

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).
I've come to a trick : (with typedef boost::rational

Hi, 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
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. Thankfully. -- Pierre Cagne pierre.cagne@gmail.com
participants (2)
-
Michael Olea
-
Pierre Cagne