-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathint64_nonjs.mbt
1687 lines (1618 loc) · 49.3 KB
/
int64_nonjs.mbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2025 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
///|
/// Performs unary negation on a 64-bit signed integer, returning its arithmetic
/// inverse.
///
/// Parameters:
///
/// * `value` : The 64-bit signed integer to negate.
///
/// Returns the arithmetic negation of the input value. For all inputs except
/// `Int64::min_value()`, returns the value with opposite sign. When the input is
/// `Int64::min_value()`, returns `Int64::min_value()` due to two's complement
/// representation.
///
/// Example:
///
/// ```moonbit
/// test "Int64::op_neg" {
/// inspect!(-42L, content="-42")
/// inspect!(--42L, content="42")
/// inspect!(-9223372036854775808L, content="-9223372036854775808") // negating min value
/// }
/// ```
pub impl Neg for Int64 with op_neg(self : Int64) -> Int64 = "%i64_neg"
///|
/// Adds two 64-bit integers together. Performs overflow checking and wrapping
/// according to two's complement arithmetic.
///
/// Parameters:
///
/// * `self` : The first 64-bit integer operand.
/// * `other` : The second 64-bit integer operand to add to the first.
///
/// Returns a new 64-bit integer representing the sum of the two operands.
///
/// Example:
///
/// ```moonbit
/// test "Int64::op_add" {
/// let a = 9223372036854775807L // Int64 maximum value
/// let b = 1L
/// inspect!(a + b, content="-9223372036854775808") // Wraps around to minimum value
/// inspect!(42L + -42L, content="0")
/// }
/// ```
pub impl Add for Int64 with op_add(self, other) = "%i64_add"
///|
/// Performs subtraction between two 64-bit integers.
///
/// Parameters:
///
/// * `self` : The minuend (the number being subtracted from).
/// * `other` : The subtrahend (the number to subtract).
///
/// Returns the difference between `self` and `other` as a 64-bit integer.
///
/// Example:
///
/// ```moonbit
/// test "Int64::op_sub" {
/// let a = 9223372036854775807L // Int64 maximum value
/// let b = 1L
/// inspect!(a - b, content="9223372036854775806")
/// let c = -9223372036854775808L // Int64 minimum value
/// let d = 1L
/// inspect!(c - d, content="9223372036854775807")
/// }
/// ```
pub impl Sub for Int64 with op_sub(self, other) = "%i64_sub"
///|
/// Multiplies two 64-bit integers.
///
/// Parameters:
///
/// * `self` : The first 64-bit integer operand.
/// * `other` : The second 64-bit integer operand.
///
/// Returns the product of the two 64-bit integers. If the result overflows the
/// range of `Int64`, it will be truncated according to two's complement
/// arithmetic.
///
/// Example:
///
/// ```moonbit
/// test "Int64::op_mul" {
/// let a = 42L
/// let b = 100L
/// inspect!(a * b, content="4200")
/// let c = -42L
/// inspect!(c * b, content="-4200")
/// }
/// ```
pub impl Mul for Int64 with op_mul(self, other) = "%i64_mul"
///|
/// Performs integer division between two 64-bit integers. Truncates the result
/// towards zero.
///
/// Parameters:
///
/// * `self` : The dividend (the number to be divided).
/// * `other` : The divisor (the number to divide by).
///
/// Returns the quotient of the division.
///
/// Throws a panic if `other` is zero.
///
/// Example:
///
/// ```moonbit
/// test "Int64::op_div" {
/// let a = 42L
/// let b = 5L
/// inspect!(a / b, content="8")
/// let c = -42L
/// let d = 5L
/// inspect!(c / d, content="-8")
/// }
///
/// test "panic Int64::op_div/division_by_zero" {
/// let a = 42L
/// ignore(a / 0L) // Division by zero
/// }
/// ```
pub impl Div for Int64 with op_div(self, other) = "%i64_div"
///|
/// Calculates the remainder of the division between two 64-bit integers. The
/// result follows the formula `self - (self / other) * other`, maintaining the
/// same sign as the dividend.
///
/// Parameters:
///
/// * `self` : The dividend 64-bit integer.
/// * `other` : The divisor 64-bit integer.
///
/// Returns the remainder of the division.
///
/// Throws a panic if `other` is zero.
///
/// Example:
///
/// ```moonbit
/// test "Int64::op_mod" {
/// inspect!(7L % 3L, content="1")
/// inspect!(-7L % 3L, content="-1")
/// inspect!(7L % -3L, content="1")
/// }
///
/// test "panic Int64::op_mod/division_by_zero" {
/// ignore(7L % 0L) // Panics with division by zero
/// }
/// ```
pub impl Mod for Int64 with op_mod(self, other) = "%i64_mod"
///|
/// Performs a bitwise NOT operation on a 64-bit integer. Each bit in the input
/// value is flipped (0 becomes 1 and 1 becomes 0).
///
/// Parameters:
///
/// * `self` : The 64-bit integer on which to perform the bitwise NOT operation.
///
/// Returns a new 64-bit integer where each bit is the inverse of the
/// corresponding bit in the input value.
///
/// Example:
///
/// ```moonbit
/// test "Int64::lnot" {
/// let a = -1L // All bits are 1
/// let b = 0L // All bits are 0
/// inspect!(a.lnot(), content="0")
/// inspect!(b.lnot(), content="-1")
/// }
/// ```
pub fn Int64::lnot(self : Int64) -> Int64 = "%i64_lnot"
///|
/// Performs a bitwise AND operation between two 64-bit signed integers.
///
/// Parameters:
///
/// * `self` : The first 64-bit integer operand.
/// * `other` : The second 64-bit integer operand.
///
/// Returns a 64-bit integer where each bit is set to 1 if and only if the
/// corresponding bits in both operands are 1.
///
/// Example:
///
/// ```moonbit
/// test "Int64::land" {
/// let a = 0xFF00FF00L
/// let b = 0x0F0F0F0FL
/// inspect!(a & b, content="251662080") // 0x0F000F00
/// }
/// ```
pub impl BitAnd for Int64 with land(self, other) = "%i64_land"
///|
/// Performs a bitwise OR operation between two 64-bit integers.
///
/// Parameters:
///
/// * `self` : The first 64-bit integer operand.
/// * `other` : The second 64-bit integer operand.
///
/// Returns a new 64-bit integer where each bit is set to 1 if at least one of
/// the corresponding bits in either operand is 1.
///
/// Example:
///
/// ```moonbit
/// test "Int64::lor" {
/// let a = 0xFF00L // 1111_1111_0000_0000
/// let b = 0x0FF0L // 0000_1111_1111_0000
/// inspect!(a | b, content="65520") // 1111_1111_1111_0000 = 65520
/// }
/// ```
pub impl BitOr for Int64 with lor(self, other) = "%i64_lor"
///|
/// Performs a bitwise XOR operation between two 64-bit integers. Each bit of the
/// result is set to 1 if the corresponding bits of the operands are different,
/// and 0 if they are the same.
///
/// Parameters:
///
/// * `self` : The first 64-bit integer operand.
/// * `other` : The second 64-bit integer operand.
///
/// Returns a new 64-bit integer containing the result of the bitwise XOR
/// operation.
///
/// Example:
///
/// ```moonbit
/// test "Int64::lxor" {
/// let a = 0xF0F0F0F0F0F0F0F0L
/// let b = 0x0F0F0F0F0F0F0F0FL
/// inspect!(a ^ b, content="-1") // All bits set to 1
/// inspect!(a ^ a, content="0") // XOR with self gives 0
/// }
/// ```
pub impl BitXOr for Int64 with lxor(self, other) = "%i64_lxor"
///|
/// Performs a left shift operation on a 64-bit signed integer. Shifts each bit
/// in the integer to the left by the specified number of positions, filling the
/// vacated bit positions with zeros.
///
/// Parameters:
///
/// * `self` : The 64-bit signed integer to be shifted.
/// * `shift` : The number of positions to shift. Must be non-negative and less
/// than 64.
///
/// Returns a new 64-bit integer with bits shifted left by the specified number
/// of positions.
///
/// Example:
///
/// ```moonbit
/// test "Int64::lsl" {
/// let x = 1L
/// inspect!(x << 2, content="4") // Binary: 1 -> 100
/// }
/// ```
///
#deprecated("Use infix operator `<<` instead")
#coverage.skip
pub fn Int64::lsl(self : Int64, other : Int) -> Int64 = "%i64_shl"
///|
/// Performs a left shift operation on a 64-bit integer value. Shifts the bits of
/// the integer to the left by a specified number of positions, filling the
/// rightmost positions with zeros.
///
/// Parameters:
///
/// * `self` : The 64-bit integer value to be shifted.
/// * `shift` : The number of positions to shift the bits to the left.
///
/// Returns a new 64-bit integer value after performing the left shift operation.
///
/// Example:
///
/// ```moonbit
/// test "Int64::shl" {
/// let x = 1L
/// inspect!(x << 3, content="8") // Equivalent to x << 3
/// }
/// ```
///
#deprecated("Use infix operator `<<` instead")
#coverage.skip
pub fn Int64::shl(self : Int64, other : Int) -> Int64 = "%i64_shl"
///|
/// **DEPRECATED:** Use `UInt64` type and infix operator `>>` instead.
///
/// Performs a logical right shift on a 64-bit integer value. In a logical right
/// shift, zeros are shifted in from the left, regardless of the sign bit.
///
/// Parameters:
///
/// * `value` : The 64-bit integer value to be shifted.
/// * `shift` : The number of positions to shift right. Must be non-negative.
///
/// Returns a new 64-bit integer value that is the result of shifting the bits of
/// `value` right by `shift` positions.
///
/// Example:
///
/// ```moonbit
/// test "Int64::lsr" {
/// let x = (-4L).reinterpret_as_uint64() // Convert to UInt64 first
/// inspect!(x >> 1, content="9223372036854775806") // Using the recommended operator
/// }
/// ```
///
#deprecated("Use UInt64 type and infix operator `>>` instead")
#coverage.skip
pub fn Int64::lsr(self : Int64, other : Int) -> Int64 = "%u64.shr"
///|
/// DEPRECATED: Use the infix operator `>>` instead.
///
/// Performs an arithmetic right shift operation on a 64-bit integer. In an
/// arithmetic right shift, the leftmost bit (sign bit) is copied to fill in from
/// the left. This preserves the sign of the number.
///
/// Parameters:
///
/// * `self` : The 64-bit integer to be shifted.
/// * `positions` : The number of positions to shift right. Must be non-negative.
///
/// Returns a new 64-bit integer that is the result of shifting `self` right by
/// `positions` bits, with sign extension.
///
/// Example:
///
/// ```moonbit
/// test "Int64::asr" {
/// let x = -240L // 0b1111_1111_0001_0000 in two's complement
/// inspect!(x >> 4, content="-15") // 0b1111_1111_1111_0001, using recommended syntax
/// }
/// ```
///
#deprecated("Use infix operator `>>` instead")
#coverage.skip
pub fn Int64::asr(self : Int64, other : Int) -> Int64 = "%i64_shr"
///|
/// Performs an arithmetic right shift operation on a 64-bit integer value,
/// shifting the bits to the right by the specified number of positions. The sign
/// bit is copied to fill the leftmost positions.
///
/// Parameters:
///
/// * `self` : The 64-bit integer value to be shifted.
/// * `shift` : The number of bit positions to shift right. Must be non-negative.
///
/// Returns a new `Int64` value representing the result of the arithmetic right
/// shift operation.
///
/// Example:
///
/// ```moonbit
/// test "Int64::shr" {
/// let n = -1024L
/// inspect!(n >> 3, content="-128") // Preserves sign bit
/// }
/// ```
///
#deprecated("Use infix operator `>>` instead")
#coverage.skip
pub fn Int64::shr(self : Int64, other : Int) -> Int64 = "%i64_shr"
///|
/// Performs a left shift operation on a 64-bit integer value. Shifts the bits of
/// the first operand to the left by the number of positions specified by the
/// second operand. The rightmost positions are filled with zeros.
///
/// Parameters:
///
/// * `self` : The 64-bit integer value to be shifted.
/// * `shift` : The number of positions to shift the bits to the left. Must be
/// non-negative and less than 64.
///
/// Returns a new `Int64` value representing the result of the left shift
/// operation.
///
/// Example:
///
/// ```moonbit
/// test "Int64::op_shl" {
/// let n = 1L
/// inspect!(n << 3, content="8") // 1 shifted left by 3 positions becomes 8
/// let m = -4L
/// inspect!(m << 2, content="-16") // -4 shifted left by 2 positions becomes -16
/// }
/// ```
pub impl Shl for Int64 with op_shl(self, other) = "%i64_shl"
///|
/// Performs arithmetic right shift operation on a 64-bit integer value by a
/// specified number of bits. Preserves the sign bit of the original number while
/// shifting its bits right, filling the leftmost positions with copies of the
/// sign bit.
///
/// Parameters:
///
/// * `self` : The 64-bit integer value to be shifted.
/// * `shift_count` : The number of positions to shift right. Must be
/// non-negative and less than 64.
///
/// Returns a new `Int64` value that represents the result of shifting `self`
/// right by `shift_count` bits.
///
/// Example:
///
/// ```moonbit
/// test "Int64::op_shr" {
/// let n = -1024L
/// inspect!(n >> 3, content="-128") // Preserves sign bit
/// let p = 1024L
/// inspect!(p >> 3, content="128") // Regular right shift for positive numbers
/// }
/// ```
pub impl Shr for Int64 with op_shr(self, other) = "%i64_shr"
///|
/// Returns the number of trailing zero bits in a 64-bit integer. For zero input,
/// returns 64.
///
/// Parameters:
///
/// * `value` : The 64-bit integer to count trailing zeros in.
///
/// Returns the number of trailing zero bits (0 to 64).
///
/// Example:
///
/// ```moonbit
/// test "Int64::ctz" {
/// inspect!(0x8000000000000000L.ctz(), content="63") // Binary: 1000...0000
/// inspect!(0x0000000000000001L.ctz(), content="0") // Binary: ...0001
/// inspect!(0L.ctz(), content="64") // All zeros
/// }
/// ```
pub fn Int64::ctz(self : Int64) -> Int = "%i64_ctz"
///|
/// Counts the number of leading zero bits in a 64-bit signed integer, starting
/// from the most significant bit.
///
/// Parameters:
///
/// * `number` : The 64-bit signed integer whose leading zeros are to be counted.
///
/// Returns the number of leading zero bits (0 to 64).
///
/// Example:
///
/// ```moonbit
/// test "Int64::clz" {
/// let a = 0x0000_0001_0000_0000L
/// inspect!(a.clz(), content="31") // 31 leading zeros before the first 1 bit
/// let b = 0L
/// inspect!(b.clz(), content="64") // All bits are zero
/// }
/// ```
pub fn Int64::clz(self : Int64) -> Int = "%i64_clz"
///|
/// Returns the number of 1 bits ('population count') in the 64-bit integer's
/// binary representation.
///
/// Parameters:
///
/// * `value` : The 64-bit integer whose bits are to be counted.
///
/// Returns an integer representing the number of set bits (1s) in the binary
/// representation of the input.
///
/// Example:
///
/// ```moonbit
/// test "Int64::popcnt" {
/// let x = 0x7000_0001_1F00_100FL // 0111000000000000000000000001000111110000000100001111
/// inspect!(x.popcnt(), content="14")
/// }
/// ```
///
/// ```moonbit
/// test "Int64::popcnt/edge_cases" {
/// inspect!((-1L).popcnt(), content="64") // All bits set
/// inspect!(0L.popcnt(), content="0") // No bits set
/// }
/// ```
pub fn Int64::popcnt(self : Int64) -> Int = "%i64_popcnt"
///|
/// Tests if two 64-bit integers are equal.
///
/// Parameters:
///
/// * `self` : The first 64-bit integer to compare.
/// * `other` : The second 64-bit integer to compare.
///
/// Returns `true` if both integers are equal, `false` otherwise.
///
/// Example:
///
/// ```moonbit
/// test "Int64::op_equal" {
/// let a = 42L
/// let b = 42L
/// let c = -42L
/// inspect!(a == b, content="true")
/// inspect!(a == c, content="false")
/// }
/// ```
pub impl Eq for Int64 with op_equal(self : Int64, other : Int64) -> Bool = "%i64_eq"
///|
/// Compares two 64-bit integers and returns their relative order.
///
/// Parameters:
///
/// * `self` : The first 64-bit integer to compare.
/// * `other` : The second 64-bit integer to compare against.
///
/// Returns an integer indicating the relative order:
///
/// * A negative value if `self` is less than `other`
/// * Zero if `self` equals `other`
/// * A positive value if `self` is greater than `other`
///
/// Example:
///
/// ```moonbit
/// test "Int64::compare" {
/// let a = 42L
/// let b = 24L
/// let c = -42L
/// inspect!(a.compare(b), content="1") // 42 > 24
/// inspect!(b.compare(a), content="-1") // 24 < 42
/// inspect!(c.compare(a), content="-1") // -42 < 42
/// inspect!(a.compare(a), content="0") // 42 = 42
/// }
/// ```
pub impl Compare for Int64 with compare(self, other) = "%i64_compare"
///|
/// Returns the default value for `Int64` type, which is zero (0L).
///
/// Returns a 64-bit signed integer with value 0.
///
/// Example:
///
/// ```moonbit
/// test "Int64::default" {
/// inspect!(Int64::default(), content="0")
/// }
/// ```
pub impl Default for Int64 with default() = "%i64_default"
///|
/// Converts a 64-bit signed integer to a 32-bit signed integer by truncating
/// higher bits.
///
/// Parameters:
///
/// * `value` : The 64-bit signed integer (`Int64`) to be converted.
///
/// Returns a 32-bit signed integer (`Int`). Note that values outside the range
/// of 32-bit integers will be truncated, potentially leading to loss of
/// information.
///
/// Example:
///
/// ```moonbit
/// test "Int64::to_int" {
/// let small = 42L
/// let big = 2147483648L // 2^31
/// inspect!(small.to_int(), content="42")
/// inspect!(big.to_int(), content="-2147483648") // Truncated to Int.min_value
/// }
/// ```
pub fn Int64::to_int(self : Int64) -> Int = "%i64_to_i32"
///|
/// Converts a 64-bit signed integer to a double-precision floating-point number.
///
/// Parameters:
///
/// * `self` : The 64-bit signed integer to be converted.
///
/// Returns a double-precision floating-point number that represents the same
/// value as the input integer.
///
/// Example:
///
/// ```moonbit
/// test "Int64::to_double" {
/// let big = 9223372036854775807L // max value of Int64
/// inspect!(big.to_double(), content="9223372036854776000")
/// let neg = -42L
/// inspect!(neg.to_double(), content="-42")
/// }
/// ```
pub fn Int64::to_double(self : Int64) -> Double = "%i64_to_f64"
///|
/// Reinterprets the bits of a 64-bit signed integer as a double-precision
/// floating-point number (IEEE 754). The bit pattern is preserved exactly, only
/// the type interpretation changes.
///
/// Parameters:
///
/// * `value` : The 64-bit signed integer whose bits are to be reinterpreted as a
/// double-precision floating-point number.
///
/// Returns a double-precision floating-point number whose bit pattern is
/// identical to the input integer.
///
/// Example:
///
/// ```moonbit
/// test "Int64::reinterpret_as_double" {
/// let n = 4607182418800017408L // Bit pattern for 1.0
/// inspect!(n.reinterpret_as_double(), content="1")
/// }
/// ```
pub fn Int64::reinterpret_as_double(self : Int64) -> Double = "%i64_to_f64_reinterpret"
///|
/// Reinterprets the bits of an unsigned 64-bit integer as a double-precision
/// floating-point number according to IEEE 754 standard. The bit pattern of the
/// input is preserved, only the type interpretation changes.
///
/// Parameters:
///
/// * `value` : The unsigned 64-bit integer whose bits are to be reinterpreted as
/// a double-precision floating-point number.
///
/// Returns a double-precision floating-point number that has the same bit
/// pattern as the input unsigned 64-bit integer.
///
/// Example:
///
/// ```moonbit
/// test "UInt64::reinterpret_as_double" {
/// // 0x4045000000000000 represents 42.0 in IEEE 754 double format
/// let n = 4636737291354636288UL
/// inspect!(n.reinterpret_as_double(), content="100")
/// }
/// ```
pub fn UInt64::reinterpret_as_double(self : UInt64) -> Double = "%i64_to_f64_reinterpret"
///|
/// Converts a 64-bit signed integer to a byte by taking its least significant 8
/// bits. Any bits beyond the first 8 bits are truncated.
///
/// Parameters:
///
/// * `self` : The 64-bit signed integer to be converted. Only the least
/// significant 8 bits will be used.
///
/// Returns a byte containing the least significant 8 bits of the input integer.
///
/// Example:
///
/// ```moonbit
/// test "Int64::to_byte" {
/// let n = 258L // In binary: 100000010
/// inspect!(n.to_byte(), content="b'\\x02'") // Only keeps 00000010
/// let neg = -1L // In binary: all 1's
/// inspect!(neg.to_byte(), content="b'\\xFF'") // Only keeps 11111111
/// }
/// ```
pub fn Int64::to_byte(self : Int64) -> Byte = "%i64_to_byte"
///|
/// Converts a 64-bit signed integer to a 16-bit signed integer by truncating the
/// value to fit within the 16-bit range (-32768 to 32767).
///
/// Parameters:
///
/// * `value` : The 64-bit signed integer to be converted.
///
/// Returns a 16-bit signed integer representing the lower 16 bits of the input
/// value.
///
/// Example:
///
/// ```moonbit
/// test "Int64::to_int16" {
/// let big = 100000L
/// inspect!(big.to_int16(), content="-31072") // 100000 doesn't fit in Int16, gets truncated
/// let small = 42L
/// inspect!(small.to_int16(), content="42") // 42 fits in Int16, remains unchanged
/// }
/// ```
pub fn Int64::to_int16(self : Int64) -> Int16 = "%i64_to_i16"
///|
/// Converts a 64-bit signed integer to a 16-bit unsigned integer by truncating
/// the value to fit within the range of UInt16 (0 to 65535).
///
/// Parameters:
///
/// * `value` : The 64-bit signed integer to be converted to UInt16.
///
/// Returns a 16-bit unsigned integer representing the lower 16 bits of the input
/// value.
///
/// Example:
///
/// ```moonbit
/// test "Int64::to_uint16" {
/// inspect!(42L.to_uint16(), content="42")
/// inspect!((-1L).to_uint16(), content="65535") // Wraps around to maximum UInt16 value
/// inspect!(70000L.to_uint16(), content="4464") // Value is truncated
/// }
/// ```
pub fn Int64::to_uint16(self : Int64) -> UInt16 = "%i64_to_u16"
///|
/// Converts a double-precision floating-point number to an unsigned 64-bit
/// integer by truncating its decimal part. This is a raw conversion function
/// that does not handle special cases like NaN or infinity.
///
/// Parameters:
///
/// * `value` : The double-precision floating-point number to be truncated and
/// converted.
///
/// Returns an unsigned 64-bit integer. The decimal part of the input is
/// discarded (truncated towards zero).
///
/// Example:
///
/// ```moonbit
/// test "UInt64::trunc_double" {
/// inspect!(UInt64::trunc_double(42.75), content="42")
/// }
/// ```
pub fn UInt64::trunc_double(val : Double) -> UInt64 = "%f64.to_u64"
///|
/// Converts a 64-bit integer to a 32-bit floating-point number. The conversion
/// may result in loss of precision due to the limited precision of the 32-bit
/// floating-point format.
///
/// Parameters:
///
/// * `self` : The 64-bit integer value to be converted.
///
/// Returns a 32-bit floating-point number that represents the input integer
/// value. Note that for values outside the range of representable 32-bit
/// floating-point numbers, the result will be rounded to the nearest
/// representable value.
///
/// Example:
///
/// ```moonbit
/// test "Int64::to_float" {
/// let n = 42L
/// let f = n.to_float()
/// // Convert to double for comparison since Float doesn't implement Show
/// inspect!(f.to_double(), content="42")
/// }
/// ```
pub fn Int64::to_float(self : Int64) -> Float = "%i64.to_f32"
///|
/// Converts an unsigned 32-bit integer to an unsigned 64-bit integer by
/// zero-extending it. The resulting value preserves the original number's
/// magnitude while using 64 bits to represent it.
///
/// Parameters:
///
/// * `value` : The unsigned 32-bit integer (`UInt`) to be converted.
///
/// Returns an unsigned 64-bit integer (`UInt64`) representing the same numerical
/// value as the input.
///
/// Example:
///
/// ```moonbit
/// test "UInt64::extend_uint" {
/// let n = 42U
/// inspect!(UInt64::extend_uint(n), content="42")
/// let max = 4294967295U // Maximum value of UInt
/// inspect!(UInt64::extend_uint(max), content="4294967295")
/// }
/// ```
pub fn UInt64::extend_uint(val : UInt) -> UInt64 = "%u32.to_u64"
///|
/// Converts a 32-bit signed integer to a 64-bit signed integer. All 32-bit
/// integers can be represented exactly in 64-bit integer format, so the
/// conversion is lossless.
///
/// Parameters:
///
/// * `self` : The 32-bit signed integer to be converted.
///
/// Returns a 64-bit signed integer that represents the same numerical value as
/// the input.
///
/// Example:
///
/// ```moonbit
/// test "Int::to_int64" {
/// let n = 42
/// inspect!(n.to_int64(), content="42")
/// let neg = -42
/// inspect!(neg.to_int64(), content="-42")
/// }
/// ```
pub fn Int::to_int64(self : Int) -> Int64 = "%i32_to_i64"
///|
pub fn Int16::to_int64(self : Int16) -> Int64 = "%i16_to_i64"
///|
/// Converts an unsigned 16-bit integer to a signed 64-bit integer. The resulting
/// value will always be non-negative since the input is unsigned.
///
/// Parameters:
///
/// * `value` : The unsigned 16-bit integer to be converted.
///
/// Returns a 64-bit signed integer representing the same numerical value as the
/// input.
///
/// Example:
///
/// ```moonbit
/// test "UInt16::to_int64" {
/// let x = Int::to_uint16(42)
/// inspect!(x.to_int64(), content="42")
/// let max = Int::to_uint16(65535) // maximum value of UInt16
/// inspect!(max.to_int64(), content="65535")
/// }
/// ```
pub fn UInt16::to_int64(self : UInt16) -> Int64 = "%u16_to_i64"
///|
/// Reinterprets the bits of a double-precision floating-point number as a 64-bit
/// signed integer without any conversion. This is a low-level operation that
/// simply reinterprets the bit pattern of the input value.
///
/// Parameters:
///
/// * `value` : The double-precision floating-point number whose bits are to be
/// reinterpreted.
///
/// Returns a 64-bit signed integer that has the same bit pattern as the input
/// double-precision floating-point number.
///
/// Example:
///
/// ```moonbit
/// test "Double::reinterpret_as_i64" {
/// let d = 1.0
/// // 1.0 in IEEE 754 double format has the bit pattern 0x3FF0000000000000
/// inspect!(d.reinterpret_as_int64(), content="4607182418800017408")
/// }
/// ```
///
#deprecated("Use `reinterpret_as_int64` instead")
#coverage.skip
pub fn Double::reinterpret_as_i64(self : Double) -> Int64 = "%f64_to_i64_reinterpret"
///|
/// Reinterprets the bits of a double-precision floating-point number as a 64-bit
/// signed integer without performing any conversion. Preserves the exact bit
/// pattern of the input value.
///
/// Parameters:
///
/// * `number` : The double-precision floating-point number whose bits will be
/// reinterpreted.
///
/// Returns a 64-bit signed integer containing the same bit pattern as the input
/// floating-point number.
///
/// Example:
///
/// ```moonbit
/// test "Double::reinterpret_as_int64" {
/// let d = 1.0
/// inspect!(d.reinterpret_as_int64(), content="4607182418800017408") // IEEE 754 representation of 1.0
/// let neg = -0.0
/// inspect!(neg.reinterpret_as_int64(), content="-9223372036854775808") // Sign bit set
/// }
/// ```
pub fn Double::reinterpret_as_int64(self : Double) -> Int64 = "%f64_to_i64_reinterpret"
///|
/// Reinterprets the bits of a double-precision floating-point number as an
/// unsigned 64-bit integer. The bit pattern is preserved during the conversion,
/// with no mathematical conversion performed.
///
/// Parameters:
///
/// * `self` : The double-precision floating-point number to be reinterpreted.
///
/// Returns an unsigned 64-bit integer containing the same bit pattern as the
/// input floating-point number.
///
/// Example:
///
/// ```moonbit
/// test "Double::reinterpret_as_u64" {
/// let zero = 0.0
/// let positive = 1.0
/// inspect!(zero.reinterpret_as_uint64(), content="0")
/// inspect!(positive.reinterpret_as_uint64(), content="4607182418800017408")
/// }
/// ```
///
#deprecated("Use `reinterpret_as_uint64` instead")
#coverage.skip
pub fn Double::reinterpret_as_u64(self : Double) -> UInt64 = "%f64_to_i64_reinterpret"
///|
/// Reinterprets the bits of a double-precision floating-point number as an
/// unsigned 64-bit integer, preserving the exact bit pattern without performing
/// any numerical conversion.
///
/// Parameters:
///
/// * `self` : The double-precision floating-point number whose bits will be
/// reinterpreted.
///
/// Returns an unsigned 64-bit integer that has the same bit pattern as the input
/// floating-point number.
///
/// Example:
///
/// ```moonbit
/// test "Double::reinterpret_as_uint64" {
/// let d = 1.0
/// inspect!(d.reinterpret_as_uint64(), content="4607182418800017408") // Binary: 0x3FF0000000000000
/// }
/// ```
pub fn Double::reinterpret_as_uint64(self : Double) -> UInt64 = "%f64_to_i64_reinterpret"
///|
/// Converts an unsigned 64-bit integer to a double-precision floating-point
/// number. The conversion is exact for integers up to 53 bits (the size of the
/// mantissa in a double-precision number), but may lose precision for larger
/// values.
///
/// Parameters:
///
/// * `value` : The unsigned 64-bit integer to be converted.
///
/// Returns a double-precision floating-point number representing the same
/// numerical value as the input.
///
/// Example:
///
/// ```moonbit
/// test "Double::convert_uint64" {
/// let n = 12345678901234567890UL
/// inspect!(Double::convert_uint64(n), content="12345678901234567000")
/// }
/// ```
pub fn Double::convert_uint64(val : UInt64) -> Double = "%u64.to_f64"
///|
/// Reinterprets a 64-bit signed integer as an unsigned 64-bit integer without
/// changing its bits. When the value is non-negative, i.e., within the range
/// \[0, 2^63-1], the value remains the same. When the value is negative, it
/// becomes a large number in the range \[2^63, 2^64-1].
///