5
5
6
6
/// <reference path="../node/node.d.ts" />
7
7
8
+ declare class BigNum {
9
+ /** Create a new BigNum from n. */
10
+ constructor ( n : number | BigNum ) ;
11
+
12
+ /** Create a new BigNum from n and a base. */
13
+ constructor ( n : string , base ?: number ) ;
14
+
15
+ /**
16
+ * Create a new BigNum from a Buffer.
17
+ *
18
+ * The default options are: {endian: 'big', size: 1}.
19
+ */
20
+ static fromBuffer ( buffer : Buffer , options ?: BigNum . BufferOptions ) : BigNum ;
21
+
22
+ /**
23
+ * Generate a probable prime of length bits.
24
+ *
25
+ * If safe is true, it will be a "safe" prime of the form p=2p'+1 where p' is also prime.
26
+ */
27
+ static prime ( bits : number , safe ?: boolean ) : BigNum ;
28
+
29
+ /** Return true if num is identified as a BigNum instance. Otherwise, return false. */
30
+ static isBigNum ( num : any ) : boolean ;
31
+
32
+ /** Print out the BigNum instance in the requested base as a string. Default: base 10 */
33
+ toString ( base ?: number ) : string ;
34
+
35
+ /**
36
+ * Turn a BigNum into a Number.
37
+ *
38
+ * If the BigNum is too big you'll lose precision or you'll get ±Infinity.
39
+ */
40
+ toNumber ( ) : number ;
41
+
42
+ /**
43
+ * Return a new Buffer with the data from the BigNum.
44
+ *
45
+ * The default options are: {endian: 'big', size: 1}.
46
+ */
47
+ toBuffer ( options ?: BigNum . BufferOptions ) : Buffer ;
48
+
49
+ /** Return a new BigNum containing the instance value plus n. */
50
+ add ( n : BigNum . BigNumCompatible ) : BigNum ;
51
+
52
+ /** Return a new BigNum containing the instance value minus n. */
53
+ sub ( n : BigNum . BigNumCompatible ) : BigNum ;
54
+
55
+ /** Return a new BigNum containing the instance value multiplied by n. */
56
+ mul ( n : BigNum . BigNumCompatible ) : BigNum ;
57
+
58
+ /** Return a new BigNum containing the instance value integrally divided by n. */
59
+ div ( n : BigNum . BigNumCompatible ) : BigNum ;
60
+
61
+ /** Return a new BigNum with the absolute value of the instance. */
62
+ abs ( ) : BigNum ;
63
+
64
+ /** Return a new BigNum with the negative of the instance value. */
65
+ neg ( ) : BigNum ;
66
+
67
+ /**
68
+ * Compare the instance value to n.
69
+ *
70
+ * Return a positive integer if > n, a negative integer if < n, and 0 if == n.
71
+ */
72
+ cmp ( n : BigNum . BigNumCompatible ) : number ;
73
+
74
+ /** Return a boolean: whether the instance value is greater than n (> n). */
75
+ gt ( n : BigNum . BigNumCompatible ) : boolean ;
76
+
77
+ /** Return a boolean: whether the instance value is greater than or equal to n (>= n). */
78
+ ge ( n : BigNum . BigNumCompatible ) : boolean ;
79
+
80
+ /** Return a boolean: whether the instance value is equal to n (== n). */
81
+ eq ( n : BigNum . BigNumCompatible ) : boolean ;
82
+
83
+ /** Return a boolean: whether the instance value is less than n (< n). */
84
+ lt ( n : BigNum . BigNumCompatible ) : boolean ;
85
+
86
+ /** Return a boolean: whether the instance value is less than or equal to n (<= n). */
87
+ le ( n : BigNum . BigNumCompatible ) : boolean ;
88
+
89
+ /** Return a new BigNum with the instance value bitwise AND (&)-ed with n. */
90
+ and ( n : BigNum . BigNumCompatible ) : BigNum ;
91
+
92
+ /** Return a new BigNum with the instance value bitwise inclusive-OR (|)-ed with n. */
93
+ or ( n : BigNum . BigNumCompatible ) : BigNum ;
94
+
95
+ /** Return a new BigNum with the instance value bitwise exclusive-OR (^)-ed with n. */
96
+ xor ( n : BigNum . BigNumCompatible ) : BigNum ;
97
+
98
+ /** Return a new BigNum with the instance value modulo n. */
99
+ mod ( n : BigNum . BigNumCompatible ) : BigNum ;
100
+
101
+ /** Return a new BigNum with the instance value raised to the nth power. */
102
+ pow ( n : BigNum . BigNumCompatible ) : BigNum ;
103
+
104
+ /** Return a new BigNum with the instance value raised to the nth power modulo m. */
105
+ powm ( n : BigNum . BigNumCompatible , m : BigNum . BigNumCompatible ) : BigNum ;
106
+
107
+ /** Compute the multiplicative inverse modulo m. */
108
+ invertm ( m : BigNum . BigNumCompatible ) : BigNum ;
109
+
110
+ /**
111
+ * If upperBound is supplied, return a random BigNum between the instance value and upperBound - 1, inclusive.
112
+ * Otherwise, return a random BigNum between 0 and the instance value - 1, inclusive.
113
+ */
114
+ rand ( upperBound ?: BigNum . BigNumCompatible ) : BigNum ;
115
+
116
+ /**
117
+ * Return whether the BigNum is:
118
+ * - certainly prime (true)
119
+ * - probably prime ('maybe')
120
+ * - certainly composite (false)
121
+ */
122
+ probPrime ( ) : boolean | string ;
123
+
124
+ /** Return a new BigNum that is the 2^n multiple. Equivalent of the << operator. */
125
+ shiftLeft ( n : BigNum . BigNumCompatible ) : BigNum ;
126
+
127
+ /** Return a new BigNum of the value integer divided by 2^n. Equivalent of the >> operator. */
128
+ shiftRight ( n : BigNum . BigNumCompatible ) : BigNum ;
129
+
130
+ /** Return the greatest common divisor of the current BigNum with n as a new BigNum. */
131
+ gcd ( n : BigNum ) : BigNum ;
132
+
133
+ /**
134
+ * Return the Jacobi symbol (or Legendre symbol if n is prime) of the current BigNum (= a) over n.
135
+ * Note that n must be odd and >= 3. 0 <= a < n.
136
+ *
137
+ * Returns -1 or 1 as an int (NOT a BigNum). Throws an error on failure.
138
+ */
139
+ jacobi ( n : BigNum ) : number ;
140
+
141
+ /** Return the number of bits used to represent the current BigNum. */
142
+ bitLength ( ) : number ;
143
+ }
144
+
8
145
declare namespace BigNum {
9
146
/** Anything that can be converted to BigNum. */
10
147
type BigNumCompatible = BigNum | number | string ;
@@ -17,143 +154,6 @@ declare namespace BigNum {
17
154
size : number | string ;
18
155
}
19
156
20
- export class BigNum {
21
- /** Create a new BigNum from n. */
22
- constructor ( n : number | BigNum ) ;
23
-
24
- /** Create a new BigNum from n and a base. */
25
- constructor ( n : string , base ?: number ) ;
26
-
27
- /**
28
- * Create a new BigNum from a Buffer.
29
- *
30
- * The default options are: {endian: 'big', size: 1}.
31
- */
32
- static fromBuffer ( buffer : Buffer , options ?: BufferOptions ) : BigNum ;
33
-
34
- /**
35
- * Generate a probable prime of length bits.
36
- *
37
- * If safe is true, it will be a "safe" prime of the form p=2p'+1 where p' is also prime.
38
- */
39
- static prime ( bits : number , safe ?: boolean ) : BigNum ;
40
-
41
- /** Return true if num is identified as a BigNum instance. Otherwise, return false. */
42
- static isBigNum ( num : any ) : boolean ;
43
-
44
- /** Print out the BigNum instance in the requested base as a string. Default: base 10 */
45
- toString ( base ?: number ) : string ;
46
-
47
- /**
48
- * Turn a BigNum into a Number.
49
- *
50
- * If the BigNum is too big you'll lose precision or you'll get ±Infinity.
51
- */
52
- toNumber ( ) : number ;
53
-
54
- /**
55
- * Return a new Buffer with the data from the BigNum.
56
- *
57
- * The default options are: {endian: 'big', size: 1}.
58
- */
59
- toBuffer ( options ?: BufferOptions ) : Buffer ;
60
-
61
- /** Return a new BigNum containing the instance value plus n. */
62
- add ( n : BigNumCompatible ) : BigNum ;
63
-
64
- /** Return a new BigNum containing the instance value minus n. */
65
- sub ( n : BigNumCompatible ) : BigNum ;
66
-
67
- /** Return a new BigNum containing the instance value multiplied by n. */
68
- mul ( n : BigNumCompatible ) : BigNum ;
69
-
70
- /** Return a new BigNum containing the instance value integrally divided by n. */
71
- div ( n : BigNumCompatible ) : BigNum ;
72
-
73
- /** Return a new BigNum with the absolute value of the instance. */
74
- abs ( ) : BigNum ;
75
-
76
- /** Return a new BigNum with the negative of the instance value. */
77
- neg ( ) : BigNum ;
78
-
79
- /**
80
- * Compare the instance value to n.
81
- *
82
- * Return a positive integer if > n, a negative integer if < n, and 0 if == n.
83
- */
84
- cmp ( n : BigNumCompatible ) : number ;
85
-
86
- /** Return a boolean: whether the instance value is greater than n (> n). */
87
- gt ( n : BigNumCompatible ) : boolean ;
88
-
89
- /** Return a boolean: whether the instance value is greater than or equal to n (>= n). */
90
- ge ( n : BigNumCompatible ) : boolean ;
91
-
92
- /** Return a boolean: whether the instance value is equal to n (== n). */
93
- eq ( n : BigNumCompatible ) : boolean ;
94
-
95
- /** Return a boolean: whether the instance value is less than n (< n). */
96
- lt ( n : BigNumCompatible ) : boolean ;
97
-
98
- /** Return a boolean: whether the instance value is less than or equal to n (<= n). */
99
- le ( n : BigNumCompatible ) : boolean ;
100
-
101
- /** Return a new BigNum with the instance value bitwise AND (&)-ed with n. */
102
- and ( n : BigNumCompatible ) : BigNum ;
103
-
104
- /** Return a new BigNum with the instance value bitwise inclusive-OR (|)-ed with n. */
105
- or ( n : BigNumCompatible ) : BigNum ;
106
-
107
- /** Return a new BigNum with the instance value bitwise exclusive-OR (^)-ed with n. */
108
- xor ( n : BigNumCompatible ) : BigNum ;
109
-
110
- /** Return a new BigNum with the instance value modulo n. */
111
- mod ( n : BigNumCompatible ) : BigNum ;
112
-
113
- /** Return a new BigNum with the instance value raised to the nth power. */
114
- pow ( n : BigNumCompatible ) : BigNum ;
115
-
116
- /** Return a new BigNum with the instance value raised to the nth power modulo m. */
117
- powm ( n : BigNumCompatible , m : BigNumCompatible ) : BigNum ;
118
-
119
- /** Compute the multiplicative inverse modulo m. */
120
- invertm ( m : BigNumCompatible ) : BigNum ;
121
-
122
- /**
123
- * If upperBound is supplied, return a random BigNum between the instance value and upperBound - 1, inclusive.
124
- * Otherwise, return a random BigNum between 0 and the instance value - 1, inclusive.
125
- */
126
- rand ( upperBound ?: BigNumCompatible ) : BigNum ;
127
-
128
- /**
129
- * Return whether the BigNum is:
130
- * - certainly prime (true)
131
- * - probably prime ('maybe')
132
- * - certainly composite (false)
133
- */
134
- probPrime ( ) : boolean | string ;
135
-
136
- /** Return a new BigNum that is the 2^n multiple. Equivalent of the << operator. */
137
- shiftLeft ( n : BigNumCompatible ) : BigNum ;
138
-
139
- /** Return a new BigNum of the value integer divided by 2^n. Equivalent of the >> operator. */
140
- shiftRight ( n : BigNumCompatible ) : BigNum ;
141
-
142
- /** Return the greatest common divisor of the current BigNum with n as a new BigNum. */
143
- gcd ( n : BigNum ) : BigNum ;
144
-
145
- /**
146
- * Return the Jacobi symbol (or Legendre symbol if n is prime) of the current BigNum (= a) over n.
147
- * Note that n must be odd and >= 3. 0 <= a < n.
148
- *
149
- * Returns -1 or 1 as an int (NOT a BigNum). Throws an error on failure.
150
- */
151
- jacobi ( n : BigNum ) : number ;
152
-
153
- /** Return the number of bits used to represent the current BigNum. */
154
- bitLength ( ) : number ;
155
- }
156
-
157
157
/**
158
158
* Turn a BigNum into a Number.
159
159
*
@@ -265,5 +265,5 @@ declare namespace BigNum {
265
265
}
266
266
267
267
declare module "bignum" {
268
- export = BigNum . BigNum ;
268
+ export = BigNum ;
269
269
}
0 commit comments