Opened 8 years ago
#10244 new Bugs
Erroneous conversion from double to boost::rational<int>
Reported by: | akrzemi1 | Owned by: | Jonathan Turkanis |
---|---|---|---|
Milestone: | To Be Determined | Component: | rational |
Version: | Boost 1.55.0 | Severity: | Problem |
Keywords: | Cc: |
Description
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.
Note:
See TracTickets
for help on using tickets.