|
1 | 1 | // Tencent is pleased to support the open source community by making RapidJSON available.
|
2 |
| -// |
| 2 | +// |
3 | 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
|
4 | 4 | //
|
5 | 5 | // Licensed under the MIT License (the "License"); you may not use this file except
|
6 | 6 | // in compliance with the License. You may obtain a copy of the License at
|
7 | 7 | //
|
8 | 8 | // http://opensource.org/licenses/MIT
|
9 | 9 | //
|
10 |
| -// Unless required by applicable law or agreed to in writing, software distributed |
11 |
| -// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
12 |
| -// CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 10 | +// Unless required by applicable law or agreed to in writing, software distributed |
| 11 | +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 12 | +// CONDITIONS OF ANY KIND, either express or implied. See the License for the |
13 | 13 | // specific language governing permissions and limitations under the License.
|
14 | 14 |
|
15 | 15 | // This is a C++ header-only implementation of Grisu2 algorithm from the publication:
|
@@ -56,7 +56,7 @@ struct DiyFp {
|
56 | 56 | if (biased_e != 0) {
|
57 | 57 | f = significand + kDpHiddenBit;
|
58 | 58 | e = biased_e - kDpExponentBias;
|
59 |
| - } |
| 59 | + } |
60 | 60 | else {
|
61 | 61 | f = significand;
|
62 | 62 | e = kDpMinExponent + 1;
|
@@ -142,9 +142,12 @@ struct DiyFp {
|
142 | 142 | uint64_t u64;
|
143 | 143 | }u;
|
144 | 144 | RAPIDJSON_ASSERT(f <= kDpHiddenBit + kDpSignificandMask);
|
145 |
| - RAPIDJSON_ASSERT(e >= kDpDenormalExponent); |
| 145 | + if (e < kDpDenormalExponent) { |
| 146 | + // Underflow. |
| 147 | + return 0.0; |
| 148 | + } |
146 | 149 | RAPIDJSON_ASSERT(e < kDpMaxExponent);
|
147 |
| - const uint64_t be = (e == kDpDenormalExponent && (f & kDpHiddenBit) == 0) ? 0 : |
| 150 | + const uint64_t be = (e == kDpDenormalExponent && (f & kDpHiddenBit) == 0) ? 0 : |
148 | 151 | static_cast<uint64_t>(e + kDpExponentBias);
|
149 | 152 | u.u64 = (f & kDpSignificandMask) | (be << kDpSignificandSize);
|
150 | 153 | return u.d;
|
@@ -226,7 +229,7 @@ inline DiyFp GetCachedPowerByIndex(size_t index) {
|
226 | 229 | RAPIDJSON_ASSERT(index < 87);
|
227 | 230 | return DiyFp(kCachedPowers_F[index], kCachedPowers_E[index]);
|
228 | 231 | }
|
229 |
| - |
| 232 | + |
230 | 233 | inline DiyFp GetCachedPower(int e, int* K) {
|
231 | 234 |
|
232 | 235 | //int k = static_cast<int>(ceil((-61 - e) * 0.30102999566398114)) + 374;
|
|
0 commit comments