@@ -18,11 +18,11 @@ private static immutable C[9] zerosImpl(C) = "0.00000.0";
1818/+ +
1919Stack-allocated decimal type.
2020Params:
21- maxSize64 = count of 64bit words in coefficient
21+ size64 = count of 64bit words in coefficient
2222+/
2323@serdeScoped @serdeProxy! (const (char )[])
24- struct Decimal (uint maxSize64 )
25- if (maxSize64 && maxSize64 <= ushort .max)
24+ struct Decimal (uint size64 )
25+ if (size64 && size64 <= ushort .max)
2626{
2727 import mir.format: NumericSpec;
2828 import mir.bignum.integer;
@@ -32,7 +32,7 @@ struct Decimal(uint maxSize64)
3232 // /
3333 long exponent;
3434 // /
35- BigInt! maxSize64 coefficient;
35+ BigInt! size64 coefficient;
3636
3737 // /
3838 DecimalView! size_t view ()
@@ -56,11 +56,11 @@ struct Decimal(uint maxSize64)
5656 static if (__traits(compiles, () @nogc { throw new Exception (" Can't parse Decimal." ); }))
5757 {
5858 import mir.exception: MirException;
59- throw new MirException(" Can't parse Decimal!" ~ maxSize64 .stringof ~ " from string `" , str , " `" );
59+ throw new MirException(" Can't parse Decimal!" ~ size64 .stringof ~ " from string `" , str , " `" );
6060 }
6161 else
6262 {
63- static immutable exception = new Exception (" Can't parse Decimal!" ~ maxSize64 .stringof ~ " ." );
63+ static immutable exception = new Exception (" Can't parse Decimal!" ~ size64 .stringof ~ " ." );
6464 throw exception;
6565 }
6666 }
@@ -71,15 +71,15 @@ struct Decimal(uint maxSize64)
7171 The number is the shortest decimal representation that being converted back would result the same floating-point number.
7272 +/
7373 this (T)(const T x)
74- if (isFloatingPoint! T && maxSize64 >= 1 + (T.mant_dig >= 64 ))
74+ if (isFloatingPoint! T && size64 >= 1 + (T.mant_dig >= 64 ))
7575 {
7676 import mir.bignum.internal.ryu.generic_128: genericBinaryToDecimal;
7777 this = genericBinaryToDecimal(x);
7878 }
7979
8080 // /
8181 ref opAssign (uint rhsMaxSize64)(auto ref scope const Decimal! rhsMaxSize64 rhs) return
82- if (rhsMaxSize64 < maxSize64 )
82+ if (rhsMaxSize64 < size64 )
8383 {
8484 this .exponent = rhs.exponent;
8585 this .coefficient = rhs.coefficient;
@@ -180,7 +180,7 @@ struct Decimal(uint maxSize64)
180180 scope @trusted pure @nogc nothrow
181181 if (isSomeChar! C)
182182 {
183- enum optimize = size_t .sizeof == 8 && maxSize64 == 1 ;
183+ enum optimize = size_t .sizeof == 8 && size64 == 1 ;
184184 version (LDC )
185185 {
186186 static if (optimize || (allowSpecialValues && allowDExponent && allowStartingPlus && checkEmpty) == false )
@@ -333,7 +333,7 @@ struct Decimal(uint maxSize64)
333333 v = mulu(v, multplier, overflow);
334334 if (overflow)
335335 return false ;
336- v = addu(v, value, overflow);;
336+ v = addu(v, value, overflow);
337337 if (overflow)
338338 return false ;
339339 }
@@ -351,7 +351,7 @@ struct Decimal(uint maxSize64)
351351 v = mulu(v, cast (uint )10 , overflow);
352352 if (overflow)
353353 return false ;
354- v = addu(v, d, overflow);;
354+ v = addu(v, d, overflow);
355355 if (overflow)
356356 return false ;
357357 }
@@ -503,13 +503,13 @@ struct Decimal(uint maxSize64)
503503 }
504504 else
505505 {
506- BigInt! maxSize64 work = coefficient;
506+ BigInt! size64 work = coefficient;
507507 coefficientLength = work.view.unsigned.toStringImpl(buffer);
508508 }
509509 }
510510 else
511511 {
512- BigInt! maxSize64 work = coefficient;
512+ BigInt! size64 work = coefficient;
513513 coefficientLength = work.view.unsigned.toStringImpl(buffer);
514514 }
515515
@@ -675,7 +675,7 @@ struct Decimal(uint maxSize64)
675675 if (op == " +" || op == " -" )
676676 {
677677 import mir.utility: max;
678- BigInt! (max(rhsMaxSize64, maxSize64 , 256u )) rhsCopy = void ;
678+ BigInt! (max(rhsMaxSize64, size64 , 256u )) rhsCopy = void ;
679679 BigIntView! (const size_t ) rhsView;
680680 auto expDiff = cast (sizediff_t ) (exponent - rhs.exponent);
681681 if (expDiff >= 0 )
@@ -702,13 +702,14 @@ version(mir_bignum_test)
702702@safe pure nothrow @nogc
703703unittest
704704{
705+ import mir.test: should;
705706 import mir.conv: to;
706707 Decimal! 256 decimal = void ;
707708 DecimalExponentKey key;
708709
709710 assert (decimal.fromStringImpl(" 3.141592653589793378e-10" , key));
710- assert ( cast ( double ) decimal == 0x1 .596bf8ce7631ep- 32 ) ;
711- assert ( key == DecimalExponentKey.e) ;
711+ decimal.to ! double .should == 0x1 .596bf8ce7631ep- 32 ;
712+ key.should == DecimalExponentKey.e;
712713}
713714
714715// /
@@ -808,6 +809,8 @@ version(mir_bignum_test)
808809@safe pure nothrow @nogc
809810unittest
810811{
812+ import mir.test: should;
813+
811814 import mir.conv: to;
812815 Decimal! 3 decimal;
813816 DecimalExponentKey key;
@@ -865,7 +868,7 @@ unittest
865868 assert (decimal.coefficient.length == 0 );
866869 assert (decimal.exponent == decimal.exponent.max);
867870 assert (key == DecimalExponentKey.infinity);
868- assert (cast (double ) decimal == - double .infinity) ;
871+ should (cast (double ) decimal) == - double .infinity;
869872
870873 assert (! decimal.fromStringImpl(" 3.3.4" , key));
871874 assert (! decimal.fromStringImpl(" 3.4." , key));
0 commit comments