Boost C++ Libraries: Ticket #11102: gmp_float backend with variable precision does not have distributive property https://svn.boost.org/trac10/ticket/11102 <p> A simple example (attached) shows that the GMP backend (and MPFR as well) do not fulfill the distributive property when variable precision is chosen. This happens when values are initialized by fractions. It does not happen, when values are initialized by simple double values. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11102 Trac 1.4.3 Tobias Beck <Tobias.Beck@…> Wed, 11 Mar 2015 13:03:32 GMT attachment set https://svn.boost.org/trac10/ticket/11102 https://svn.boost.org/trac10/ticket/11102 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test.cpp</span> </li> </ul> <p> test case to reproduce the problem </p> Ticket Tobias Beck <Tobias.Beck@…> Wed, 11 Mar 2015 13:07:44 GMT <link>https://svn.boost.org/trac10/ticket/11102#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11102#comment:1</guid> <description> <p> Sorry, I produced a duplicate 11103, because the web page was not very responsive. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Wed, 11 Mar 2015 19:16:23 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/11102#comment:2 https://svn.boost.org/trac10/ticket/11102#comment:2 <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">invalid</span> </li> </ul> <p> Why would you expect this to work? Due to the way floating point values work there will always be roundoff error and I would not in general expect those two expressions to be exactly equal - even for type double. In point of fact, at least on my system they are equal when using the MPFR or cpp_bin_float backends (both of which are exactly rounded), but not for the GMP backend which does not round operations at all. Even so, I bet there are certain input values that will fail for MPFR and cpp_bin_float as well. The reason it works for you when initializing from a double is that you are only seeding a few of the bits in the mantissa with random values, and therefore there is never any rounding in any of thre operations. Seed of all of the bits in the mantissa with random values and any floating point type will fail this test. </p> <p> Please reopen if I've misunderstood your point. </p> Ticket Tobias Beck <Tobias.Beck@…> Thu, 12 Mar 2015 07:04:05 GMT <link>https://svn.boost.org/trac10/ticket/11102#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11102#comment:3</guid> <description> <p> Maybe this is due to a misunderstanding on what "variable precision" means? I assumed, that variable precision means that the number of bits is extended to fit any result as long as we only apply multiplications, subtractions and additions. In this case the distributive law should hold independently of the initialization method. </p> <p> In fact, I even assumed that internally a fractional representation is chosen to cope with the case of divisions. std::numeric_limits shows an epsilon of 0.0. I interpreted this as "values are represented exactly" (ok, at least w.r.t. certain simple operations). </p> <p> In any case, maybe the term "variable precision" needs some clarification... What can we expect of a variable precision variable? Is there only a very intransparent internal way of choosing the bitness? In this case, the type is probably useless, isn't it? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Thu, 12 Mar 2015 10:02:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11102#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11102#comment:4</guid> <description> <p> Variable precision means you get to choose at runtime what the precision is by calling number&lt;&gt;::set_precision or number&lt;&gt;::set_default_precision. It's the same behaviour that the underlying GMP or MPFR libraries have. </p> </description> <category>Ticket</category> </item> <item> <author>Tobias Beck <Tobias.Beck@…></author> <pubDate>Thu, 12 Mar 2015 11:01:57 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11102#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11102#comment:5</guid> <description> <p> Sorry, I missed that point. Thank you for the explanation. </p> </description> <category>Ticket</category> </item> </channel> </rss>