Boost logo

Boost Users :

Subject: [Boost-users] Sign of gcd in rational.hpp
From: Helmut Zeisel (helmut.zeisel_at_[hidden])
Date: 2010-06-24 11:58:11


The invariant check in rational.hpp assumes that the sign of gcd is positive:

template <typename IntType>
inline bool rational<IntType>::test_invariant() const
{
    return ( this->den > int_type(0) ) &&
    ( math::gcd(this->num, this->den) == int_type(1) );
}

For built-in types, math::gcd is indeed specialized in such a way that it is always positive. For user defined IntType, math::gcd, however, does not ensure a special sign.

Does this mean that the user has to specialize boost::math::gcd<IntType>?
I did not find such an requirement in

http://www.boost.org/doc/libs/1_43_0/libs/rational/rational.html#Integer%20Type%20Requirements

Or should this better be solved in rational.hpp, e.g. by adding some function abs(gcd) or some test is_unit(gcd)?

Helmut

-- 
Sicherer, schneller und einfacher. Die aktuellen Internet-Browser -
jetzt kostenlos herunterladen! http://portal.gmx.net/de/go/atbrowser

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