ic-mops 0.8.5 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -1
- package/.mops/base@0.7.4/LICENSE +0 -208
- package/.mops/base@0.7.4/README.md +0 -64
- package/.mops/base@0.7.4/mops.toml +0 -5
- package/.mops/base@0.7.4/src/Array.mo +0 -686
- package/.mops/base@0.7.4/src/AssocList.mo +0 -203
- package/.mops/base@0.7.4/src/Blob.mo +0 -55
- package/.mops/base@0.7.4/src/Bool.mo +0 -44
- package/.mops/base@0.7.4/src/Buffer.mo +0 -1937
- package/.mops/base@0.7.4/src/CertifiedData.mo +0 -29
- package/.mops/base@0.7.4/src/Char.mo +0 -67
- package/.mops/base@0.7.4/src/Debug.mo +0 -15
- package/.mops/base@0.7.4/src/Deque.mo +0 -75
- package/.mops/base@0.7.4/src/Error.mo +0 -41
- package/.mops/base@0.7.4/src/ExperimentalCycles.mo +0 -51
- package/.mops/base@0.7.4/src/ExperimentalInternetComputer.mo +0 -36
- package/.mops/base@0.7.4/src/ExperimentalStableMemory.mo +0 -121
- package/.mops/base@0.7.4/src/Float.mo +0 -150
- package/.mops/base@0.7.4/src/Func.mo +0 -38
- package/.mops/base@0.7.4/src/Hash.mo +0 -83
- package/.mops/base@0.7.4/src/HashMap.mo +0 -229
- package/.mops/base@0.7.4/src/Heap.mo +0 -113
- package/.mops/base@0.7.4/src/Int.mo +0 -150
- package/.mops/base@0.7.4/src/Int16.mo +0 -159
- package/.mops/base@0.7.4/src/Int32.mo +0 -160
- package/.mops/base@0.7.4/src/Int64.mo +0 -161
- package/.mops/base@0.7.4/src/Int8.mo +0 -160
- package/.mops/base@0.7.4/src/Iter.mo +0 -220
- package/.mops/base@0.7.4/src/IterType.mo +0 -7
- package/.mops/base@0.7.4/src/List.mo +0 -433
- package/.mops/base@0.7.4/src/Nat.mo +0 -75
- package/.mops/base@0.7.4/src/Nat16.mo +0 -146
- package/.mops/base@0.7.4/src/Nat32.mo +0 -146
- package/.mops/base@0.7.4/src/Nat64.mo +0 -146
- package/.mops/base@0.7.4/src/Nat8.mo +0 -146
- package/.mops/base@0.7.4/src/None.mo +0 -19
- package/.mops/base@0.7.4/src/Option.mo +0 -160
- package/.mops/base@0.7.4/src/Order.mo +0 -46
- package/.mops/base@0.7.4/src/Prelude.mo +0 -33
- package/.mops/base@0.7.4/src/Principal.mo +0 -58
- package/.mops/base@0.7.4/src/RBTree.mo +0 -218
- package/.mops/base@0.7.4/src/Random.mo +0 -188
- package/.mops/base@0.7.4/src/Result.mo +0 -210
- package/.mops/base@0.7.4/src/Stack.mo +0 -40
- package/.mops/base@0.7.4/src/Text.mo +0 -615
- package/.mops/base@0.7.4/src/Time.mo +0 -37
- package/.mops/base@0.7.4/src/Trie.mo +0 -1200
- package/.mops/base@0.7.4/src/TrieMap.mo +0 -180
- package/.mops/base@0.7.4/src/TrieSet.mo +0 -97
- package/.mops/base@0.8.3/LICENSE +0 -208
- package/.mops/base@0.8.3/README.md +0 -64
- package/.mops/base@0.8.3/mops.toml +0 -6
- package/.mops/base@0.8.3/src/Array.mo +0 -717
- package/.mops/base@0.8.3/src/AssocList.mo +0 -404
- package/.mops/base@0.8.3/src/Blob.mo +0 -212
- package/.mops/base@0.8.3/src/Bool.mo +0 -44
- package/.mops/base@0.8.3/src/Buffer.mo +0 -2660
- package/.mops/base@0.8.3/src/CertifiedData.mo +0 -53
- package/.mops/base@0.8.3/src/Char.mo +0 -65
- package/.mops/base@0.8.3/src/Debug.mo +0 -56
- package/.mops/base@0.8.3/src/Deque.mo +0 -243
- package/.mops/base@0.8.3/src/Error.mo +0 -68
- package/.mops/base@0.8.3/src/ExperimentalCycles.mo +0 -151
- package/.mops/base@0.8.3/src/ExperimentalInternetComputer.mo +0 -60
- package/.mops/base@0.8.3/src/ExperimentalStableMemory.mo +0 -348
- package/.mops/base@0.8.3/src/Float.mo +0 -843
- package/.mops/base@0.8.3/src/Func.mo +0 -46
- package/.mops/base@0.8.3/src/Hash.mo +0 -82
- package/.mops/base@0.8.3/src/HashMap.mo +0 -457
- package/.mops/base@0.8.3/src/Heap.mo +0 -233
- package/.mops/base@0.8.3/src/Int.mo +0 -365
- package/.mops/base@0.8.3/src/Int16.mo +0 -521
- package/.mops/base@0.8.3/src/Int32.mo +0 -522
- package/.mops/base@0.8.3/src/Int64.mo +0 -522
- package/.mops/base@0.8.3/src/Int8.mo +0 -522
- package/.mops/base@0.8.3/src/Iter.mo +0 -227
- package/.mops/base@0.8.3/src/IterType.mo +0 -7
- package/.mops/base@0.8.3/src/List.mo +0 -930
- package/.mops/base@0.8.3/src/Nat.mo +0 -305
- package/.mops/base@0.8.3/src/Nat16.mo +0 -144
- package/.mops/base@0.8.3/src/Nat32.mo +0 -144
- package/.mops/base@0.8.3/src/Nat64.mo +0 -144
- package/.mops/base@0.8.3/src/Nat8.mo +0 -144
- package/.mops/base@0.8.3/src/None.mo +0 -19
- package/.mops/base@0.8.3/src/Option.mo +0 -154
- package/.mops/base@0.8.3/src/Order.mo +0 -46
- package/.mops/base@0.8.3/src/Prelude.mo +0 -33
- package/.mops/base@0.8.3/src/Principal.mo +0 -249
- package/.mops/base@0.8.3/src/RBTree.mo +0 -681
- package/.mops/base@0.8.3/src/Random.mo +0 -270
- package/.mops/base@0.8.3/src/Result.mo +0 -209
- package/.mops/base@0.8.3/src/Stack.mo +0 -93
- package/.mops/base@0.8.3/src/Text.mo +0 -761
- package/.mops/base@0.8.3/src/Time.mo +0 -36
- package/.mops/base@0.8.3/src/Timer.mo +0 -62
- package/.mops/base@0.8.3/src/Trie.mo +0 -1603
- package/.mops/base@0.8.3/src/TrieMap.mo +0 -392
- package/.mops/base@0.8.3/src/TrieSet.mo +0 -148
- package/network.txt +0 -1
|
@@ -1,522 +0,0 @@
|
|
|
1
|
-
/// 64-bit signed integers with checked arithmetic.
|
|
2
|
-
///
|
|
3
|
-
/// Common 64-bit integer functions.
|
|
4
|
-
/// Most operations are available as built-in operators (e.g. `1 + 1`).
|
|
5
|
-
import Int "Int";
|
|
6
|
-
import Prim "mo:⛔";
|
|
7
|
-
|
|
8
|
-
module {
|
|
9
|
-
|
|
10
|
-
/// 64-bit signed integers.
|
|
11
|
-
public type Int64 = Prim.Types.Int64;
|
|
12
|
-
|
|
13
|
-
/// Minimum 64-bit integer value, `-2 ** 63`.
|
|
14
|
-
public let minimumValue = -9_223_372_036_854_775_808 : Int64;
|
|
15
|
-
|
|
16
|
-
/// Maximum 64-bit integer value, `+2 ** 63 - 1`.
|
|
17
|
-
public let maximumValue = 9_223_372_036_854_775_807 : Int64;
|
|
18
|
-
|
|
19
|
-
/// Converts a 64-bit signed integer to a signed integer with infinite precision.
|
|
20
|
-
///
|
|
21
|
-
/// Example:
|
|
22
|
-
/// ```motoko
|
|
23
|
-
/// import Int64 "mo:base/Int64";
|
|
24
|
-
///
|
|
25
|
-
/// Int64.toInt(123_456) // => 123_456 : Int
|
|
26
|
-
/// ```
|
|
27
|
-
public let toInt : Int64 -> Int = Prim.int64ToInt;
|
|
28
|
-
|
|
29
|
-
/// Converts a signed integer with infinite precision to a 64-bit signed integer.
|
|
30
|
-
///
|
|
31
|
-
/// Traps on overflow/underflow.
|
|
32
|
-
///
|
|
33
|
-
/// Example:
|
|
34
|
-
/// ```motoko
|
|
35
|
-
/// import Int64 "mo:base/Int64";
|
|
36
|
-
///
|
|
37
|
-
/// Int64.fromInt(123_456) // => +123_456 : Int64
|
|
38
|
-
/// ```
|
|
39
|
-
public let fromInt : Int -> Int64 = Prim.intToInt64;
|
|
40
|
-
|
|
41
|
-
/// Converts a signed integer with infinite precision to a 64-bit signed integer.
|
|
42
|
-
///
|
|
43
|
-
/// Wraps on overflow/underflow.
|
|
44
|
-
///
|
|
45
|
-
/// Example:
|
|
46
|
-
/// ```motoko
|
|
47
|
-
/// import Int64 "mo:base/Int64";
|
|
48
|
-
///
|
|
49
|
-
/// Int64.fromIntWrap(-123_456) // => -123_456 : Int64
|
|
50
|
-
/// ```
|
|
51
|
-
public let fromIntWrap : Int -> Int64 = Prim.intToInt64Wrap;
|
|
52
|
-
|
|
53
|
-
/// Converts an unsigned 64-bit integer to a signed 64-bit integer.
|
|
54
|
-
///
|
|
55
|
-
/// Wraps on overflow/underflow.
|
|
56
|
-
///
|
|
57
|
-
/// Example:
|
|
58
|
-
/// ```motoko
|
|
59
|
-
/// import Int64 "mo:base/Int64";
|
|
60
|
-
///
|
|
61
|
-
/// Int64.fromNat64(123_456) // => +123_456 : Int64
|
|
62
|
-
/// ```
|
|
63
|
-
public let fromNat64 : Nat64 -> Int64 = Prim.nat64ToInt64;
|
|
64
|
-
|
|
65
|
-
/// Converts a signed 64-bit integer to an unsigned 64-bit integer.
|
|
66
|
-
///
|
|
67
|
-
/// Wraps on overflow/underflow.
|
|
68
|
-
///
|
|
69
|
-
/// Example:
|
|
70
|
-
/// ```motoko
|
|
71
|
-
/// import Int64 "mo:base/Int64";
|
|
72
|
-
///
|
|
73
|
-
/// Int64.toNat64(-1) // => 18_446_744_073_709_551_615 : Nat64 // underflow
|
|
74
|
-
/// ```
|
|
75
|
-
public let toNat64 : Int64 -> Nat64 = Prim.int64ToNat64;
|
|
76
|
-
|
|
77
|
-
/// Returns the Text representation of `x`.
|
|
78
|
-
/// Formats the integer in decimal representation without underscore separators for thousand figures.
|
|
79
|
-
///
|
|
80
|
-
/// Example:
|
|
81
|
-
/// ```motoko
|
|
82
|
-
/// import Int64 "mo:base/Int64";
|
|
83
|
-
///
|
|
84
|
-
/// Int64.toText(-123456) // => "-123456"
|
|
85
|
-
/// ```
|
|
86
|
-
public func toText(x : Int64) : Text {
|
|
87
|
-
Int.toText(toInt(x))
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
/// Returns the absolute value of `x`.
|
|
91
|
-
///
|
|
92
|
-
/// Traps when `x == -2 ** 63` (the minimum `Int64` value).
|
|
93
|
-
///
|
|
94
|
-
/// Example:
|
|
95
|
-
/// ```motoko
|
|
96
|
-
/// import Int64 "mo:base/Int64";
|
|
97
|
-
///
|
|
98
|
-
/// Int64.abs(-123456) // => +123_456
|
|
99
|
-
/// ```
|
|
100
|
-
public func abs(x : Int64) : Int64 {
|
|
101
|
-
fromInt(Int.abs(toInt(x)))
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
/// Returns the minimum of `x` and `y`.
|
|
105
|
-
///
|
|
106
|
-
/// Example:
|
|
107
|
-
/// ```motoko
|
|
108
|
-
/// import Int64 "mo:base/Int64";
|
|
109
|
-
///
|
|
110
|
-
/// Int64.min(+2, -3) // => -3
|
|
111
|
-
/// ```
|
|
112
|
-
public func min(x : Int64, y : Int64) : Int64 {
|
|
113
|
-
if (x < y) { x } else { y }
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
/// Returns the maximum of `x` and `y`.
|
|
117
|
-
///
|
|
118
|
-
/// Example:
|
|
119
|
-
/// ```motoko
|
|
120
|
-
/// import Int64 "mo:base/Int64";
|
|
121
|
-
///
|
|
122
|
-
/// Int64.max(+2, -3) // => +2
|
|
123
|
-
/// ```
|
|
124
|
-
public func max(x : Int64, y : Int64) : Int64 {
|
|
125
|
-
if (x < y) { y } else { x }
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
/// Returns `x == y`.
|
|
129
|
-
///
|
|
130
|
-
/// Example:
|
|
131
|
-
/// ```motoko
|
|
132
|
-
/// import Int64 "mo:base/Int64";
|
|
133
|
-
///
|
|
134
|
-
/// Int64.equal(123, 123) // => true
|
|
135
|
-
/// ```
|
|
136
|
-
public func equal(x : Int64, y : Int64) : Bool { x == y };
|
|
137
|
-
|
|
138
|
-
/// Returns `x != y`.
|
|
139
|
-
///
|
|
140
|
-
/// Example:
|
|
141
|
-
/// ```motoko
|
|
142
|
-
/// import Int64 "mo:base/Int64";
|
|
143
|
-
///
|
|
144
|
-
/// Int64.notEqual(123, 123) // => false
|
|
145
|
-
/// ```
|
|
146
|
-
public func notEqual(x : Int64, y : Int64) : Bool { x != y };
|
|
147
|
-
|
|
148
|
-
/// Returns `x < y`.
|
|
149
|
-
///
|
|
150
|
-
/// Example:
|
|
151
|
-
/// ```motoko
|
|
152
|
-
/// import Int64 "mo:base/Int64";
|
|
153
|
-
///
|
|
154
|
-
/// Int64.less(123, 1234) // => true
|
|
155
|
-
/// ```
|
|
156
|
-
public func less(x : Int64, y : Int64) : Bool { x < y };
|
|
157
|
-
|
|
158
|
-
/// Returns `x <= y`.
|
|
159
|
-
///
|
|
160
|
-
/// Example:
|
|
161
|
-
/// ```motoko
|
|
162
|
-
/// import Int64 "mo:base/Int64";
|
|
163
|
-
///
|
|
164
|
-
/// Int64.lessOrEqual(123, 1234) // => true
|
|
165
|
-
/// ```
|
|
166
|
-
public func lessOrEqual(x : Int64, y : Int64) : Bool { x <= y };
|
|
167
|
-
|
|
168
|
-
/// Returns `x > y`.
|
|
169
|
-
///
|
|
170
|
-
/// Example:
|
|
171
|
-
/// ```motoko
|
|
172
|
-
/// import Int64 "mo:base/Int64";
|
|
173
|
-
///
|
|
174
|
-
/// Int64.greater(1234, 123) // => true
|
|
175
|
-
/// ```
|
|
176
|
-
public func greater(x : Int64, y : Int64) : Bool { x > y };
|
|
177
|
-
|
|
178
|
-
/// Returns `x >= y`.
|
|
179
|
-
///
|
|
180
|
-
/// Example:
|
|
181
|
-
/// ```motoko
|
|
182
|
-
/// import Int64 "mo:base/Int64";
|
|
183
|
-
///
|
|
184
|
-
/// Int64.greaterOrEqual(1234, 123) // => true
|
|
185
|
-
/// ```
|
|
186
|
-
public func greaterOrEqual(x : Int64, y : Int64) : Bool { x >= y };
|
|
187
|
-
|
|
188
|
-
/// Returns the order of `x` and `y`.
|
|
189
|
-
///
|
|
190
|
-
/// Example:
|
|
191
|
-
/// ```motoko
|
|
192
|
-
/// import Int64 "mo:base/Int64";
|
|
193
|
-
///
|
|
194
|
-
/// Int64.compare(123, 1234) // => #less
|
|
195
|
-
/// ```
|
|
196
|
-
public func compare(x : Int64, y : Int64) : { #less; #equal; #greater } {
|
|
197
|
-
if (x < y) { #less } else if (x == y) { #equal } else { #greater }
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
/// Returns the negation of `x`, `-x`.
|
|
201
|
-
///
|
|
202
|
-
/// Traps on overflow, i.e. for `neg(-2 ** 63)`.
|
|
203
|
-
///
|
|
204
|
-
///
|
|
205
|
-
/// Example:
|
|
206
|
-
/// ```motoko
|
|
207
|
-
/// import Int64 "mo:base/Int64";
|
|
208
|
-
///
|
|
209
|
-
/// Int64.neg(123) // => -123
|
|
210
|
-
/// ```
|
|
211
|
-
public func neg(x : Int64) : Int64 { -x };
|
|
212
|
-
|
|
213
|
-
/// Returns the sum of `x` and `y`, `x + y`.
|
|
214
|
-
///
|
|
215
|
-
/// Traps on overflow/underflow.
|
|
216
|
-
///
|
|
217
|
-
/// Example:
|
|
218
|
-
/// ```motoko
|
|
219
|
-
/// import Int64 "mo:base/Int64";
|
|
220
|
-
///
|
|
221
|
-
/// Int64.add(1234, 123) // => +1_357
|
|
222
|
-
/// ```
|
|
223
|
-
public func add(x : Int64, y : Int64) : Int64 { x + y };
|
|
224
|
-
|
|
225
|
-
/// Returns the difference of `x` and `y`, `x - y`.
|
|
226
|
-
///
|
|
227
|
-
/// Traps on overflow/underflow.
|
|
228
|
-
///
|
|
229
|
-
/// Example:
|
|
230
|
-
/// ```motoko
|
|
231
|
-
/// import Int64 "mo:base/Int64";
|
|
232
|
-
///
|
|
233
|
-
/// Int64.sub(1234, 123) // => +1_111
|
|
234
|
-
/// ```
|
|
235
|
-
public func sub(x : Int64, y : Int64) : Int64 { x - y };
|
|
236
|
-
|
|
237
|
-
/// Returns the product of `x` and `y`, `x * y`.
|
|
238
|
-
///
|
|
239
|
-
/// Traps on overflow/underflow.
|
|
240
|
-
///
|
|
241
|
-
/// Example:
|
|
242
|
-
/// ```motoko
|
|
243
|
-
/// import Int64 "mo:base/Int64";
|
|
244
|
-
///
|
|
245
|
-
/// Int64.mul(123, 100) // => +12_300
|
|
246
|
-
/// ```
|
|
247
|
-
public func mul(x : Int64, y : Int64) : Int64 { x * y };
|
|
248
|
-
|
|
249
|
-
/// Returns the signed integer division of `x` by `y`, `x / y`.
|
|
250
|
-
/// Rounds the quotient towards zero, which is the same as truncating the decimal places of the quotient.
|
|
251
|
-
///
|
|
252
|
-
/// Traps when `y` is zero.
|
|
253
|
-
///
|
|
254
|
-
/// Example:
|
|
255
|
-
/// ```motoko
|
|
256
|
-
/// import Int64 "mo:base/Int64";
|
|
257
|
-
///
|
|
258
|
-
/// Int64.div(123, 10) // => +12
|
|
259
|
-
/// ```
|
|
260
|
-
public func div(x : Int64, y : Int64) : Int64 { x / y };
|
|
261
|
-
|
|
262
|
-
/// Returns the remainder of the signed integer division of `x` by `y`, `x % y`,
|
|
263
|
-
/// which is defined as `x - x / y * y`.
|
|
264
|
-
///
|
|
265
|
-
/// Traps when `y` is zero.
|
|
266
|
-
///
|
|
267
|
-
/// Example:
|
|
268
|
-
/// ```motoko
|
|
269
|
-
/// import Int64 "mo:base/Int64";
|
|
270
|
-
///
|
|
271
|
-
/// Int64.rem(123, 10) // => +3
|
|
272
|
-
/// ```
|
|
273
|
-
public func rem(x : Int64, y : Int64) : Int64 { x % y };
|
|
274
|
-
|
|
275
|
-
/// Returns `x` to the power of `y`, `x ** y`.
|
|
276
|
-
///
|
|
277
|
-
/// Traps on overflow/underflow and when `y < 0 or y >= 64`.
|
|
278
|
-
///
|
|
279
|
-
/// Example:
|
|
280
|
-
/// ```motoko
|
|
281
|
-
/// import Int64 "mo:base/Int64";
|
|
282
|
-
///
|
|
283
|
-
/// Int64.pow(2, 10) // => +1_024
|
|
284
|
-
/// ```
|
|
285
|
-
public func pow(x : Int64, y : Int64) : Int64 { x ** y };
|
|
286
|
-
|
|
287
|
-
/// Returns the bitwise negation of `x`, `^x`.
|
|
288
|
-
///
|
|
289
|
-
/// Example:
|
|
290
|
-
/// ```motoko
|
|
291
|
-
/// import Int64 "mo:base/Int64";
|
|
292
|
-
///
|
|
293
|
-
/// Int64.bitnot(-256 /* 0xffff_ffff_ffff_ff00 */) // => +255 // 0xff
|
|
294
|
-
/// ```
|
|
295
|
-
public func bitnot(x : Int64) : Int64 { ^x };
|
|
296
|
-
|
|
297
|
-
/// Returns the bitwise "and" of `x` and `y`, `x & y`.
|
|
298
|
-
///
|
|
299
|
-
/// Example:
|
|
300
|
-
/// ```motoko
|
|
301
|
-
/// import Int64 "mo:base/Int64";
|
|
302
|
-
///
|
|
303
|
-
/// Int64.bitand(0xffff, 0x00f0) // => +240 // 0xf0
|
|
304
|
-
/// ```
|
|
305
|
-
public func bitand(x : Int64, y : Int64) : Int64 { x & y };
|
|
306
|
-
|
|
307
|
-
/// Returns the bitwise "or" of `x` and `y`, `x | y`.
|
|
308
|
-
///
|
|
309
|
-
/// Example:
|
|
310
|
-
/// ```motoko
|
|
311
|
-
/// import Int64 "mo:base/Int64";
|
|
312
|
-
///
|
|
313
|
-
/// Int64.bitor(0xffff, 0x00f0) // => +65_535 // 0xffff
|
|
314
|
-
/// ```
|
|
315
|
-
public func bitor(x : Int64, y : Int64) : Int64 { x | y };
|
|
316
|
-
|
|
317
|
-
/// Returns the bitwise "exclusive or" of `x` and `y`, `x ^ y`.
|
|
318
|
-
///
|
|
319
|
-
/// Example:
|
|
320
|
-
/// ```motoko
|
|
321
|
-
/// import Int64 "mo:base/Int64";
|
|
322
|
-
///
|
|
323
|
-
/// Int64.bitxor(0xffff, 0x00f0) // => +65_295 // 0xff0f
|
|
324
|
-
/// ```
|
|
325
|
-
public func bitxor(x : Int64, y : Int64) : Int64 { x ^ y };
|
|
326
|
-
|
|
327
|
-
/// Returns the bitwise left shift of `x` by `y`, `x << y`.
|
|
328
|
-
/// The right bits of the shift filled with zeros.
|
|
329
|
-
/// Left-overflowing bits, including the sign bit, are discarded.
|
|
330
|
-
///
|
|
331
|
-
/// For `y >= 64`, the semantics is the same as for `bitshiftLeft(x, y % 64)`.
|
|
332
|
-
/// For `y < 0`, the semantics is the same as for `bitshiftLeft(x, y + y % 64)`.
|
|
333
|
-
///
|
|
334
|
-
/// Example:
|
|
335
|
-
/// ```motoko
|
|
336
|
-
/// import Int64 "mo:base/Int64";
|
|
337
|
-
///
|
|
338
|
-
/// Int64.bitshiftLeft(1, 8) // => +256 // 0x100 equivalent to `2 ** 8`.
|
|
339
|
-
/// ```
|
|
340
|
-
public func bitshiftLeft(x : Int64, y : Int64) : Int64 { x << y };
|
|
341
|
-
|
|
342
|
-
/// Returns the signed bitwise right shift of `x` by `y`, `x >> y`.
|
|
343
|
-
/// The sign bit is retained and the left side is filled with the sign bit.
|
|
344
|
-
/// Right-underflowing bits are discarded, i.e. not rotated to the left side.
|
|
345
|
-
///
|
|
346
|
-
/// For `y >= 64`, the semantics is the same as for `bitshiftRight(x, y % 64)`.
|
|
347
|
-
/// For `y < 0`, the semantics is the same as for `bitshiftRight (x, y + y % 64)`.
|
|
348
|
-
///
|
|
349
|
-
/// Example:
|
|
350
|
-
/// ```motoko
|
|
351
|
-
/// import Int64 "mo:base/Int64";
|
|
352
|
-
///
|
|
353
|
-
/// Int64.bitshiftRight(1024, 8) // => +4 // equivalent to `1024 / (2 ** 8)`
|
|
354
|
-
/// ```
|
|
355
|
-
public func bitshiftRight(x : Int64, y : Int64) : Int64 { x >> y };
|
|
356
|
-
|
|
357
|
-
/// Returns the bitwise left rotatation of `x` by `y`, `x <<> y`.
|
|
358
|
-
/// Each left-overflowing bit is inserted again on the right side.
|
|
359
|
-
/// The sign bit is rotated like other bits, i.e. the rotation interprets the number as unsigned.
|
|
360
|
-
///
|
|
361
|
-
/// Changes the direction of rotation for negative `y`.
|
|
362
|
-
/// For `y >= 64`, the semantics is the same as for `bitrotLeft(x, y % 64)`.
|
|
363
|
-
///
|
|
364
|
-
/// Example:
|
|
365
|
-
/// ```motoko
|
|
366
|
-
/// import Int64 "mo:base/Int64";
|
|
367
|
-
///
|
|
368
|
-
/// Int64.bitrotLeft(0x2000_0000_0000_0001, 4) // => +18 // 0x12.
|
|
369
|
-
/// ```
|
|
370
|
-
public func bitrotLeft(x : Int64, y : Int64) : Int64 { x <<> y };
|
|
371
|
-
|
|
372
|
-
/// Returns the bitwise right rotation of `x` by `y`, `x <>> y`.
|
|
373
|
-
/// Each right-underflowing bit is inserted again on the right side.
|
|
374
|
-
/// The sign bit is rotated like other bits, i.e. the rotation interprets the number as unsigned.
|
|
375
|
-
///
|
|
376
|
-
/// Changes the direction of rotation for negative `y`.
|
|
377
|
-
/// For `y >= 64`, the semantics is the same as for `bitrotRight(x, y % 64)`.
|
|
378
|
-
///
|
|
379
|
-
/// Example:
|
|
380
|
-
/// ```motoko
|
|
381
|
-
/// import Int64 "mo:base/Int64";
|
|
382
|
-
///
|
|
383
|
-
/// Int64.bitrotRight(0x0002_0000_0000_0001, 48) // => +65538 // 0x1_0002.
|
|
384
|
-
/// ```
|
|
385
|
-
public func bitrotRight(x : Int64, y : Int64) : Int64 { x <>> y };
|
|
386
|
-
|
|
387
|
-
/// Returns the value of bit `p` in `x`, `x & 2**p == 2**p`.
|
|
388
|
-
/// If `p >= 64`, the semantics is the same as for `bittest(x, p % 64)`.
|
|
389
|
-
///
|
|
390
|
-
/// Example:
|
|
391
|
-
/// ```motoko
|
|
392
|
-
/// import Int64 "mo:base/Int64";
|
|
393
|
-
///
|
|
394
|
-
/// Int64.bittest(128, 7) // => true
|
|
395
|
-
/// ```
|
|
396
|
-
public func bittest(x : Int64, p : Nat) : Bool {
|
|
397
|
-
Prim.btstInt64(x, Prim.intToInt64(p))
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
/// Returns the value of setting bit `p` in `x` to `1`.
|
|
401
|
-
/// If `p >= 64`, the semantics is the same as for `bitset(x, p % 64)`.
|
|
402
|
-
///
|
|
403
|
-
/// Example:
|
|
404
|
-
/// ```motoko
|
|
405
|
-
/// import Int64 "mo:base/Int64";
|
|
406
|
-
///
|
|
407
|
-
/// Int64.bitset(0, 7) // => +128
|
|
408
|
-
/// ```
|
|
409
|
-
public func bitset(x : Int64, p : Nat) : Int64 {
|
|
410
|
-
x | (1 << Prim.intToInt64(p))
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
/// Returns the value of clearing bit `p` in `x` to `0`.
|
|
414
|
-
/// If `p >= 64`, the semantics is the same as for `bitclear(x, p % 64)`.
|
|
415
|
-
///
|
|
416
|
-
/// Example:
|
|
417
|
-
/// ```motoko
|
|
418
|
-
/// import Int64 "mo:base/Int64";
|
|
419
|
-
///
|
|
420
|
-
/// Int64.bitclear(-1, 7) // => -129
|
|
421
|
-
/// ```
|
|
422
|
-
public func bitclear(x : Int64, p : Nat) : Int64 {
|
|
423
|
-
x & ^(1 << Prim.intToInt64(p))
|
|
424
|
-
};
|
|
425
|
-
|
|
426
|
-
/// Returns the value of flipping bit `p` in `x`.
|
|
427
|
-
/// If `p >= 64`, the semantics is the same as for `bitclear(x, p % 64)`.
|
|
428
|
-
///
|
|
429
|
-
/// Example:
|
|
430
|
-
/// ```motoko
|
|
431
|
-
/// import Int64 "mo:base/Int64";
|
|
432
|
-
///
|
|
433
|
-
/// Int64.bitflip(255, 7) // => +127
|
|
434
|
-
/// ```
|
|
435
|
-
public func bitflip(x : Int64, p : Nat) : Int64 {
|
|
436
|
-
x ^ (1 << Prim.intToInt64(p))
|
|
437
|
-
};
|
|
438
|
-
|
|
439
|
-
/// Returns the count of non-zero bits in `x`.
|
|
440
|
-
///
|
|
441
|
-
/// Example:
|
|
442
|
-
/// ```motoko
|
|
443
|
-
/// import Int64 "mo:base/Int64";
|
|
444
|
-
///
|
|
445
|
-
/// Int64.bitcountNonZero(0xffff) // => +16
|
|
446
|
-
/// ```
|
|
447
|
-
public let bitcountNonZero : (x : Int64) -> Int64 = Prim.popcntInt64;
|
|
448
|
-
|
|
449
|
-
/// Returns the count of leading zero bits in `x`.
|
|
450
|
-
///
|
|
451
|
-
/// Example:
|
|
452
|
-
/// ```motoko
|
|
453
|
-
/// import Int64 "mo:base/Int64";
|
|
454
|
-
///
|
|
455
|
-
/// Int64.bitcountLeadingZero(0x8000_0000) // => +32
|
|
456
|
-
/// ```
|
|
457
|
-
public let bitcountLeadingZero : (x : Int64) -> Int64 = Prim.clzInt64;
|
|
458
|
-
|
|
459
|
-
/// Returns the count of trailing zero bits in `x`.
|
|
460
|
-
///
|
|
461
|
-
/// Example:
|
|
462
|
-
/// ```motoko
|
|
463
|
-
/// import Int64 "mo:base/Int64";
|
|
464
|
-
///
|
|
465
|
-
/// Int64.bitcountTrailingZero(0x0201_0000) // => +16
|
|
466
|
-
/// ```
|
|
467
|
-
public let bitcountTrailingZero : (x : Int64) -> Int64 = Prim.ctzInt64;
|
|
468
|
-
|
|
469
|
-
/// Returns the sum of `x` and `y`, `x +% y`.
|
|
470
|
-
///
|
|
471
|
-
/// Wraps on overflow/underflow.
|
|
472
|
-
///
|
|
473
|
-
///
|
|
474
|
-
/// Example:
|
|
475
|
-
/// ```motoko
|
|
476
|
-
/// import Int64 "mo:base/Int64";
|
|
477
|
-
///
|
|
478
|
-
/// Int64.addWrap(2 ** 62, 2 ** 62) // => -9_223_372_036_854_775_808 // overflow
|
|
479
|
-
/// ```
|
|
480
|
-
public func addWrap(x : Int64, y : Int64) : Int64 { x +% y };
|
|
481
|
-
|
|
482
|
-
/// Returns the difference of `x` and `y`, `x -% y`.
|
|
483
|
-
///
|
|
484
|
-
/// Wraps on overflow/underflow.
|
|
485
|
-
///
|
|
486
|
-
///
|
|
487
|
-
/// Example:
|
|
488
|
-
/// ```motoko
|
|
489
|
-
/// import Int64 "mo:base/Int64";
|
|
490
|
-
///
|
|
491
|
-
/// Int64.subWrap(-2 ** 63, 1) // => +9_223_372_036_854_775_807 // underflow
|
|
492
|
-
/// ```
|
|
493
|
-
public func subWrap(x : Int64, y : Int64) : Int64 { x -% y };
|
|
494
|
-
|
|
495
|
-
/// Returns the product of `x` and `y`, `x *% y`. Wraps on overflow.
|
|
496
|
-
///
|
|
497
|
-
/// Wraps on overflow/underflow.
|
|
498
|
-
///
|
|
499
|
-
///
|
|
500
|
-
/// Example:
|
|
501
|
-
/// ```motoko
|
|
502
|
-
/// import Int64 "mo:base/Int64";
|
|
503
|
-
///
|
|
504
|
-
/// Int64.mulWrap(2 ** 32, 2 ** 32) // => 0 // overflow
|
|
505
|
-
/// ```
|
|
506
|
-
public func mulWrap(x : Int64, y : Int64) : Int64 { x *% y };
|
|
507
|
-
|
|
508
|
-
/// Returns `x` to the power of `y`, `x **% y`.
|
|
509
|
-
///
|
|
510
|
-
/// Wraps on overflow/underflow.
|
|
511
|
-
/// Traps if `y < 0 or y >= 64`.
|
|
512
|
-
///
|
|
513
|
-
///
|
|
514
|
-
/// Example:
|
|
515
|
-
/// ```motoko
|
|
516
|
-
/// import Int64 "mo:base/Int64";
|
|
517
|
-
///
|
|
518
|
-
/// Int64.powWrap(2, 63) // => -9_223_372_036_854_775_808 // overflow
|
|
519
|
-
/// ```
|
|
520
|
-
public func powWrap(x : Int64, y : Int64) : Int64 { x **% y };
|
|
521
|
-
|
|
522
|
-
}
|