Boost C++ Libraries: Ticket #11159: With float128 x = nan, the test x > 0 evaluates to true https://svn.boost.org/trac10/ticket/11159 <p> On Linux with boost 1.57, executing the following code </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;limits&gt; #include &lt;boost/multiprecision/float128.hpp&gt; int main() { typedef boost::multiprecision::float128 real; real x = std::numeric_limits&lt;real&gt;::quiet_NaN(); std::cout &lt;&lt; "x: " &lt;&lt; x &lt;&lt; "\n" &lt;&lt; "x == 0: " &lt;&lt; (x == 0) &lt;&lt; "\n" &lt;&lt; "x &gt; 0: " &lt;&lt; (x &gt; 0) &lt;&lt; "\n" &lt;&lt; "x &lt; 0: " &lt;&lt; (x &lt; 0) &lt;&lt; "\n" &lt;&lt; "x &gt;= 0: " &lt;&lt; (x &gt;= 0) &lt;&lt; "\n" &lt;&lt; "x &lt;= 0: " &lt;&lt; (x &lt;= 0) &lt;&lt; "\n" &lt;&lt; "x != 0: " &lt;&lt; (x != 0) &lt;&lt; "\n"; return 0; } </pre><p> gives </p> <pre class="wiki">x: nan x == 0: 0 x &gt; 0: 1 x &lt; 0: 0 x &gt;= 0: 1 x &lt;= 0: 0 x != 0: 1 </pre><p> I should get </p> <pre class="wiki">x: nan x == 0: 0 x &gt; 0: 0 x &lt; 0: 0 x &gt;= 0: 0 x &lt;= 0: 0 x != 0: 1 </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11159 Trac 1.4.3 charles@… Tue, 31 Mar 2015 15:04:21 GMT <link>https://svn.boost.org/trac10/ticket/11159#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11159#comment:1</guid> <description> <p> I took a look at the code and see, for example in float128.hpp: </p> <pre class="wiki"> int compare(const float128_backend&amp; o)const { return m_value == o.m_value ? 0 : m_value &lt; o.m_value ? -1 : 1; } </pre><p> Clearly, this approach to comparisons will fail with <a class="missing wiki">NaNs</a>. There will need to be a 4th possible value to indicate "unordered". </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Tue, 31 Mar 2015 17:16:50 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11159#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11159#comment:2</guid> <description> <p> Oh :( </p> <p> I need to look into this some more with all the floating-point backends. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Fri, 03 Apr 2015 08:37:32 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/11159#comment:3 https://svn.boost.org/trac10/ticket/11159#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/4f16c26457cd707d238133bc602db2ef05db91a8"><span class="icon">​</span>https://github.com/boostorg/multiprecision/commit/4f16c26457cd707d238133bc602db2ef05db91a8</a> </p> Ticket