Skip to content

Commit 42ddd59

Browse files
committed
simplify bignum generic types
1 parent cdad5d7 commit 42ddd59

File tree

7 files changed

+34
-34
lines changed

7 files changed

+34
-34
lines changed

source/mir/bignum/decimal.d

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import std.traits: isSomeChar;
1212
public import mir.bignum.low_level_view: DecimalExponentKey;
1313
import mir.bignum.low_level_view: ceilLog10Exp2;
1414

15-
private enum expBufferLength = 2 + ceilLog10Exp2(size_t.sizeof * 8);
15+
private enum expBufferLength = 2 + ceilLog10Exp2(ulong.sizeof * 8);
1616
private static immutable C[9] zerosImpl(C) = "0.00000.0";
1717

1818
/++
@@ -21,7 +21,7 @@ Params:
2121
maxSize64 = count of 64bit words in coefficient
2222
+/
2323
@serdeScoped @serdeProxy!(const(char)[])
24-
struct Decimal(size_t maxSize64)
24+
struct Decimal(uint maxSize64)
2525
if (maxSize64 && maxSize64 <= ushort.max)
2626
{
2727
import mir.format: NumericSpec;
@@ -30,7 +30,7 @@ struct Decimal(size_t maxSize64)
3030
import std.traits: isMutable, isFloatingPoint;
3131

3232
///
33-
sizediff_t exponent;
33+
long exponent;
3434
///
3535
BigInt!maxSize64 coefficient;
3636

@@ -108,7 +108,7 @@ struct Decimal(size_t maxSize64)
108108
}
109109

110110
///
111-
ref opAssign(size_t rhsMaxSize64)(auto ref scope const Decimal!rhsMaxSize64 rhs) return
111+
ref opAssign(uint rhsMaxSize64)(auto ref scope const Decimal!rhsMaxSize64 rhs) return
112112
if (rhsMaxSize64 < maxSize64)
113113
{
114114
this.exponent = rhs.exponent;
@@ -737,7 +737,7 @@ struct Decimal(size_t maxSize64)
737737

738738
C[1] sign = coefficient.sign ? "-" : "+";
739739
bool addSign = coefficient.sign || spec.plus;
740-
sizediff_t s = this.exponent + coefficientLength;
740+
long s = this.exponent + coefficientLength;
741741

742742
alias zeros = zerosImpl!C;
743743

@@ -840,7 +840,7 @@ struct Decimal(size_t maxSize64)
840840

841841
assert(coefficientLength);
842842

843-
sizediff_t exponent = s - 1;
843+
long exponent = s - 1;
844844

845845
if (coefficientLength > 1)
846846
{
@@ -854,7 +854,7 @@ struct Decimal(size_t maxSize64)
854854

855855
import mir.format_impl: printSignedToTail;
856856

857-
static if (sizediff_t.sizeof == 8)
857+
static if (exponent.sizeof == 8)
858858
enum N = 21;
859859
else
860860
enum N = 11;
@@ -1081,7 +1081,7 @@ unittest
10811081

10821082
deprecated("use decimal.fromStringImpl insteade")
10831083
@trusted @nogc pure nothrow
1084-
bool parseDecimal(size_t maxSize64, C)(scope const(C)[] str, ref Decimal!maxSize64 decimal, out DecimalExponentKey key)
1084+
bool parseDecimal(uint maxSize64, C)(scope const(C)[] str, ref Decimal!maxSize64 decimal, out DecimalExponentKey key)
10851085
if (isSomeChar!C)
10861086
{
10871087
return decimal.fromStringImpl(str, key);

source/mir/bignum/fixed.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ struct UInt(size_t size)
334334
}
335335

336336
/// ditto
337-
bool opOpAssign(string op, size_t rsize)(UInt!rsize rhs, bool overflow = false)
337+
bool opOpAssign(string op, uint rsize)(UInt!rsize rhs, bool overflow = false)
338338
@safe pure nothrow @nogc scope
339339
if ((op == "+" || op == "-") && rsize < size)
340340
{

source/mir/bignum/fp.d

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import std.traits;
88
import mir.bitop;
99
import mir.utility;
1010

11-
package enum half(size_t hs) = (){
11+
package enum half(uint hs) = (){
1212
import mir.bignum.fixed: UInt;
1313
UInt!hs ret; ret.signBit = true; return ret;
1414
}();
@@ -21,8 +21,8 @@ Params:
2121
2222
Note: the implementation doesn't support NaN and Infinity values.
2323
+/
24-
struct Fp(size_t coefficientSize, Exp = sizediff_t)
25-
if ((is(Exp == int) || is(Exp == long)) && coefficientSize % (size_t.sizeof * 8) == 0 && coefficientSize >= (size_t.sizeof * 8))
24+
struct Fp(uint coefficientSize, Exp = long)
25+
if ((is(Exp == int) || is(Exp == long)) && coefficientSize % (uint.sizeof * 8) == 0 && coefficientSize >= (uint.sizeof * 8))
2626
{
2727
import mir.bignum.fixed: UInt;
2828

@@ -161,7 +161,7 @@ struct Fp(size_t coefficientSize, Exp = sizediff_t)
161161

162162
/++
163163
+/
164-
this(size_t size)(UInt!size integer, bool normalizedInteger = false)
164+
this(uint size)(UInt!size integer, bool normalizedInteger = false)
165165
nothrow
166166
{
167167
import mir.bignum.fixed: UInt;
@@ -313,7 +313,7 @@ struct Fp(size_t coefficientSize, Exp = sizediff_t)
313313
Fp a = this;
314314
alias b = rhs;
315315
auto exponent = a.exponent - b.exponent;
316-
a.exponent = b.exponent = -coefficientSize;
316+
a.exponent = b.exponent = -Exp(coefficientSize);
317317
auto ret = Fp(cast(real) a / cast(real) b);
318318
ret.exponent += exponent;
319319
return ret;
@@ -460,7 +460,7 @@ struct Fp(size_t coefficientSize, Exp = sizediff_t)
460460
}
461461

462462
///
463-
Fp!(coefficientizeA + coefficientizeB) extendedMul(size_t coefficientizeA, size_t coefficientizeB)(Fp!coefficientizeA a, Fp!coefficientizeB b)
463+
Fp!(coefficientizeA + coefficientizeB) extendedMul(uint coefficientizeA, size_t coefficientizeB)(Fp!coefficientizeA a, Fp!coefficientizeB b)
464464
@safe pure nothrow @nogc
465465
{
466466
import mir.bignum.fixed: extendedMul;
@@ -480,11 +480,11 @@ template fp_log2(T)
480480
if (__traits(isFloating, T))
481481
{
482482
///
483-
T fp_log2(size_t coefficientSize, Exp = sizediff_t)(Fp!(coefficientSize, Exp) x)
483+
T fp_log2(uint coefficientSize, Exp = long)(Fp!(coefficientSize, Exp) x)
484484
{
485485
import mir.math.common: log2;
486486
auto exponent = x.exponent + coefficientSize;
487-
x.exponent = -coefficientSize;
487+
x.exponent = -Exp(coefficientSize);
488488
return log2(cast(T)x) + exponent;
489489
}
490490
}
@@ -506,7 +506,7 @@ template fp_log(T)
506506
if (__traits(isFloating, T))
507507
{
508508
///
509-
T fp_log(size_t coefficientSize, Exp = sizediff_t)(Fp!(coefficientSize, Exp) x)
509+
T fp_log(uint coefficientSize, Exp = long)(Fp!(coefficientSize, Exp) x)
510510
{
511511
import mir.math.constant: LN2;
512512
return T(LN2) * fp_log2!T(x);

source/mir/bignum/integer.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Params:
1515
maxSize64 = count of 64bit words in coefficient
1616
+/
1717
@serdeScoped @serdeProxy!(const(char)[])
18-
struct BigInt(size_t maxSize64)
18+
struct BigInt(uint maxSize64)
1919
if (maxSize64 && maxSize64 <= ushort.max)
2020
{
2121
import mir.bignum.low_level_view;
@@ -29,13 +29,13 @@ struct BigInt(size_t maxSize64)
2929
size_t[ulong.sizeof / size_t.sizeof * maxSize64] data = void;
3030

3131
///
32-
this(size_t size)(UInt!size fixedInt)
32+
this(uint size)(UInt!size fixedInt)
3333
{
3434
this(fixedInt.data);
3535
}
3636

3737
///
38-
this(size_t N)(size_t[N] data)
38+
this(uint N)(size_t[N] data)
3939
if (N <= this.data.length)
4040
{
4141
sign = false;
@@ -115,7 +115,7 @@ struct BigInt(size_t maxSize64)
115115
}
116116

117117
///
118-
ref opAssign(size_t rhsMaxSize64)(auto ref scope const BigInt!rhsMaxSize64 rhs) return
118+
ref opAssign(uint rhsMaxSize64)(auto ref scope const BigInt!rhsMaxSize64 rhs) return
119119
if (rhsMaxSize64 < maxSize64)
120120
{
121121
this.sign = rhs.sign;

source/mir/bignum/internal/ryu/generic_128.d

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,44 +142,44 @@ else
142142

143143
enum baseDiv5 = UInt!128([0x3333333333333333, 0x3333333333333333]);
144144

145-
uint divRem5(size_t size)(ref UInt!size value)
145+
uint divRem5(uint size)(ref UInt!size value)
146146
{
147147
auto q = div5(value);
148148
auto r = cast(uint)(value - q * 5);
149149
value = q;
150150
return r;
151151
}
152152

153-
uint divRem10(size_t size)(ref UInt!size value)
153+
uint divRem10(uint size)(ref UInt!size value)
154154
{
155155
auto q = div10(value);
156156
auto r = cast(uint)(value - q * 10);
157157
value = q;
158158
return r;
159159
}
160160

161-
uint rem5(size_t size)(UInt!size value)
161+
uint rem5(uint size)(UInt!size value)
162162
{
163163
return divRem5(value);
164164
}
165165

166-
uint rem10(size_t size)(UInt!size value)
166+
uint rem10(uint size)(UInt!size value)
167167
{
168168
return divRem10(value);
169169
}
170170

171-
UInt!size div5(size_t size)(UInt!size value)
171+
UInt!size div5(uint size)(UInt!size value)
172172
{
173173
return extendedMulHigh(value, fiveReciprocal.toSize!size) >> 2;
174174
}
175175

176-
UInt!size div10(size_t size)(UInt!size value)
176+
UInt!size div10(uint size)(UInt!size value)
177177
{
178178
return extendedMulHigh(value, fiveReciprocal.toSize!size) >> 3;
179179
}
180180

181181
// Returns true if value is divisible by 5^p.
182-
bool multipleOfPowerOf5(size_t size)(UInt!size value, const uint p)
182+
bool multipleOfPowerOf5(uint size)(UInt!size value, const uint p)
183183
{
184184
enum fiveReciprocal = .fiveReciprocal.toSize!size;
185185
enum baseDiv5 = .baseDiv5.toSize!size;
@@ -206,7 +206,7 @@ version(mir_bignum_test) unittest
206206
}
207207

208208
// Returns true if value is divisible by 2^p.
209-
bool multipleOfPowerOf2(size_t size)(const UInt!size value, const uint p)
209+
bool multipleOfPowerOf2(uint size)(const UInt!size value, const uint p)
210210
{
211211
version(LDC) pragma(inline, true);
212212
return (value & ((UInt!size(1) << p) - 1)) == 0;
@@ -224,7 +224,7 @@ version(mir_bignum_test) unittest
224224
assert(multipleOfPowerOf2(UInt!128(8), 4) == false);
225225
}
226226

227-
UInt!size mulShift(size_t size)(const UInt!size m, const UInt!256 mul, const uint j)
227+
UInt!size mulShift(uint size)(const UInt!size m, const UInt!256 mul, const uint j)
228228
{
229229
version(LDC) pragma(inline, true);
230230
assert(j > 128);

source/mir/bignum/low_level_view.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2460,7 +2460,7 @@ enum DecimalExponentKey
24602460

24612461
/++
24622462
+/
2463-
struct DecimalView(W, WordEndian endian = TargetEndian, Exp = sizediff_t)
2463+
struct DecimalView(W, WordEndian endian = TargetEndian, Exp = long)
24642464
if (isUnsigned!W)
24652465
{
24662466
///

source/mir/math/numeric.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ Returns: `(count + start - 1)! / (start - 1)!`
523523
Complexity: O(count)
524524
+/
525525
auto factorial
526-
(size_t coefficientSize = 128, Exp = sizediff_t)
526+
(uint coefficientSize = 128, Exp = long)
527527
(ulong count, ulong start = 1)
528528
if (coefficientSize % (size_t.sizeof * 8) == 0 && coefficientSize >= (size_t.sizeof * 8))
529529
in (start)
@@ -592,7 +592,7 @@ Returns: n choose k
592592
Complexity: O(min(k, n - k))
593593
+/
594594
auto binomialCoefficient
595-
(size_t coefficientSize = 128, Exp = sizediff_t)
595+
(uint coefficientSize = 128, Exp = long)
596596
(ulong n, uint k)
597597
if (coefficientSize % (size_t.sizeof * 8) == 0 && coefficientSize >= (size_t.sizeof * 8))
598598
in (k <= n)

0 commit comments

Comments
 (0)