Boost C++ Libraries: Ticket #10082: implicit cpp_rational(double) https://svn.boost.org/trac10/ticket/10082 <p> Hello, </p> <p> while trying to plug cpp_rational in our software, I noticed that the conversion from double is explicit, which complicates things quite a bit for me. I can't think of a reason why it needs to be explicit. The documentation seems to say that non-lossy conversions from builtin types are implicit, and converting from double to cpp_rational should be exact. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10082 Trac 1.4.3 John Maddock Fri, 30 May 2014 18:07:28 GMT <link>https://svn.boost.org/trac10/ticket/10082#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10082#comment:1</guid> <description> <p> Ugh, I'm a bit conflicted by this: you're quite right that the double value is converted exactly, however making this implicit does allow you to shoot yourself in the foot, for example: </p> <pre class="wiki">cpp_rational r(0.1); </pre><p> Assigns the value 3602879701896397/36028797018963968 to r, which is probably not what was intended! Of course a naive user may just add the necessary cast and shoot themselves anyway, but on balance I think I'm marginally against making the conversion implicit. </p> </description> <category>Ticket</category> </item> <item> <author>marc.glisse@…</author> <pubDate>Sat, 31 May 2014 08:06:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10082#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10082#comment:2</guid> <description> <p> Argh, please don't base your design on dumb users. Using expression templates in the first place will cause problems for dumb users (and even not so dumb ones). And the 0.1 issue is in my opinion orthogonal to implicit/explicit. The example as you wrote it already compiles (it uses the explicit constructor), you want to write it: </p> <pre class="wiki">cpp_rational r = 0.1; </pre><p> if it is supposed to be an argument against making it implicit. But the "problem" won't really become worse by making the constructor implicit. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sun, 01 Jun 2014 17:44:55 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/10082#comment:3 https://svn.boost.org/trac10/ticket/10082#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed in <a class="ext-link" href="https://github.com/boostorg/multiprecision/commit/0481ca18ec39a3794f1db008bde31ac5e22e8d93"><span class="icon">​</span>https://github.com/boostorg/multiprecision/commit/0481ca18ec39a3794f1db008bde31ac5e22e8d93</a> </p> Ticket