|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85334 - sandbox/multiprecision.cpp_bin_float/boost/multiprecision
From: john_at_[hidden]
Date: 2013-08-13 13:07:18
Author: johnmaddock
Date: 2013-08-13 13:07:18 EDT (Tue, 13 Aug 2013)
New Revision: 85334
URL: http://svn.boost.org/trac/boost/changeset/85334
Log:
Fix sign handling.
Text files modified:
sandbox/multiprecision.cpp_bin_float/boost/multiprecision/cpp_bin_float.hpp | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
Modified: sandbox/multiprecision.cpp_bin_float/boost/multiprecision/cpp_bin_float.hpp
==============================================================================
--- sandbox/multiprecision.cpp_bin_float/boost/multiprecision/cpp_bin_float.hpp Tue Aug 13 13:05:54 2013 (r85333)
+++ sandbox/multiprecision.cpp_bin_float/boost/multiprecision/cpp_bin_float.hpp 2013-08-13 13:07:18 EDT (Tue, 13 Aug 2013) (r85334)
@@ -36,7 +36,7 @@
rep_type m_data;
int m_exponent;
- int m_sign;
+ bool m_sign;
public:
cpp_bin_float() : m_data(), m_exponent(exponent_nan), m_sign(false) {}
@@ -291,8 +291,8 @@
const rep_type& bits()const { return m_data; }
int& exponent() { return m_exponent; }
const int& exponent()const { return m_exponent; }
- int& sign() { return m_sign; }
- const int& sign()const { return m_sign; }
+ bool& sign() { return m_sign; }
+ const bool& sign()const { return m_sign; }
void check_invariants()
{
using default_ops::eval_bit_test;
@@ -424,6 +424,7 @@
}
int e_diff = a.exponent() - b.exponent();
+ bool s = a.sign();
if(e_diff >= 0)
{
dt = a.bits();
@@ -433,6 +434,8 @@
res.exponent() = a.exponent() - e_diff;
eval_add(dt, b.bits());
}
+ else
+ res.exponent() = a.exponent();
}
else
{
@@ -449,6 +452,8 @@
copy_and_round(res, dt);
res.check_invariants();
+ if(res.sign() != s)
+ res.negate();
}
template <unsigned bits>
@@ -498,6 +503,7 @@
}
int e_diff = a.exponent() - b.exponent();
+ bool s = a.sign();
if((e_diff > 0) || ((e_diff == 0) && a.bits().compare(b.bits()) >= 0))
{
dt = a.bits();
@@ -507,6 +513,8 @@
res.exponent() = a.exponent() - e_diff;
eval_subtract(dt, b.bits());
}
+ else
+ res.exponent() = a.exponent();
}
else
{
@@ -516,13 +524,15 @@
eval_left_shift(dt, -e_diff);
res.exponent() = b.exponent() + e_diff;
eval_subtract(dt, a.bits());
- res.negate();
}
else
res.exponent() = b.exponent();
+ s = !s;
}
copy_and_round(res, dt);
+ if(res.sign() != s)
+ res.negate();
res.check_invariants();
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk