Boost logo

Boost :

Subject: Re: [boost] [rational] Inadvertent construction from double
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2014-07-25 09:47:17


2014-07-25 14:13 GMT+02:00 Andrzej Krzemienski <akrzemi1_at_[hidden]>:

> 2014-07-25 13:38 GMT+02:00 Andrzej Krzemienski <akrzemi1_at_[hidden]>:
>
> > Hi,
> > 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:
> > 31/1
> > It just discards the fractional part. Such conversion is really confusing
> > an I claim should be explicitly deleted.
>
+1

Regards,
Kris

>
> I forgot to mention why this is working. A double is implicitly converted
> to int and then the implicit constructor from int is used.


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