From 55bbda0c3179f59fd27b5725fb0177cd90678fc6 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Thu, 9 Oct 2014 16:41:21 +0100 Subject: [PATCH] Fix rare bug that breaks invariants in exp. --- .../boost/multiprecision/cpp_bin_float/transcendental.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/boost/multiprecision/cpp_bin_float/transcendental.hpp b/include/boost/multiprecision/cpp_bin_float/transcendental.hpp index 9afcc4e7..9037dd39 100644 --- a/include/boost/multiprecision/cpp_bin_float/transcendental.hpp +++ b/include/boost/multiprecision/cpp_bin_float/transcendental.hpp @@ -103,7 +103,12 @@ void eval_exp(cpp_bin_float eval_multiply(t, n, default_ops::get_constant_ln2 >()); eval_subtract(t, arg); t.negate(); - BOOST_ASSERT(t.compare(limb_type(0)) >= 0); + if(eval_get_sign(t) < 0) + { + // There are some very rare cases where arg/ln2 is an integer, and the subsequent multiply + // rounds up, in that situation t ends up negative at this point which breaks our invariants below: + t = limb_type(0); + } BOOST_ASSERT(t.compare(default_ops::get_constant_ln2 >()) < 0); Exponent k, nn;