dartfmt
diff --git a/lib/src/int32.dart b/lib/src/int32.dart
index 786f2bb..562ff0c 100644
--- a/lib/src/int32.dart
+++ b/lib/src/int32.dart
@@ -9,7 +9,6 @@
* Arithmetic operations may overflow in order to maintain this range.
*/
class Int32 implements IntX {
-
/**
* The maximum positive value attainable by an [Int32], namely
* 2147483647.
diff --git a/lib/src/int64.dart b/lib/src/int64.dart
index b7127ee..87b8deb 100644
--- a/lib/src/int64.dart
+++ b/lib/src/int64.dart
@@ -9,7 +9,6 @@
* Arithmetic operations may overflow in order to maintain this range.
*/
class Int64 implements IntX {
-
// A 64-bit integer is represented internally as three non-negative
// integers, storing the 22 low, 22 middle, and 20 high bits of the
// 64-bit value. _l (low) and _m (middle) are in the range
@@ -80,7 +79,7 @@
negative = true;
i++;
}
- int d0 = 0, d1 = 0, d2 = 0; // low, middle, high components.
+ int d0 = 0, d1 = 0, d2 = 0; // low, middle, high components.
for (; i < s.length; i++) {
int c = s.codeUnitAt(i);
int digit = Int32._decodeDigit(c);
@@ -124,7 +123,7 @@
/**
* Constructs an [Int64] with a given [int] value; zero by default.
*/
- factory Int64([int value=0]) {
+ factory Int64([int value = 0]) {
int v0 = 0, v1 = 0, v2 = 0;
bool negative = false;
if (value < 0) {
@@ -185,7 +184,7 @@
bottom |= bytes[7] & 0xff;
return new Int64.fromInts(top, bottom);
- }
+ }
/**
* Constructs an [Int64] from a pair of 32-bit integers having the value
@@ -197,7 +196,7 @@
int d0 = _MASK & bottom;
int d1 = ((0xfff & top) << 10) | (0x3ff & (bottom >> _BITS));
int d2 = _MASK2 & (top >> 12);
- return Int64._masked(d0, d1, d2);
+ return Int64._masked(d0, d1, d2);
}
// Returns the [Int64] representation of the specified value. Throws
@@ -582,12 +581,12 @@
int m = _m.toSigned(width - _BITS);
return m.isNegative
? Int64._masked(_l, m, _MASK2)
- : Int64._masked(_l, m, 0); // Masking for type inferrer.
+ : Int64._masked(_l, m, 0); // Masking for type inferrer.
} else {
int l = _l.toSigned(width);
return l.isNegative
? Int64._masked(l, _MASK, _MASK2)
- : Int64._masked(l, 0, 0); // Masking for type inferrer.
+ : Int64._masked(l, 0, 0); // Masking for type inferrer.
}
}
@@ -771,8 +770,26 @@
static const _fatRadixTable = const <int>[
0,
0,
- 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2
- * 2,
+ 2 *
+ 2 *
+ 2 *
+ 2 *
+ 2 *
+ 2 *
+ 2 *
+ 2 *
+ 2 *
+ 2 *
+ 2 *
+ 2 *
+ 2 *
+ 2 *
+ 2 *
+ 2 *
+ 2 *
+ 2 *
+ 2 *
+ 2,
3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3,
4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4,
5 * 5 * 5 * 5 * 5 * 5 * 5 * 5,
@@ -872,11 +889,17 @@
static _divideHelper(
// up to 64 bits unsigned in a2/a1/a0 and b2/b1/b0
- int a0, int a1, int a2, bool aNeg, // input A.
- int b0, int b1, int b2, bool bNeg, // input B.
+ int a0,
+ int a1,
+ int a2,
+ bool aNeg, // input A.
+ int b0,
+ int b1,
+ int b2,
+ bool bNeg, // input B.
int what) {
- int q0 = 0, q1 = 0, q2 = 0; // result Q.
- int r0 = 0, r1 = 0, r2 = 0; // result R.
+ int q0 = 0, q1 = 0, q2 = 0; // result Q.
+ int r0 = 0, r1 = 0, r2 = 0; // result R.
if (b2 == 0 && b1 == 0 && b0 < (1 << (30 - _BITS))) {
// Small divisor can be handled by single-digit division within Smi range.
@@ -924,7 +947,7 @@
q0 = q0d.toInt();
assert(q0 + K1 * q1 + K2 * q2 == (ad / bd).floorToDouble());
- assert(q2 == 0 || b2 == 0); // Q and B can't both be big since Q*B <= A.
+ assert(q2 == 0 || b2 == 0); // Q and B can't both be big since Q*B <= A.
// P = Q * B, using doubles to hold intermediates.
// We don't need all partial sums since Q*B <= A.
@@ -935,7 +958,7 @@
double p1carry = (p1d / K1).floorToDouble();
p1d = p1d - p1carry * K1;
double p2d = q2d * b0 + q1d * b1 + q0d * b2 + p1carry;
- assert(p2d <= _MASK2); // No partial sum overflow.
+ assert(p2d <= _MASK2); // No partial sum overflow.
// R = A - P
int diff0 = a0 - p0d.toInt();
@@ -947,8 +970,7 @@
// while (R < 0 || R >= B)
// adjust R towards [0, B)
- while (
- r2 >= _SIGN_BIT_MASK ||
+ while (r2 >= _SIGN_BIT_MASK ||
r2 > b2 ||
(r2 == b2 && (r1 > b1 || (r1 == b1 && r0 >= b0)))) {
// Direction multiplier for adjustment.
@@ -973,17 +995,17 @@
// 0 <= R < B
assert(Int64.ZERO <= new Int64._bits(r0, r1, r2));
- assert(r2 < b2 || // Handles case where B = -(MIN_VALUE)
+ assert(r2 < b2 || // Handles case where B = -(MIN_VALUE)
new Int64._bits(r0, r1, r2) < new Int64._bits(b0, b1, b2));
assert(what == _RETURN_DIV || what == _RETURN_MOD || what == _RETURN_REM);
if (what == _RETURN_DIV) {
if (aNeg != bNeg) return _negate(q0, q1, q2);
- return Int64._masked(q0, q1, q2); // Masking for type inferrer.
+ return Int64._masked(q0, q1, q2); // Masking for type inferrer.
}
if (!aNeg) {
- return Int64._masked(r0, r1, r2); // Masking for type inferrer.
+ return Int64._masked(r0, r1, r2); // Masking for type inferrer.
}
if (what == _RETURN_MOD) {
diff --git a/lib/src/intx.dart b/lib/src/intx.dart
index 6b4a454..3c2207d 100644
--- a/lib/src/intx.dart
+++ b/lib/src/intx.dart
@@ -8,7 +8,6 @@
* A fixed-precision integer.
*/
abstract class IntX implements Comparable<dynamic> {
-
/** Addition operator. */
IntX operator +(other);
diff --git a/test/int32_test.dart b/test/int32_test.dart
index d237a03..6f904cf 100644
--- a/test/int32_test.dart
+++ b/test/int32_test.dart
@@ -302,8 +302,9 @@
test("shiftRightUnsigned", () {
expect(new Int32(0x12345678).shiftRightUnsigned(7),
new Int32(0x12345678 >> 7));
- expect(() => (new Int32(17).shiftRightUnsigned(-1)), throwsArgumentError);
expect(() => (new Int32(17).shiftRightUnsigned(null)), throws);
+ expect(() => (new Int32(17).shiftRightUnsigned(null)),
+ throwsNoSuchMethodError);
});
});
@@ -345,10 +346,10 @@
expect(new Int32(-17).toInt64(), new Int64(-17));
});
test("toBytes", () {
- expect(new Int32(0).toBytes(), [ 0, 0, 0, 0 ]);
- expect(new Int32(0x01020304).toBytes(), [ 4, 3, 2, 1 ]);
- expect(new Int32(0x04030201).toBytes(), [ 1, 2, 3, 4 ]);
- expect(new Int32(-1).toBytes(), [ 0xff, 0xff, 0xff, 0xff ]);
+ expect(new Int32(0).toBytes(), [0, 0, 0, 0]);
+ expect(new Int32(0x01020304).toBytes(), [4, 3, 2, 1]);
+ expect(new Int32(0x04030201).toBytes(), [1, 2, 3, 4]);
+ expect(new Int32(-1).toBytes(), [0xff, 0xff, 0xff, 0xff]);
});
});
@@ -357,6 +358,7 @@
checkInt(int x) {
expect(Int32.parseRadix('$x', 10), new Int32(x));
}
+
checkInt(0);
checkInt(1);
checkInt(1000);
@@ -374,6 +376,7 @@
check(String s, int r, String x) {
expect(Int32.parseRadix(s, r).toString(), x);
}
+
check('deadbeef', 16, '-559038737');
check('95', 12, '113');
});
diff --git a/test/int64_test.dart b/test/int64_test.dart
index 1ea7e75..8e6a90e 100644
--- a/test/int64_test.dart
+++ b/test/int64_test.dart
@@ -13,25 +13,27 @@
checkBytes(List<int> bytes, int h, int l) {
expect(new Int64.fromBytes(bytes), new Int64.fromInts(h, l));
}
- checkBytes([ 0, 0, 0, 0, 0, 0, 0, 0 ], 0, 0);
- checkBytes([ 1, 0, 0, 0, 0, 0, 0, 0 ], 0, 1);
- checkBytes([ 1, 2, 3, 4, 5, 6, 7, 8 ], 0x08070605, 0x04030201);
- checkBytes([ 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ],
- 0xffffffff, 0xfffffffe);
- checkBytes([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ],
- 0xffffffff, 0xffffffff);
+
+ checkBytes([0, 0, 0, 0, 0, 0, 0, 0], 0, 0);
+ checkBytes([1, 0, 0, 0, 0, 0, 0, 0], 0, 1);
+ checkBytes([1, 2, 3, 4, 5, 6, 7, 8], 0x08070605, 0x04030201);
+ checkBytes([0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], 0xffffffff,
+ 0xfffffffe);
+ checkBytes([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], 0xffffffff,
+ 0xffffffff);
});
test("fromBytesBigEndian", () {
checkBytes(List<int> bytes, int h, int l) {
expect(new Int64.fromBytesBigEndian(bytes), new Int64.fromInts(h, l));
}
- checkBytes([ 0, 0, 0, 0, 0, 0, 0, 0 ], 0, 0);
- checkBytes([ 0, 0, 0, 0, 0, 0, 0, 1 ], 0, 1);
- checkBytes([ 8, 7, 6, 5, 4, 3, 2, 1 ], 0x08070605, 0x04030201);
- checkBytes([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe ],
- 0xffffffff, 0xfffffffe);
- checkBytes([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ],
- 0xffffffff, 0xffffffff);
+
+ checkBytes([0, 0, 0, 0, 0, 0, 0, 0], 0, 0);
+ checkBytes([0, 0, 0, 0, 0, 0, 0, 1], 0, 1);
+ checkBytes([8, 7, 6, 5, 4, 3, 2, 1], 0x08070605, 0x04030201);
+ checkBytes([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe], 0xffffffff,
+ 0xfffffffe);
+ checkBytes([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], 0xffffffff,
+ 0xffffffff);
});
});
@@ -128,14 +130,17 @@
expect(new Int64(-1111) * new Int64(-3), new Int64(3333));
expect(new Int64(100) * Int64.ZERO, Int64.ZERO);
- expect(new Int64.fromInts(0x12345678, 0x12345678) *
- new Int64.fromInts(0x1234, 0x12345678),
+ expect(
+ new Int64.fromInts(0x12345678, 0x12345678) *
+ new Int64.fromInts(0x1234, 0x12345678),
new Int64.fromInts(0x7ff63f7c, 0x1df4d840));
- expect(new Int64.fromInts(0xf2345678, 0x12345678) *
- new Int64.fromInts(0x1234, 0x12345678),
+ expect(
+ new Int64.fromInts(0xf2345678, 0x12345678) *
+ new Int64.fromInts(0x1234, 0x12345678),
new Int64.fromInts(0x7ff63f7c, 0x1df4d840));
- expect(new Int64.fromInts(0xf2345678, 0x12345678) *
- new Int64.fromInts(0xffff1234, 0x12345678),
+ expect(
+ new Int64.fromInts(0xf2345678, 0x12345678) *
+ new Int64.fromInts(0xffff1234, 0x12345678),
new Int64.fromInts(0x297e3f7c, 0x1df4d840));
// RHS Int32
@@ -202,17 +207,21 @@
expect(new Int64(-1000) ~/ new Int64(3), new Int64(-333));
expect(new Int64(-1000) ~/ new Int64(-3), new Int64(333));
expect(new Int64(3) ~/ new Int64(1000), Int64.ZERO);
- expect(new Int64.fromInts(0x12345678, 0x12345678) ~/
- new Int64.fromInts(0x0, 0x123),
+ expect(
+ new Int64.fromInts(0x12345678, 0x12345678) ~/
+ new Int64.fromInts(0x0, 0x123),
new Int64.fromInts(0x1003d0, 0xe84f5ae8));
- expect(new Int64.fromInts(0x12345678, 0x12345678) ~/
- new Int64.fromInts(0x1234, 0x12345678),
+ expect(
+ new Int64.fromInts(0x12345678, 0x12345678) ~/
+ new Int64.fromInts(0x1234, 0x12345678),
new Int64.fromInts(0x0, 0x10003));
- expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/
- new Int64.fromInts(0x1234, 0x12345678),
+ expect(
+ new Int64.fromInts(0xf2345678, 0x12345678) ~/
+ new Int64.fromInts(0x1234, 0x12345678),
new Int64.fromInts(0xffffffff, 0xffff3dfe));
- expect(new Int64.fromInts(0xf2345678, 0x12345678) ~/
- new Int64.fromInts(0xffff1234, 0x12345678),
+ expect(
+ new Int64.fromInts(0xf2345678, 0x12345678) ~/
+ new Int64.fromInts(0xffff1234, 0x12345678),
new Int64.fromInts(0x0, 0xeda));
expect(new Int64(829893893) ~/ new Int32(1919), new Int32(432461));
expect(new Int64(829893893) ~/ new Int64(1919), new Int32(432461));
@@ -293,6 +302,7 @@
checkZeros(Int64 value, int zeros) {
expect(value.numberOfLeadingZeros(), zeros);
}
+
checkZeros(new Int64(0), 64);
checkZeros(new Int64(1), 63);
checkZeros(new Int64.fromInts(0x00000000, 0x003fffff), 42);
@@ -307,6 +317,7 @@
checkZeros(Int64 value, int zeros) {
expect(value.numberOfTrailingZeros(), zeros);
}
+
checkZeros(new Int64(-1), 0);
checkZeros(new Int64(1), 0);
checkZeros(new Int64(2), 1);
@@ -634,10 +645,10 @@
expect(new Int64(-2147483648).toDouble(), same(-2147483648.0));
expect(new Int64(4503599627370495).toDouble(), same(4503599627370495.0));
expect(new Int64(4503599627370496).toDouble(), same(4503599627370496.0));
- expect(new Int64(-4503599627370495).toDouble(),
- same(-4503599627370495.0));
- expect(new Int64(-4503599627370496).toDouble(),
- same(-4503599627370496.0));
+ expect(
+ new Int64(-4503599627370495).toDouble(), same(-4503599627370495.0));
+ expect(
+ new Int64(-4503599627370496).toDouble(), same(-4503599627370496.0));
expect(Int64.parseInt("-10000000000000000").toDouble().toStringAsFixed(1),
"-10000000000000000.0");
expect(Int64.parseInt("-10000000000000001").toDouble().toStringAsFixed(1),
@@ -705,13 +716,13 @@
});
test("toBytes", () {
- expect(new Int64(0).toBytes(), [ 0, 0, 0, 0, 0, 0, 0, 0 ]);
+ expect(new Int64(0).toBytes(), [0, 0, 0, 0, 0, 0, 0, 0]);
expect(new Int64.fromInts(0x08070605, 0x04030201).toBytes(),
- [ 1, 2, 3, 4, 5, 6, 7, 8 ]);
+ [1, 2, 3, 4, 5, 6, 7, 8]);
expect(new Int64.fromInts(0x01020304, 0x05060708).toBytes(),
- [ 8, 7, 6, 5, 4, 3, 2, 1 ]);
+ [8, 7, 6, 5, 4, 3, 2, 1]);
expect(new Int64(-1).toBytes(),
- [ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ]);
+ [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]);
});
});
@@ -723,6 +734,7 @@
return n * _factorial(n - new Int64(1));
}
}
+
Int64 fact18 = _factorial(new Int64(18));
Int64 fact17 = _factorial(new Int64(17));
expect(fact18 ~/ fact17, new Int64(18));
@@ -738,6 +750,7 @@
checkInt(int x) {
expect(Int64.parseRadix('$x', 10), new Int64(x));
}
+
checkInt(0);
checkInt(1);
checkInt(-1);
@@ -761,6 +774,7 @@
checkHex(String hexStr, int h, int l) {
expect(Int64.parseHex(hexStr), new Int64.fromInts(h, l));
}
+
checkHex('0', 0, 0);
checkHex('-0', 0, 0);
checkHex('00', 0, 0);
@@ -780,6 +794,7 @@
check(String s, int r, String x) {
expect(Int64.parseRadix(s, r).toString(), x);
}
+
check('ghoul', 36, '27699213');
check('ghoul', 35, '24769346');
// Min and max value.
@@ -798,7 +813,8 @@
check(String s, int r) {
expect(Int64.parseRadix(s, r).toRadixString(r), s);
}
- check("2ppp111222333", 33); // This value & radix requires three chunks.
+
+ check("2ppp111222333", 33); // This value & radix requires three chunks.
});
});
@@ -853,8 +869,8 @@
"111111111111111111111111111111111111111111111111111111111111111");
expect(Int64.MAX_VALUE.toRadixString(3),
"2021110011022210012102010021220101220221");
- expect(Int64.MAX_VALUE.toRadixString(4),
- "13333333333333333333333333333333");
+ expect(
+ Int64.MAX_VALUE.toRadixString(4), "13333333333333333333333333333333");
expect(Int64.MAX_VALUE.toRadixString(5), "1104332401304422434310311212");
expect(Int64.MAX_VALUE.toRadixString(6), "1540241003031030222122211");
expect(Int64.MAX_VALUE.toRadixString(7), "22341010611245052052300");