Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type annotations to fix strong-mode errors #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
packages
.packages
.project
.children
pubspec.lock
Expand Down
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
analyzer:
strong-mode: true
87 changes: 43 additions & 44 deletions lib/bignum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,72 +59,72 @@ abstract class BigInteger {
return new BigIntegerDartvm.fromBytes(signum, magnitude);
}
}
BigInteger operator %( other);
BigInteger operator %(covariant BigInteger other);

BigInteger operator &( other);
BigInteger operator &(covariant BigInteger other);

BigInteger operator *( other);
BigInteger operator *(covariant BigInteger other);

BigInteger operator +( other);
BigInteger operator +(covariant BigInteger other);

BigInteger operator -();

BigInteger operator -( other);
BigInteger operator -(covariant BigInteger other);

BigInteger operator /( other);
BigInteger operator /(covariant BigInteger other);

bool operator <( other);
bool operator <(covariant BigInteger other);

BigInteger operator <<(int shiftAmount);

bool operator <=( other);
bool operator <=(covariant BigInteger other);

bool operator >( other);
bool operator >(covariant BigInteger other);

bool operator >=( other);
bool operator >=(covariant BigInteger other);

BigInteger operator >>(int shiftAmount);

BigInteger operator ^( other);
BigInteger operator ^(covariant BigInteger other);

BigInteger abs();

BigInteger add(a);
BigInteger add(covariant BigInteger a);

void bitwiseTo(a, Function op, r);

addTo(a, r);
void bitwiseTo(covariant BigInteger a, Function op, covariant BigInteger r);

and(a);
addTo(covariant BigInteger a, covariant BigInteger r);

andNot(a);
and(covariant BigInteger a);

andNot(covariant BigInteger a);

bitCount();

int bitLength();

byteValue();

cbit(x);
int cbit(int x);

clearBit(n);

clone();

int compareTo(a);

void copyTo( r);
void copyTo(covariant BigInteger r);

dMultiply(n);
dAddOffset(n,w);

divRemTo( m, q, r);

BigInteger divide(a);
divRemTo(covariant BigInteger m, covariant BigInteger q, covariant BigInteger r);

BigInteger divide(covariant BigInteger a);

Map<int, BigInteger> divideAndRemainder(a);
Map<int, BigInteger> divideAndRemainder(covariant BigInteger a);

bool equals( a);
bool equals(covariant BigInteger a);

BigInteger exp(int e, z);

Expand All @@ -134,9 +134,9 @@ abstract class BigInteger {

void fromRadix(s, b);

void fromString(s, int b);
void fromString(String s, int b);

gcd(a);
gcd(covariant BigInteger a);

getLowestSetBit();

Expand All @@ -148,32 +148,32 @@ abstract class BigInteger {

bool isProbablePrime(int t);

void lShiftTo(n, r);
void lShiftTo(int n, covariant BigInteger r);

lbit(x);
int lbit(int x);

// TODO: implement lowestSetBit
int get lowestSetBit;

BigInteger max( a);
BigInteger max(covariant BigInteger a);

bool millerRabin(t);

BigInteger min( a);
BigInteger min(covariant BigInteger a);

mod(a);
mod(covariant BigInteger a);

int modInt(int n);

BigInteger modInverse( m);
BigInteger modInverse(covariant BigInteger m);

modPow( e, m);
modPow(covariant BigInteger e, covariant BigInteger m);

BigInteger modPowInt(int e, m);
BigInteger modPowInt(int e, covariant BigInteger m);

BigInteger multiply(a);
BigInteger multiply(covariant BigInteger a);

void multiplyTo(a, r);
void multiplyTo(covariant BigInteger a, covariant BigInteger r);

int nbits(x);

Expand All @@ -189,13 +189,13 @@ abstract class BigInteger {

op_xor(x, y);

or(a);
or(covariant BigInteger a);

BigInteger pow(int e);

void rShiftTo(int n, r);

BigInteger remainder( a);
BigInteger remainder(covariant BigInteger a);

setBit(n);

Expand All @@ -209,10 +209,9 @@ abstract class BigInteger {

void squareTo(r);

void subTo(a, r);

BigInteger subtract(a);
void subTo(covariant BigInteger a, covariant BigInteger r);

BigInteger subtract(covariant BigInteger a);

testBit(n);

Expand All @@ -222,11 +221,11 @@ abstract class BigInteger {

String toString([int b]);

xor(a);
xor(covariant BigInteger a);

BigInteger operator |( other);
BigInteger operator |(covariant BigInteger other);

BigInteger operator ~();

BigInteger operator ~/( other);
BigInteger operator ~/(covariant BigInteger other);
}
28 changes: 14 additions & 14 deletions lib/src/big_integer_dartvm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class BigIntegerDartvm implements BigInteger {
}

/** r = this << n */
void lShiftTo(int n, r) {
void lShiftTo(int n, BigIntegerDartvm r) {
r.data = data << n;
}

Expand All @@ -357,15 +357,15 @@ class BigIntegerDartvm implements BigInteger {
}

/** r = this - a */
void subTo(a, r) {
void subTo(BigIntegerDartvm a, BigIntegerDartvm r) {
r.data = data - a.data;
}

/**
* r = this * a, r != this,a (HAC 14.12)
* [this] should be the larger one if appropriate.
*/
void multiplyTo(a, r) {
void multiplyTo(BigIntegerDartvm a, BigIntegerDartvm r) {
r.data = data * a.data;
}

Expand All @@ -384,7 +384,7 @@ class BigIntegerDartvm implements BigInteger {
}

/** this mod a */
mod(a) {
mod(BigIntegerDartvm a) {
return new BigIntegerDartvm(data % a.data);
}

Expand Down Expand Up @@ -528,7 +528,7 @@ class BigIntegerDartvm implements BigInteger {
op_and(x, y) {
return x & y;
}
and(a) {
and(BigIntegerDartvm a) {
return new BigIntegerDartvm(data & a.data);
}

Expand All @@ -537,23 +537,23 @@ class BigIntegerDartvm implements BigInteger {
return x | y;
}

or(a) {
or(BigIntegerDartvm a) {
return new BigIntegerDartvm(data | a.data);
}

/** this ^ a */
op_xor(x, y) {
return x ^ y;
}
xor(a) {
xor(BigIntegerDartvm a) {
return new BigIntegerDartvm(data ^ a.data);
}

/** this & ~a */
op_andnot(x, y) {
return x & ~y;
}
andNot(a) {
andNot(BigIntegerDartvm a) {
return new BigIntegerDartvm(data & ~a.data);
}

Expand Down Expand Up @@ -644,27 +644,27 @@ class BigIntegerDartvm implements BigInteger {
}

/** r = this + a */
addTo(a, r) {
addTo(BigIntegerDartvm a, BigIntegerDartvm r) {
r.data = data + a.data;
}

/** this + a */
BigIntegerDartvm add(a) {
BigIntegerDartvm add(BigIntegerDartvm a) {
return new BigIntegerDartvm(data + a.data);
}

/** this - a */
BigIntegerDartvm subtract(a) {
BigIntegerDartvm subtract(BigIntegerDartvm a) {
return new BigIntegerDartvm(data - a.data);
}

/** this * a */
BigIntegerDartvm multiply(a) {
BigIntegerDartvm multiply(BigIntegerDartvm a) {
return new BigIntegerDartvm(data * a.data);
}

/** this / a */
BigIntegerDartvm divide(a) {
BigIntegerDartvm divide(BigIntegerDartvm a) {
return new BigIntegerDartvm(data ~/ a.data);
}

Expand Down Expand Up @@ -707,7 +707,7 @@ class BigIntegerDartvm implements BigInteger {
}

/** gcd(this,a) (HAC 14.54) */
gcd(v) {
gcd(BigIntegerDartvm v) {
return new BigIntegerDartvm(data.gcd(v.data));
}

Expand Down
14 changes: 7 additions & 7 deletions lib/src/big_integer_v8.dart
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ class BigIntegerV8 implements BigInteger {
}

/** set from string [s] and radix [b] */
void fromString(s, int b) {
void fromString(dynamic s, int b) {
var this_array = this.array;
var k;
if(b == 16) { k = 4;
Expand Down Expand Up @@ -621,7 +621,7 @@ class BigIntegerV8 implements BigInteger {
}

/** r = this << n */
void lShiftTo(n,r) {
void lShiftTo(n,BigIntegerV8 r) {
var this_array = this.array;
var r_array = r.array;
var bs = n%BI_DB;
Expand Down Expand Up @@ -678,7 +678,7 @@ class BigIntegerV8 implements BigInteger {
}

/** r = this - a */
void subTo(a,r) {
void subTo(BigIntegerV8 a, BigIntegerV8 r) {
var this_array = this.array;
var r_array = r.array;
var a_array = a.array;
Expand Down Expand Up @@ -744,7 +744,7 @@ class BigIntegerV8 implements BigInteger {
* r = this * a, r != this,a (HAC 14.12)
* [this] should be the larger one if appropriate.
*/
void multiplyTo(a,r) {
void multiplyTo(BigIntegerV8 a, BigIntegerV8 r) {
var this_array = this.array;
var r_array = r.array;
BigIntegerV8 x = this.abs();
Expand Down Expand Up @@ -1266,7 +1266,7 @@ class BigIntegerV8 implements BigInteger {
flipBit(n) { return this.changeBit(n,op_xor); }

/** r = this + a */
addTo(a,r) {
addTo(BigIntegerV8 a, BigIntegerV8 r) {
var this_array = this.array;
var a_array = a.array;
var r_array = r.array;
Expand Down Expand Up @@ -1380,7 +1380,7 @@ class BigIntegerV8 implements BigInteger {
* r = lower n words of "this * a", a.t <= n
* "this" should be the larger one if appropriate.
*/
multiplyLowerTo(a,n,r) {
multiplyLowerTo(BigIntegerV8 a, int n, BigIntegerV8 r) {
var r_array = r.array;
var a_array = a.array;
var i = Mathx.min(this.t+a.t,n);
Expand Down Expand Up @@ -1477,7 +1477,7 @@ class BigIntegerV8 implements BigInteger {
}

/** gcd(this,a) (HAC 14.54) */
gcd(a) {
gcd(BigIntegerV8 a) {
var x = (this.s<0)?this.negate_op():this.clone();
var y = (a.s<0)?a.negate_op():a.clone();
if(x.compareTo(y) < 0) { var t = x; x = y; y = t; }
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: bignum
author: Adam Singer <[email protected]>
version: 0.1.0
version: 0.2.0
homepage: https://github.com/Dartist/dart-bignum
description: Big Number library for Dart
dependencies:
fixnum: '>=0.10.2 <0.11.0'
dev_dependencies:
unittest: '>=0.9.0 <0.10.0'
environment:
sdk: ">=1.11.0"
sdk: '>=1.22.1 <2.0.0'