diff options
author | abolz <lt.morris.schaffer@googlemail.com> | 2018-06-15 12:32:32 +0300 |
---|---|---|
committer | abolz <lt.morris.schaffer@googlemail.com> | 2018-06-15 12:32:32 +0300 |
commit | 4e9b4f6d6a57bb6fb1419b824073073078dbceb3 (patch) | |
tree | 0788e8ab02d02b7c6107522fda5fc9694048978f /include/rapidjson/internal | |
parent | f5e5d47fac0f654749c4d6267015005b74643dff (diff) |
Return 0 if binary exponent is too small
Diffstat (limited to 'include/rapidjson/internal')
-rw-r--r-- | include/rapidjson/internal/diyfp.h | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/include/rapidjson/internal/diyfp.h b/include/rapidjson/internal/diyfp.h index b02e0ca9..85243aff 100644 --- a/include/rapidjson/internal/diyfp.h +++ b/include/rapidjson/internal/diyfp.h @@ -1,5 +1,5 @@ // Tencent is pleased to support the open source community by making RapidJSON available. -// +// // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. // // Licensed under the MIT License (the "License"); you may not use this file except @@ -7,9 +7,9 @@ // // http://opensource.org/licenses/MIT // -// Unless required by applicable law or agreed to in writing, software distributed -// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. // This is a C++ header-only implementation of Grisu2 algorithm from the publication: @@ -56,7 +56,7 @@ struct DiyFp { if (biased_e != 0) { f = significand + kDpHiddenBit; e = biased_e - kDpExponentBias; - } + } else { f = significand; e = kDpMinExponent + 1; @@ -142,9 +142,12 @@ struct DiyFp { uint64_t u64; }u; RAPIDJSON_ASSERT(f <= kDpHiddenBit + kDpSignificandMask); - RAPIDJSON_ASSERT(e >= kDpDenormalExponent); + if (e < kDpDenormalExponent) { + // Underflow. + return 0.0; + } RAPIDJSON_ASSERT(e < kDpMaxExponent); - const uint64_t be = (e == kDpDenormalExponent && (f & kDpHiddenBit) == 0) ? 0 : + const uint64_t be = (e == kDpDenormalExponent && (f & kDpHiddenBit) == 0) ? 0 : static_cast<uint64_t>(e + kDpExponentBias); u.u64 = (f & kDpSignificandMask) | (be << kDpSignificandSize); return u.d; @@ -226,7 +229,7 @@ inline DiyFp GetCachedPowerByIndex(size_t index) { RAPIDJSON_ASSERT(index < 87); return DiyFp(kCachedPowers_F[index], kCachedPowers_E[index]); } - + inline DiyFp GetCachedPower(int e, int* K) { //int k = static_cast<int>(ceil((-61 - e) * 0.30102999566398114)) + 374; |