Subject: [Boost-bugs] [Boost C++ Libraries] #10244: Erroneous conversion from double to boost::rational<int>
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-07-25 12:58:54
#10244: Erroneous conversion from double to boost::rational<int>
------------------------------+----------------------
Reporter: akrzemi1 | Owner: turkanis
Type: Bugs | Status: new
Milestone: To Be Determined | Component: rational
Version: Boost 1.55.0 | Severity: Problem
Keywords: |
------------------------------+----------------------
The 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 "31/1". It just discards the fractional part. A
double is implicitly converted to int and then the implicit constructor
from int is used.
Such conversion is really confusing. Make it explicitly declared as
deleted.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/10244> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:16 UTC