Boost logo

Boost :

Subject: [boost] [mp_int] Incorrect comparison with native types
From: Nathan Kitchen (nathan.kitchen_at_[hidden])
Date: 2009-01-10 19:52:54


When I create an negative mp_int outside the range of a native type
and compare it to a number of that type, I get incorrect results. Here
is an example to reproduce the behavior:

#include <iostream>
#include <limits>
#include <boost/cstdint.hpp>
#include <boost/mp_math/mp_int.hpp>

using namespace boost::mp_math;
using namespace std;

int main()
{
  int32_t MIN = numeric_limits<int32_t>::min();
  mp_int<> a = MIN;
  cout << a << endl;
  a -= 1;
  // Should print "-2147483649 1" but prints "-2147483649 0" instead
  cout << a << ' ' << (a < MIN) << endl;

  return 0;

}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk