With the program shown below, I obtained the following output:
std::numeric_limits<long>::max() == 9223372036854775807
r == boost::rational<long>(4294967296, 1853020188851841) ==
4294967296/1853020188851841
r * r == 0/8733086111712066817
Clearly there are 2 overflows but this leads to the invariant of the
class not being maintained, i.e. the faction is not simplified to 0/1
(gcd(num, den) != 1).
F
#include