From dec60cb66ad951fe3f152a860d003a72bf367162 Mon Sep 17 00:00:00 2001 From: Jett Date: Thu, 20 Oct 2016 23:59:02 -0500 Subject: [PATCH] remove unneeded branch --- src/json.hpp | 51 ++++++++++++++++++++++------------------------- src/json.hpp.re2c | 51 ++++++++++++++++++++++------------------------- 2 files changed, 48 insertions(+), 54 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 99561ea03..a96c98fc8 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -8900,41 +8900,38 @@ skip_loop: } // adjust number by powers of ten specified by format and exponent. - if (result != 0.0L) + constexpr std::array powerof10 = { + {1.e1L, 1.e2L, 1.e4L, 1.e8L, 1.e16L, 1.e32L, 1.e64L, 1.e128L, 1.e256L} + }; + + if (exp > std::numeric_limits::max_exponent10) { - constexpr std::array powerof10 = { - {1.e1L, 1.e2L, 1.e4L, 1.e8L, 1.e16L, 1.e32L, 1.e64L, 1.e128L, 1.e256L} - }; + constexpr long double inf = std::numeric_limits::infinity(); + result = (result < 0) ? -inf : inf; + } + else if (exp < std::numeric_limits::min_exponent10) + { + result = 0.0L; + } + else if (exp < 0) + { + exp = -exp; - if (exp > std::numeric_limits::max_exponent10) + for (std::size_t count = 0; exp; ++count, exp >>= 1) { - constexpr long double inf = std::numeric_limits::infinity(); - result = (result < 0) ? -inf : inf; - } - else if (exp < std::numeric_limits::min_exponent10) - { - result = 0.0L; - } - else if (exp < 0) - { - exp = -exp; - - for (std::size_t count = 0; exp; ++count, exp >>= 1) + if (exp & 1) { - if (exp & 1) - { - result /= powerof10[count]; - } + result /= powerof10[count]; } } - else + } + else + { + for (std::size_t count = 0; exp; ++count, exp >>= 1) { - for (std::size_t count = 0; exp; ++count, exp >>= 1) + if (exp & 1) { - if (exp & 1) - { - result *= powerof10[count]; - } + result *= powerof10[count]; } } } diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 166276c40..76b80978b 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -8197,41 +8197,38 @@ skip_loop: } // adjust number by powers of ten specified by format and exponent. - if (result != 0.0L) + constexpr std::array powerof10 = { + {1.e1L, 1.e2L, 1.e4L, 1.e8L, 1.e16L, 1.e32L, 1.e64L, 1.e128L, 1.e256L} + }; + + if (exp > std::numeric_limits::max_exponent10) { - constexpr std::array powerof10 = { - {1.e1L, 1.e2L, 1.e4L, 1.e8L, 1.e16L, 1.e32L, 1.e64L, 1.e128L, 1.e256L} - }; + constexpr long double inf = std::numeric_limits::infinity(); + result = (result < 0) ? -inf : inf; + } + else if (exp < std::numeric_limits::min_exponent10) + { + result = 0.0L; + } + else if (exp < 0) + { + exp = -exp; - if (exp > std::numeric_limits::max_exponent10) + for (std::size_t count = 0; exp; ++count, exp >>= 1) { - constexpr long double inf = std::numeric_limits::infinity(); - result = (result < 0) ? -inf : inf; - } - else if (exp < std::numeric_limits::min_exponent10) - { - result = 0.0L; - } - else if (exp < 0) - { - exp = -exp; - - for (std::size_t count = 0; exp; ++count, exp >>= 1) + if (exp & 1) { - if (exp & 1) - { - result /= powerof10[count]; - } + result /= powerof10[count]; } } - else + } + else + { + for (std::size_t count = 0; exp; ++count, exp >>= 1) { - for (std::size_t count = 0; exp; ++count, exp >>= 1) + if (exp & 1) { - if (exp & 1) - { - result *= powerof10[count]; - } + result *= powerof10[count]; } } }