You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[ ]`ZZ(n).get(3)` - `returns the equivalence class [3]_n`
83
+
*[ ]`a.add(b)` - no comment
84
+
*[ ]`a.sub(b)` - no comment
85
+
*[ ]`a.mul(b)` - no comment
86
+
*[ ]`a.inv()` - inverse `a` modulo `n`
87
+
*[ ]`a.square()` - no comment
88
+
*[ ]`a.pow(b)` - no comment
89
+
90
+
91
+
### Bit operations
92
+
93
+
We should really have two packages:
94
+
95
+
- One for immutable, keyable, hashable integers.
96
+
- One for safe in-place word array manipulation.
97
+
98
+
There are multiple reasons for this:
99
+
100
+
- Some bit operations do not really care about endianess
101
+
- It only works efficiently with a radix that is a power of 2
102
+
103
+
Q: Does it make any sense to have those operations defined for unbounded
104
+
integers?
105
+
106
+
The following will be implemented in a package to come.
107
+
108
+
*[ ]`a.or(b)` - or (`i`, `u`, `iu`)
109
+
*[ ]`a.and(b)` - and (`i`, `u`, `iu`, `andln`) (NOTE: `andln` is going to be replaced with `andn` in future)
110
+
*[ ]`a.xor(b)` - xor (`i`, `u`, `iu`)
111
+
*[ ]`a.setn(b)` - set specified bit to `1`
112
+
*[ ]`a.shln(b)` - shift left (`i`, `u`, `iu`)
113
+
*[ ]`a.shrn(b)` - shift right (`i`, `u`, `iu`)
114
+
*[ ]`a.testn(b)` - test if specified bit is set
115
+
*[ ]`a.maskn(b)` - clear bits with indexes higher or equal to `b` (`i`)
116
+
*[ ]`a.bincn(b)` - add `1 << b` to the number
117
+
*[ ]`a.notn(w)` - not (for the width specified by `w`) (`i`)
118
+
119
+
### Test
120
+
121
+
*[x]`a.sign()` - return -1, 0, 1
122
+
*[x]`a.iszero()` - no comments
123
+
*[x]`a.isone()` - no comments
124
+
*[x]`a.ispositive()` - no comments
125
+
*[x]`a.isnegative()` - no comments
126
+
*[x]`a.isnonnegative()` - no comments
127
+
*[x]`a.isnonpositive()` - no comments
128
+
*[x]`a.iseven()` - no comments
129
+
*[x]`a.isodd()` - no comments
130
+
*[x]`a.divides(b)` - no comments
131
+
132
+
### Utilities
133
+
134
+
*[x]`ZZ.has(object)` - returns true if the supplied `object` is an integer.
135
+
*[x]`ZZ.max(a, b)` - return `a` if `a` larger than `b`.
136
+
*[x]`ZZ.min(a, b)` - return `a` if `a` smaller than `b`.
137
+
*[ ]`a.bitLength()` - get number of bits occupied
138
+
*[ ]`a.zeroBits()` - return number of less-significant consequent zero bits (example: `1010000` has 4 zero bits)
139
+
*[ ]`a.byteLength()` - return number of bytes occupied
140
+
*[ ]`a.toTwos(width)` - convert to two's complement representation, where `width` is bit width
141
+
*[ ]`a.fromTwos(width)` - convert from two's complement representation, where `width` is the bit width
142
+
143
+
### Conversion
144
+
*[x]`a.toString(base=10)` - convert to base-string (No zero padding, this is up to you)
145
+
*[x]`a.bin()` - alias for `a.toString(2)`
146
+
*[x]`a.oct()` - alias for `a.toString(8)`
147
+
*[x]`a.hex()` - alias for `a.toString(16)`
148
+
*[x]`d = a.digits(base=10)` - returns little endian array of digits in given base so that d[0] is the first digit, d[1] the second, etc.
149
+
*[x]`a.bin()` - alias for `a.digits(2)`.
150
+
*[x]`a.valueOf()` - convert to Javascript Number (limited to 53 bits `toNumber` in bn.js)
151
+
*[x]`a.toJSON()` - convert to JSON compatible hex string (alias of `toString(16)`)
152
+
*[ ]`a.to(type, endian, length)` - convert to an instance of `type`, which must behave like an `Array` (`toArrayLike` in bn.js)
153
+
*[ ]`a.toArray(endian, length)` - convert to byte `Array`, and optionally zero pad to length, throwing if already exceeding
154
+
*[ ]`a.toBuffer(endian, length)` - convert to Node.js Buffer (if available). For compatibility with browserify and similar tools, use this instead: `a.toArrayLike(Buffer, endian, length)`
0 commit comments