Boost logo

Boost :

Subject: [boost] [rational] Inadvertent construction from double
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2014-07-25 07:38:51

I have encountered something I consider a bug in boost::rational's
interface. Its documentation discusses in detail why conversion from double
is not supported, but the following code works fine:

#include <iostream>
#include <boost/rational.hpp>

int main()
  double d = 31.82;
  boost::rational<int> r = d;
  std::cout << r << std::endl;

With the following result:
It just discards the fractional part. Such conversion is really confusing
an I claim should be explicitly deleted.


Boost list run by bdawes at, gregod at, cpdaniel at, john at