From bc53b798e610831a2b06ee1779dd4973b649fa06 Mon Sep 17 00:00:00 2001 From: Jett Date: Sun, 23 Oct 2016 18:01:40 -0500 Subject: [PATCH] add additional comments --- src/json.hpp | 7 +++++++ src/json.hpp.re2c | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/json.hpp b/src/json.hpp index 12fbcf5b0..0509e4564 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -8903,19 +8903,24 @@ skip_loop: {1.e1L, 1.e2L, 1.e4L, 1.e8L, 1.e16L, 1.e32L, 1.e64L, 1.e128L, 1.e256L} }; + // round to INF if our exponent is larger than representable number if (exp > std::numeric_limits::max_exponent10) { constexpr long double inf = std::numeric_limits::infinity(); result = (result < 0) ? -inf : inf; } + // round to zero if our exponent is smaller than representable number else if (exp < std::numeric_limits::min_exponent10) { result = 0.0L; } + // iteratively divide result for negative exp else if (exp < 0) { + // make exp positive for loop below exp *= -1; + // check enabled exp bits on lookup powerof10 lookup table for (std::size_t count = 0; exp; ++count, exp >>= 1) { if (exp & 1) @@ -8924,8 +8929,10 @@ skip_loop: } } } + // iteratively multiply result for positive exp else { + // check enabled exp bits on lookup powerof10 lookup table for (std::size_t count = 0; exp; ++count, exp >>= 1) { if (exp & 1) diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 0014de271..99631bbae 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -8200,19 +8200,24 @@ skip_loop: {1.e1L, 1.e2L, 1.e4L, 1.e8L, 1.e16L, 1.e32L, 1.e64L, 1.e128L, 1.e256L} }; + // round to INF if our exponent is larger than representable number if (exp > std::numeric_limits::max_exponent10) { constexpr long double inf = std::numeric_limits::infinity(); result = (result < 0) ? -inf : inf; } + // round to zero if our exponent is smaller than representable number else if (exp < std::numeric_limits::min_exponent10) { result = 0.0L; } + // iteratively divide result for negative exp else if (exp < 0) { + // make exp positive for loop below exp *= -1; + // check enabled exp bits on lookup powerof10 lookup table for (std::size_t count = 0; exp; ++count, exp >>= 1) { if (exp & 1) @@ -8221,8 +8226,10 @@ skip_loop: } } } + // iteratively multiply result for positive exp else { + // check enabled exp bits on lookup powerof10 lookup table for (std::size_t count = 0; exp; ++count, exp >>= 1) { if (exp & 1)