Skip to content

Commit f6685b7

Browse files
committed
update parse
1 parent 8e03797 commit f6685b7

1 file changed

Lines changed: 29 additions & 10 deletions

File tree

source/mir/bignum/internal/parse.d

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ SmallDecimalParsingResult parseJsonNumberImpl()(scope const(char)[] str)
6161

6262
typeof(return) result;
6363

64-
bool mullAdd(ulong multplier, ulong carry)
64+
bool mullAdd(ulong multiplier, ulong carry)
6565
{
6666
import mir.checkedint: mulu, addu;
6767
bool overflow;
68-
result.coefficient = mulu(result.coefficient, multplier, overflow);
68+
result.coefficient = mulu(result.coefficient, multiplier, overflow);
6969
if (overflow)
7070
return overflow;
7171
result.coefficient = addu(result.coefficient, carry, overflow);
@@ -89,6 +89,26 @@ SmallDecimalParsingResult parseJsonNumberImpl()(scope const(char)[] str)
8989
return result;
9090
}
9191

92+
unittest
93+
{
94+
import mir.test;
95+
auto res = "-0.1234567890e-30".parseJsonNumberImpl;
96+
res.key.should == DecimalExponentKey.e;
97+
res.sign.should == true;
98+
res.exponent.should == -40;
99+
res.coefficient.should == 1234567890;
100+
}
101+
102+
unittest
103+
{
104+
import mir.test;
105+
auto res = "2.9802322387695312E-8".parseJsonNumberImpl;
106+
res.key.should == DecimalExponentKey.E;
107+
res.sign.should == false;
108+
res.exponent.should == -24;
109+
res.coefficient.should == 29802322387695312;
110+
}
111+
92112
/++
93113
Returns: false in case of overflow or incorrect string.
94114
+/
@@ -219,22 +239,21 @@ template decimalFromStringImpl(alias mullAdd, W = size_t)
219239
}
220240

221241
IF:
222-
W multplier = 10;
242+
W multiplier = 10;
223243
static if (is(C == char) && is(W == ulong))
224244
if (!__ctfe)
225245
{
226-
import mir.bignum.internal.parse: isMadeOfEightDigits, parseEightDigits;
227246
if (str.length >= 8 && isMadeOfEightDigits(str[0 .. 8]))
228247
{
229-
multplier = 100000000;
248+
multiplier = 100000000;
230249
d = parseEightDigits(str[0 .. 8]);
231250
str = str[8 .. $];
232251
exponent -= 8;
233252
if (str.length >= 7)
234253
{
235254
if (isMadeOfEightDigits((str.ptr - 1)[0 .. 8]))
236255
{
237-
multplier = 100000000UL * 10000000;
256+
multiplier = 100000000UL * 10000000;
238257
d -= str.ptr[-1] - '0';
239258
d *= 10000000;
240259
d += parseEightDigits((str.ptr - 1)[0 .. 8]);
@@ -246,7 +265,7 @@ template decimalFromStringImpl(alias mullAdd, W = size_t)
246265
if (md < 10)
247266
{
248267
d *= 10;
249-
multplier = 100000000UL * 100000000;
268+
multiplier = 100000000UL * 100000000;
250269
d += md;
251270
str = str[1 .. $];
252271
exponent -= 1;
@@ -258,7 +277,7 @@ template decimalFromStringImpl(alias mullAdd, W = size_t)
258277
TrySix:
259278
if (isMadeOfEightDigits((str.ptr - 2)[0 .. 8]))
260279
{
261-
multplier = 100000000UL * 1000000;
280+
multiplier = 100000000UL * 1000000;
262281
d -= str.ptr[-1] - '0';
263282
d -= (str.ptr[-2] - '0') * 10;
264283
d *= 1000000;
@@ -282,9 +301,9 @@ template decimalFromStringImpl(alias mullAdd, W = size_t)
282301
goto DOB;
283302
FI:
284303
exponent--;
285-
multplier = 10;
304+
multiplier = 10;
286305
FIL:
287-
if (_expect(mullAdd(multplier, d), false))
306+
if (_expect(mullAdd(multiplier, d), false))
288307
return false;
289308
import mir.stdio;
290309
// debug dump("str = ", str);

0 commit comments

Comments
 (0)