Opened 8 years ago
Closed 8 years ago
#11159 closed Bugs (fixed)
With float128 x = nan, the test x > 0 evaluates to true
| Reported by: | Owned by: | John Maddock | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | multiprecision |
| Version: | Boost 1.57.0 | Severity: | Problem |
| Keywords: | float128 nan tests | Cc: | charles@… |
Description
On Linux with boost 1.57, executing the following code
#include <iostream>
#include <limits>
#include <boost/multiprecision/float128.hpp>
int main() {
typedef boost::multiprecision::float128 real;
real x = std::numeric_limits<real>::quiet_NaN();
std::cout << "x: " << x << "\n"
<< "x == 0: " << (x == 0) << "\n"
<< "x > 0: " << (x > 0) << "\n"
<< "x < 0: " << (x < 0) << "\n"
<< "x >= 0: " << (x >= 0) << "\n"
<< "x <= 0: " << (x <= 0) << "\n"
<< "x != 0: " << (x != 0) << "\n";
return 0;
}
gives
x: nan x == 0: 0 x > 0: 1 x < 0: 0 x >= 0: 1 x <= 0: 0 x != 0: 1
I should get
x: nan x == 0: 0 x > 0: 0 x < 0: 0 x >= 0: 0 x <= 0: 0 x != 0: 1
Change History (3)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
Oh :(
I need to look into this some more with all the floating-point backends.
comment:3 by , 8 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.

I took a look at the code and see, for example in float128.hpp:
int compare(const float128_backend& o)const { return m_value == o.m_value ? 0 : m_value < o.m_value ? -1 : 1; }Clearly, this approach to comparisons will fail with NaNs. There will need to be a 4th possible value to indicate "unordered".