Boost C++ Libraries: Ticket #10103: setprecision(0) does displays too many digits of a float128 https://svn.boost.org/trac10/ticket/10103 <p> setprecision(0) is not honored for float128. Compare the display of a double and a float128 (default and fixed): </p> <pre class="wiki">0.1 0.123400000000000000000000000000000006 0 0.123400000000000000000000000000000006 </pre><p> This is produced with </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/multiprecision/float128.hpp&gt; int main() { double x = 0.1234; boost::multiprecision::float128 y = 0.1234Q; std::cout &lt;&lt; std::setprecision(0) &lt;&lt; x &lt;&lt; " " &lt;&lt; y &lt;&lt; "\n"; std::cout &lt;&lt; std::fixed &lt;&lt; x &lt;&lt; " " &lt;&lt; y &lt;&lt; "\n"; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10103 Trac 1.4.3 John Maddock Sat, 07 Jun 2014 15:38:03 GMT status changed https://svn.boost.org/trac10/ticket/10103#comment:1 https://svn.boost.org/trac10/ticket/10103#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> This is indeed a bug, but I don't know how to fix it without breaking existing code: we've used a precision of 0 to mean "as many digits as you've got", and this is pervasive/consistent throughout the library. I guess we should have used -1 as the "special" value, but it's too late now... </p> Ticket Charles Karney <charles@…> Sat, 07 Jun 2014 17:00:04 GMT <link>https://svn.boost.org/trac10/ticket/10103#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10103#comment:2</guid> <description> <p> Perhaps define an enum for this special value and advertise that it <strong>will</strong> change in future versions. </p> </description> <category>Ticket</category> </item> <item> <author>Charles Karney <charles@…></author> <pubDate>Tue, 15 Jul 2014 03:41:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10103#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10103#comment:3</guid> <description> <p> Perhaps boost can fruitfully distinguish the cases </p> <blockquote> <p> cout &lt;&lt; fixed &lt;&lt; setprecision(0) &lt;&lt; x; </p> </blockquote> <p> and </p> <blockquote> <p> cout &lt;&lt; scientific &lt;&lt; setprecision(0) &lt;&lt; x; </p> </blockquote> <p> with the former printing x as the nearest integer (ties go to even) and the latter retaining its current interpretation of printing "as many digits as you've got". This would certainly satisfy my requirements and, typically, the "as many digits as you've got" mode implies scientific notation. </p> </description> <category>Ticket</category> </item> <item> <author>Charles Karney <charles@…></author> <pubDate>Wed, 14 Oct 2015 14:40:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10103#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10103#comment:4</guid> <description> <p> With C++11 manipulators, I recommend that </p> <pre class="wiki">cout &lt;&lt; scientific &lt;&lt; setprecision(0) &lt;&lt; x; cout &lt;&lt; hexfloat &lt;&lt; setprecision(0) &lt;&lt; x; </pre><p> should print lossless representations of x. While </p> <pre class="wiki">cout &lt;&lt; fixed &lt;&lt; setprecision(0) &lt;&lt; x; cout &lt;&lt; defaultfloat &lt;&lt; setprecision(0) &lt;&lt; x; </pre><p> should mimic whatever the standard library does with doubles. </p> </description> <category>Ticket</category> </item> </channel> </rss>