Skip to content

Commit 4a154dc

Browse files
authored
add DIP1000 (#345)
1 parent f730393 commit 4a154dc

6 files changed

Lines changed: 86 additions & 77 deletions

File tree

dub.sdl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ buildType "unittest-dip1008" {
1717
versions "mir_bignum_test" "mir_test"
1818
dflags "-lowmem" "-preview=dip1008"
1919
}
20+
buildType "unittest-dip1000" {
21+
buildOptions "unittests" "debugMode" "debugInfo"
22+
versions "mir_bignum_test" // "mir_test"
23+
dflags "-lowmem" "-preview=dip1000"
24+
}
2025
buildType "unittest-cov" {
2126
buildOptions "unittests" "coverage" "debugMode" "debugInfo"
2227
versions "mir_bignum_test" "mir_test"

source/mir/appender.d

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ version (mir_test) unittest
332332
assert(buf.data == "cs");
333333
}
334334

335-
version(mir_test)
335+
version(mir_bignum_test) // for DIP1000
336+
@safe pure nothrow
336337
unittest
337338
{
338339
import mir.conv: to;
@@ -345,12 +346,14 @@ unittest
345346
return "_";
346347
}
347348
}
348-
Algebraic!(int, string) x;
349+
Algebraic!(int, string, double) x;
349350
x = 42;
350351
auto s = x.to!string;
351352
assert(s == "42", s);
352353
x = "abc";
353354
assert(x.to!string == "abc");
355+
x = 42.0;
356+
assert(x.to!string == "42.0");
354357
Algebraic!S y;
355358
y = S();
356359
assert(y.to!string == "_");

source/mir/bignum/fixed.d

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ struct UInt(size_t size)
111111

112112
static if (size == 128)
113113
///
114-
version(mir_test) @safe pure @nogc unittest
114+
version(mir_bignum_test) @safe pure @nogc unittest
115115
{
116116
import mir.math.constant: PI;
117117
UInt!256 integer = "34010447314490204552169750449563978034784726557588085989975288830070948234680"; // constructor
@@ -265,14 +265,14 @@ struct UInt(size_t size)
265265
}
266266

267267
/// ditto
268-
auto opCmp(ulong rhs) const
268+
auto opCmp(ulong rhs) const scope
269269
{
270270
return opCmp(UInt!size(rhs));
271271
}
272272

273273
/++
274274
+/
275-
ref UInt!size opAssign(ulong rhs) return
275+
ref UInt!size opAssign(ulong rhs) scope return
276276
@safe pure nothrow @nogc
277277
{
278278
this.data = UInt!size(rhs).data;
@@ -283,15 +283,15 @@ struct UInt(size_t size)
283283
`bool overflow = a += b ` and `bool overflow = a -= b` operations.
284284
+/
285285
bool opOpAssign(string op)(UInt!size rhs, bool overflow = false)
286-
@safe pure nothrow @nogc
286+
@safe pure nothrow @nogc scope
287287
if (op == "+" || op == "-")
288288
{
289289
return view.opOpAssign!op(rhs.view, overflow);
290290
}
291291

292292
/// ditto
293293
bool opOpAssign(string op)(size_t rhs)
294-
@safe pure nothrow @nogc
294+
@safe pure nothrow @nogc scope
295295
if (op == "+" || op == "-")
296296
{
297297
return view.opOpAssign!op(rhs);
@@ -300,15 +300,15 @@ struct UInt(size_t size)
300300
static if (size_t.sizeof < ulong.sizeof)
301301
/// ditto
302302
bool opOpAssign(string op)(ulong rhs)
303-
@safe pure nothrow @nogc
303+
@safe pure nothrow @nogc scope
304304
if (op == "+" || op == "-")
305305
{
306306
return opOpAssign!op(UInt!size(rhs));
307307
}
308308

309309
/// ditto
310310
bool opOpAssign(string op, size_t rsize)(UInt!rsize rhs, bool overflow = false)
311-
@safe pure nothrow @nogc
311+
@safe pure nothrow @nogc scope
312312
if ((op == "+" || op == "-") && rsize < size)
313313
{
314314
return opOpAssign!op(rhs.toSize!size, overflow);
@@ -318,15 +318,15 @@ struct UInt(size_t size)
318318
Returns: overflow value of multiplication
319319
+/
320320
size_t opOpAssign(string op : "*")(size_t rhs, size_t carry = 0)
321-
@safe pure nothrow @nogc
321+
@safe pure nothrow @nogc scope
322322
{
323323
return view.opOpAssign!op(rhs, carry);
324324
}
325325

326326
static if (size_t.sizeof == 4)
327327
/// ditto
328328
auto opOpAssign(string op : "*")(ulong rhs)
329-
@safe pure nothrow @nogc
329+
@safe pure nothrow @nogc scope
330330
{
331331
return opOpAssign!op(UInt!64(rhs));
332332
}
@@ -336,7 +336,7 @@ struct UInt(size_t size)
336336
Returns: overflow value of multiplication
337337
+/
338338
void opOpAssign(string op : "*", size_t rhsSize)(UInt!rhsSize rhs)
339-
@safe pure nothrow @nogc
339+
@safe pure nothrow @nogc scope
340340
if (rhsSize <= size)
341341
{
342342
this = extendedMul(this, rhs).toSize!size;
@@ -352,7 +352,7 @@ struct UInt(size_t size)
352352
unsigned remainder value (evaluated overflow)
353353
+/
354354
uint opOpAssign(string op : "/")(uint rhs, uint overflow = 0)
355-
@safe pure nothrow @nogc
355+
@safe pure nothrow @nogc scope
356356
{
357357
assert(overflow < rhs);
358358
auto work = view.normalized;
@@ -382,7 +382,7 @@ struct UInt(size_t size)
382382
}
383383

384384
///
385-
ref UInt!size opOpAssign(string op)(size_t rhs) nothrow return
385+
ref UInt!size opOpAssign(string op)(size_t rhs) nothrow return scope
386386
if (op == "^" || op == "|" || op == "&")
387387
{
388388
mixin(`view.leastSignificantFirst[0] ` ~ op ~ `= rhs;`);
@@ -392,7 +392,7 @@ struct UInt(size_t size)
392392
static if (size_t.sizeof < ulong.sizeof)
393393
/// ditto
394394
ref opOpAssign(string op)(ulong rhs) return
395-
@safe pure nothrow @nogc
395+
@safe pure nothrow @nogc scope
396396
if (op == "^" || op == "|" || op == "&")
397397
{
398398
return opOpAssign!op(UInt!size(rhs));
@@ -805,7 +805,7 @@ UInt!sizeB extendedMulHigh(size_t sizeA, size_t sizeB)(UInt!sizeA a, UInt!sizeB
805805

806806
/++
807807
+/
808-
UInt!(sizeA + sizeB) extendedMul(size_t sizeA, size_t sizeB)(UInt!sizeA a, UInt!sizeB b)
808+
UInt!(sizeA + sizeB) extendedMul(size_t sizeA, size_t sizeB)(UInt!sizeA a, UInt!sizeB b) @safe
809809
{
810810
UInt!(sizeA + sizeB) ret;
811811
enum al = a.data.length;
@@ -827,7 +827,7 @@ UInt!(sizeA + sizeB) extendedMul(size_t sizeA, size_t sizeB)(UInt!sizeA a, UInt!
827827

828828
/// ditto
829829
UInt!(size + size_t.sizeof * 8)
830-
extendedMul(size_t size)(UInt!size a, size_t b)
830+
extendedMul(size_t size)(UInt!size a, size_t b) @safe
831831
{
832832
size_t overflow = a.view *= b;
833833
auto ret = a.toSize!(size + size_t.sizeof * 8);
@@ -873,7 +873,6 @@ UInt!64 extendedMul()(uint a, uint b)
873873

874874
///
875875
version(mir_bignum_test)
876-
version(mir_bignum_test)
877876
@safe pure @nogc
878877
unittest
879878
{

0 commit comments

Comments
 (0)