1 package frost.core
6
7 uses frost.unsafe.Pointer
8
9
12 class Int : Value, HashKey<Int>, Comparable<Int>, Formattable {
13 @private
14 class Bits : ListView<Bit> {
15 def value:Int
16 init(value:Int) {
17 self.value := value
18 }
19
20
21 @override
22 function [](index:Int):Bit {
23 return value && (1 << index) != 0
24 }
25
26
29 @override
30 function get_count():Int {
31 return $int_size
32 }
33
34 @override
35 function get_iterator():Iterator<Bit> {
36 return org.frostlang.frost.IntBitIterator(value.toUInt64, 1 << ($int_size->builtin_uint64 - 1))
37 }
38 }
39
42 constant MIN:Int := -1 << ($int_size - 1)
43
44
47 constant MAX:Int := 1 << ($int_size - 1) -& 1
48
49 @package
50 def value:builtin_int
51
52
53 @implicit
54 @priority(1)
55 init(value:builtin_int) {
56 self.value := value
57 }
58
59
60 @implicit
61 @priority(-5)
62 init(value:Int8) {
63 self.value := value.value->builtin_int
64 }
65
66
67 @implicit
68 @priority(-4)
69 init(value:Int16) {
70 self.value := value.value->builtin_int
71 }
72
73
74 @implicit
75 @priority(-2)
76 init(value:UInt8) {
77 self.value := value.value->builtin_int
78 }
79
80
81 @implicit
82 @priority(-1)
83 init(value:UInt16) {
84 self.value := value.value->builtin_int
85 }
86
87
88 @priority(14)
89 function +(other:Int32):Int32 {
90 return value->builtin_int32 + other.value
91 }
92
93
94 @priority(16)
95 function +(other:Int64):Int64 {
96 return value->builtin_int64 + other.value
97 }
98
99
100 @priority(20)
101 function +(other:Int):Int {
102 return value + other.value
103 }
104
105
106 @priority(13)
107 function +(other:UInt32):Int64 {
108 return value->builtin_int64 + other.value->builtin_int64
109 }
110
111
112 @priority(17)
113 function +(other:UInt):Int64 {
114 return value->builtin_int64 + other.value->builtin_int64
115 }
116
117
118 @priority(14)
119 function +&(other:Int32):Int32 {
120 return value->builtin_int32 +& other.value
121 }
122
123
124 @priority(16)
125 function +&(other:Int64):Int64 {
126 return value->builtin_int64 +& other.value
127 }
128
129
130 @priority(20)
131 function +&(other:Int):Int {
132 return value +& other.value
133 }
134
135
136 @priority(13)
137 function +&(other:UInt32):Int64 {
138 return value->builtin_int64 +& other.value->builtin_int64
139 }
140
141
142 @priority(17)
143 function +&(other:UInt):Int64 {
144 return value->builtin_int64 +& other.value->builtin_int64
145 }
146
147
148 @priority(14)
149 function -(other:Int32):Int32 {
150 return value->builtin_int32 - other.value
151 }
152
153
154 @priority(16)
155 function -(other:Int64):Int64 {
156 return value->builtin_int64 - other.value
157 }
158
159
160 @priority(20)
161 function -(other:Int):Int {
162 return value - other.value
163 }
164
165
166 @priority(13)
167 function -(other:UInt32):Int64 {
168 return value->builtin_int64 - other.value->builtin_int64
169 }
170
171
172 @priority(17)
173 function -(other:UInt):Int64 {
174 return value->builtin_int64 - other.value->builtin_int64
175 }
176
177
178 @priority(14)
179 function -&(other:Int32):Int32 {
180 return value->builtin_int32 -& other.value
181 }
182
183
184 @priority(16)
185 function -&(other:Int64):Int64 {
186 return value->builtin_int64 -& other.value
187 }
188
189
190 @priority(20)
191 function -&(other:Int):Int {
192 return value -& other.value
193 }
194
195
196 @priority(13)
197 function -&(other:UInt32):Int64 {
198 return value->builtin_int64 -& other.value->builtin_int64
199 }
200
201
202 @priority(17)
203 function -&(other:UInt):Int64 {
204 return value->builtin_int64 -& other.value->builtin_int64
205 }
206
207
208 function -():Int {
209 return Int(-value)
210 }
211
212
213 @priority(14)
214 function *(other:Int32):Int32 {
215 return value->builtin_int32 * other.value
216 }
217
218
219 @priority(16)
220 function *(other:Int64):Int64 {
221 return value->builtin_int64 * other.value
222 }
223
224
225 @priority(20)
226 function *(other:Int):Int {
227 return value * other.value
228 }
229
230
231 @priority(13)
232 function *(other:UInt32):Int64 {
233 return value->builtin_int64 * other.value->builtin_int64
234 }
235
236
237 @priority(17)
238 function *(other:UInt):Int64 {
239 return value->builtin_int64 * other.value->builtin_int64
240 }
241
242
243 @priority(14)
244 function *&(other:Int32):Int32 {
245 return value->builtin_int32 *& other.value
246 }
247
248
249 @priority(16)
250 function *&(other:Int64):Int64 {
251 return value->builtin_int64 *& other.value
252 }
253
254
255 @priority(20)
256 function *&(other:Int):Int {
257 return value *& other.value
258 }
259
260
261 @priority(13)
262 function *&(other:UInt32):Int64 {
263 return value->builtin_int64 *& other.value->builtin_int64
264 }
265
266
267 @priority(17)
268 function *&(other:UInt):Int64 {
269 return value->builtin_int64 *& other.value->builtin_int64
270 }
271
272
273 @priority(14)
274 function //(other:Int32):Int32 {
275 return value->builtin_int32 // other.value
276 }
277
278
279 @priority(16)
280 function //(other:Int64):Int64 {
281 return value->builtin_int64 // other.value
282 }
283
284
285 @priority(20)
286 function //(other:Int):Int {
287 return value // other.value
288 }
289
290
291 @priority(13)
292 function //(other:UInt32):Int64 {
293 return value->builtin_int64 // other.value->builtin_int64
294 }
295
296
297 @priority(17)
298 function //(other:UInt):Int64 {
299 return value->builtin_int64 // other.value->builtin_int64
300 }
301
302
303 @priority(14)
304 function //&(other:Int32):Int32 {
305 return value->builtin_int32 //& other.value
306 }
307
308
309 @priority(16)
310 function //&(other:Int64):Int64 {
311 return value->builtin_int64 //& other.value
312 }
313
314
315 @priority(20)
316 function //&(other:Int):Int {
317 return value //& other.value
318 }
319
320
321 @priority(13)
322 function //&(other:UInt32):Int64 {
323 return value->builtin_int64 //& other.value->builtin_int64
324 }
325
326
327 @priority(17)
328 function //&(other:UInt):Int64 {
329 return value->builtin_int64 //& other.value->builtin_int64
330 }
331
332
333 @priority(14)
334 function %(other:Int32):Int32 {
335 return value->builtin_int32 % other.value
336 }
337
338
339 @priority(16)
340 function %(other:Int64):Int64 {
341 return value->builtin_int64 % other.value
342 }
343
344
345 @priority(20)
346 function %(other:Int):Int {
347 return value % other.value
348 }
349
350
351 @priority(13)
352 function %(other:UInt32):Int64 {
353 return value->builtin_int64 % other.value->builtin_int64
354 }
355
356
357 @priority(17)
358 function %(other:UInt):Int64 {
359 return value->builtin_int64 % other.value->builtin_int64
360 }
361
362
363 @priority(10)
364 function /(other:Int8):Real32 {
365 return value->builtin_float32 / other.value->builtin_float32
366 }
367
368
369 @priority(12)
370 function /(other:Int16):Real32 {
371 return value->builtin_float32 / other.value->builtin_float32
372 }
373
374
375 @priority(14)
376 function /(other:Int32):Real32 {
377 return value->builtin_float32 / other.value->builtin_float32
378 }
379
380
381 @priority(16)
382 function /(other:Int64):Real64 {
383 return value->builtin_float64 / other.value->builtin_float64
384 }
385
386
387 @priority(9)
388 function /(other:UInt8):Real32 {
389 return value->builtin_float32 / other.value->builtin_float32
390 }
391
392
393 @priority(11)
394 function /(other:UInt16):Real32 {
395 return value->builtin_float32 / other.value->builtin_float32
396 }
397
398
399 @priority(13)
400 function /(other:UInt32):Real32 {
401 return value->builtin_float32 / other.value->builtin_float32
402 }
403
404
405 @priority(15)
406 function /(other:UInt64):Real64 {
407 return value->builtin_float64 / other.value->builtin_float64
408 }
409
410
411 @priority(19)
412 function /(other:Real32):Real32 {
413 return value->builtin_float32 / other.value
414 }
415
416
417 @priority(20)
418 function /(other:Real64):Real64 {
419 return value->builtin_float64 / other.value
420 }
421
422
423 function !!():Int {
424 return Int(!!value)
425 }
426
427
428 @priority(14)
429 function &&(other:Int32):Int32 {
430 return value->builtin_int32 && other.value
431 }
432
433
434 @priority(16)
435 function &&(other:Int64):Int64 {
436 return value->builtin_int64 && other.value
437 }
438
439
440 @priority(20)
441 function &&(other:Int):Int {
442 return value && other.value
443 }
444
445
446 @priority(13)
447 function &&(other:UInt32):UInt32 {
448 return value->builtin_uint32 && other.value
449 }
450
451
452 @priority(15)
453 function &&(other:UInt64):UInt64 {
454 return value->builtin_uint64 && other.value
455 }
456
457
458 @priority(17)
459 function &&(other:UInt):UInt {
460 return value->builtin_uint && other.value
461 }
462
463
464 @priority(14)
465 function ||(other:Int32):Int32 {
466 return value->builtin_int32 || other.value
467 }
468
469
470 @priority(16)
471 function ||(other:Int64):Int64 {
472 return value->builtin_int64 || other.value
473 }
474
475
476 @priority(20)
477 function ||(other:Int):Int {
478 return value || other.value
479 }
480
481
482 @priority(13)
483 function ||(other:UInt32):UInt32 {
484 return value->builtin_uint32 || other.value
485 }
486
487
488 @priority(15)
489 function ||(other:UInt64):UInt64 {
490 return value->builtin_uint64 || other.value
491 }
492
493
494 @priority(17)
495 function ||(other:UInt):UInt {
496 return value->builtin_uint || other.value
497 }
498
499
500 @priority(14)
501 function ~~(other:Int32):Int32 {
502 return value->builtin_int32 ~~ other.value
503 }
504
505
506 @priority(16)
507 function ~~(other:Int64):Int64 {
508 return value->builtin_int64 ~~ other.value
509 }
510
511
512 @priority(20)
513 function ~~(other:Int):Int {
514 return value ~~ other.value
515 }
516
517
518 @priority(13)
519 function ~~(other:UInt32):UInt32 {
520 return value->builtin_uint32 ~~ other.value
521 }
522
523
524 @priority(15)
525 function ~~(other:UInt64):UInt64 {
526 return value->builtin_uint64 ~~ other.value
527 }
528
529
530 @priority(17)
531 function ~~(other:UInt):UInt {
532 return value->builtin_uint ~~ other.value
533 }
534
535
536 @priority(20)
537 function <<(other:Int):Int {
538 return value << other.value
539 }
540
541
542 @priority(20)
543 function <<&(other:Int):Int {
544 return value <<& other.value
545 }
546
547
548 @priority(20)
549 function >>(other:Int):Int {
550 return value >> other.value
551 }
552
553
554 @priority(10)
555 function =(other:Int8):Bit {
556 return value = other.value->builtin_int
557 }
558
559
560 @priority(12)
561 function =(other:Int16):Bit {
562 return value = other.value->builtin_int
563 }
564
565
566 @priority(14)
567 function =(other:Int32):Bit {
568 return value->builtin_int32 = other.value
569 }
570
571
572 @priority(16)
573 function =(other:Int64):Bit {
574 return value->builtin_int64 = other.value
575 }
576
577
578 @override
579 @priority(20)
580 function =(other:Int):Bit {
581 return value = other.value
582 }
583
584
585 @priority(9)
586 function =(other:UInt8):Bit {
587 return value->builtin_int64 = other.value->builtin_int64
588 }
589
590
591 @priority(11)
592 function =(other:UInt16):Bit {
593 return value->builtin_int64 = other.value->builtin_int64
594 }
595
596
597 @priority(13)
598 function =(other:UInt32):Bit {
599 return value->builtin_int64 = other.value->builtin_int64
600 }
601
602
603 @priority(17)
604 function =(other:UInt):Bit {
605 return value->builtin_int64 = other.value->builtin_int64
606 }
607
608
609 @priority(10)
610 function !=(other:Int8):Bit {
611 return value != other.value->builtin_int
612 }
613
614
615 @priority(12)
616 function !=(other:Int16):Bit {
617 return value != other.value->builtin_int
618 }
619
620
621 @priority(14)
622 function !=(other:Int32):Bit {
623 return value->builtin_int32 != other.value
624 }
625
626
627 @priority(16)
628 function !=(other:Int64):Bit {
629 return value->builtin_int64 != other.value
630 }
631
632
633 @override
634 @priority(20)
635 function !=(other:Int):Bit {
636 return value != other.value
637 }
638
639
640 @priority(9)
641 function !=(other:UInt8):Bit {
642 return value->builtin_int64 != other.value->builtin_int64
643 }
644
645
646 @priority(11)
647 function !=(other:UInt16):Bit {
648 return value->builtin_int64 != other.value->builtin_int64
649 }
650
651
652 @priority(13)
653 function !=(other:UInt32):Bit {
654 return value->builtin_int64 != other.value->builtin_int64
655 }
656
657
658 @priority(17)
659 function !=(other:UInt):Bit {
660 return value->builtin_int64 != other.value->builtin_int64
661 }
662
663
664 @priority(10)
665 function <(other:Int8):Bit {
666 return value < other.value->< other.value->builtin_int
667 }
668
669
670 @priority(12)
671 function <(other:Int16):Bit {
672 return value < other.value->< other.value->builtin_int
673 }
674
675
676 @priority(14)
677 function <(other:Int32):Bit {
678 return value->builtin_int32 < other.value
679 }< other.value
680 }
681
682
683 @priority(16)
684 function <(other:Int64):Bit {
685 return value->builtin_int64 < other.value
686 }< other.value
687 }
688
689
690 @override
691 @priority(20)
692 function <(other:Int):Bit {
693 return value < other.value
694 }< other.value
695 }
696
697
698 @priority(9)
699 function <(other:UInt8):Bit {
700 return value->builtin_int64 < other.value->< other.value->builtin_int64
701 }
702
703
704 @priority(11)
705 function <(other:UInt16):Bit {
706 return value->builtin_int64 < other.value->< other.value->builtin_int64
707 }
708
709
710 @priority(13)
711 function <(other:UInt32):Bit {
712 return value->builtin_int64 < other.value->< other.value->builtin_int64
713 }
714
715
716 @priority(17)
717 function <(other:UInt):Bit {
718 return value->builtin_int64 < other.value->< other.value->builtin_int64
719 }
720
721
722 @priority(10)
723 function >(other:Int8):Bit {
724 return value > other.value->builtin_int
725 }
726
727
728 @priority(12)
729 function >(other:Int16):Bit {
730 return value > other.value->builtin_int
731 }
732
733
734 @priority(14)
735 function >(other:Int32):Bit {
736 return value->builtin_int32 > other.value
737 }
738
739
740 @priority(16)
741 function >(other:Int64):Bit {
742 return value->builtin_int64 > other.value
743 }
744
745
746 @override
747 @priority(20)
748 function >(other:Int):Bit {
749 return value > other.value
750 }
751
752
753 @priority(9)
754 function >(other:UInt8):Bit {
755 return value->builtin_int64 > other.value->builtin_int64
756 }
757
758
759 @priority(11)
760 function >(other:UInt16):Bit {
761 return value->builtin_int64 > other.value->builtin_int64
762 }
763
764
765 @priority(13)
766 function >(other:UInt32):Bit {
767 return value->builtin_int64 > other.value->builtin_int64
768 }
769
770
771 @priority(17)
772 function >(other:UInt):Bit {
773 return value->builtin_int64 > other.value->builtin_int64
774 }
775
776
777 @priority(10)
778 function >=(other:Int8):Bit {
779 return value >= other.value->builtin_int
780 }
781
782
783 @priority(12)
784 function >=(other:Int16):Bit {
785 return value >= other.value->builtin_int
786 }
787
788
789 @priority(14)
790 function >=(other:Int32):Bit {
791 return value->builtin_int32 >= other.value
792 }
793
794
795 @priority(16)
796 function >=(other:Int64):Bit {
797 return value->builtin_int64 >= other.value
798 }
799
800
801 @override
802 @priority(20)
803 function >=(other:Int):Bit {
804 return value >= other.value
805 }
806
807
808 @priority(9)
809 function >=(other:UInt8):Bit {
810 return value->builtin_int64 >= other.value->builtin_int64
811 }
812
813
814 @priority(11)
815 function >=(other:UInt16):Bit {
816 return value->builtin_int64 >= other.value->builtin_int64
817 }
818
819
820 @priority(13)
821 function >=(other:UInt32):Bit {
822 return value->builtin_int64 >= other.value->builtin_int64
823 }
824
825
826 @priority(17)
827 function >=(other:UInt):Bit {
828 return value->builtin_int64 >= other.value->builtin_int64
829 }
830
831
832 @priority(10)
833 function <=(other:Int8):Bit {
834 return value <= other.value->builtin_int
835 }
836
837
838 @priority(12)
839 function <=(other:Int16):Bit {
840 return value <= other.value->builtin_int
841 }
842
843
844 @priority(14)
845 function <=(other:Int32):Bit {
846 return value->builtin_int32 <= other.value
847 }
848
849
850 @priority(16)
851 function <=(other:Int64):Bit {
852 return value->builtin_int64 <= other.value
853 }
854
855
856 @override
857 @priority(20)
858 function <=(other:Int):Bit {
859 return value <= other.value
860 }
861
862
863 @priority(9)
864 function <=(other:UInt8):Bit {
865 return value->builtin_int64 <= other.value->builtin_int64
866 }
867
868
869 @priority(11)
870 function <=(other:UInt16):Bit {
871 return value->builtin_int64 <= other.value->builtin_int64
872 }
873
874
875 @priority(13)
876 function <=(other:UInt32):Bit {
877 return value->builtin_int64 <= other.value->builtin_int64
878 }
879
880
881 @priority(17)
882 function <=(other:UInt):Bit {
883 return value->builtin_int64 <= other.value->builtin_int64
884 }
885
886 @class
887 function [](range:Range<Int>):ListView<Int> {
888 return org.frostlang.frost.IntList(SteppedRange<Int, Int>(range.min, range.max, 1, range.inclusive))
889 }
890
891 @class
892 function [](range:SteppedRange<Int, Int>):ListView<Int> {
893 return org.frostlang.frost.IntList(range)
894 }
895
896
897 property abs:Int
898 function get_abs():Int {
899 if self < 0 {
900 return -self
901 }
902 return self
903 }
904
907 property bits:ListView<Bit>
908 function get_bits():ListView<Bit> { return Bits(self) }
909
910
911 property sqrt:Real64
912 function get_sqrt():Real64 {
913 return toReal64.sqrt
914 }
915
916
917 @priority(10)
918 function min(other:Int8):Int {
919 if value < other.value->< other.value->builtin_int {
920 return value
921 }
922 return other.value->builtin_int
923 }
924
925
926 @priority(12)
927 function min(other:Int16):Int {
928 if value < other.value->< other.value->builtin_int {
929 return value
930 }
931 return other.value->builtin_int
932 }
933
934
935 @priority(14)
936 function min(other:Int32):Int32 {
937 if value->builtin_int32 < other.value {< other.value {
938 return value->builtin_int32
939 }
940 return other.value
941 }
942
943
944 @priority(16)
945 function min(other:Int64):Int64 {
946 if value->builtin_int64 < other.value {< other.value {
947 return value->builtin_int64
948 }
949 return other.value
950 }
951
952
953 @priority(20)
954 function min(other:Int):Int {
955 if value < other.value {< other.value {
956 return value
957 }
958 return other.value
959 }
960
961
962 @priority(9)
963 function min(other:UInt8):Int64 {
964 if value->builtin_int64 < other.value->< other.value->builtin_int64 {
965 return value->builtin_int64
966 }
967 return other.value->builtin_int64
968 }
969
970
971 @priority(11)
972 function min(other:UInt16):Int64 {
973 if value->builtin_int64 < other.value->< other.value->builtin_int64 {
974 return value->builtin_int64
975 }
976 return other.value->builtin_int64
977 }
978
979
980 @priority(13)
981 function min(other:UInt32):Int64 {
982 if value->builtin_int64 < other.value->< other.value->builtin_int64 {
983 return value->builtin_int64
984 }
985 return other.value->builtin_int64
986 }
987
988
989
990 @priority(17)
991 function min(other:UInt):Int64 {
992 if value->builtin_int64 < other.value->< other.value->builtin_int64 {
993 return value->builtin_int64
994 }
995 return other.value->builtin_int64
996 }
997
998
999 @priority(10)
1000 function max(other:Int8):Int {
1001 if value > other.value->builtin_int {
1002 return value
1003 }
1004 return other.value->builtin_int
1005 }
1006
1007
1008 @priority(12)
1009 function max(other:Int16):Int {
1010 if value > other.value->builtin_int {
1011 return value
1012 }
1013 return other.value->builtin_int
1014 }
1015
1016
1017 @priority(14)
1018 function max(other:Int32):Int32 {
1019 if value->builtin_int32 > other.value {
1020 return value->builtin_int32
1021 }
1022 return other.value
1023 }
1024
1025
1026 @priority(16)
1027 function max(other:Int64):Int64 {
1028 if value->builtin_int64 > other.value {
1029 return value->builtin_int64
1030 }
1031 return other.value
1032 }
1033
1034
1035 @priority(20)
1036 function max(other:Int):Int {
1037 if value > other.value {
1038 return value
1039 }
1040 return other.value
1041 }
1042
1043
1044 @priority(9)
1045 function max(other:UInt8):Int64 {
1046 if value->builtin_int64 > other.value->builtin_int64 {
1047 return value->builtin_int64
1048 }
1049 return other.value->builtin_int64
1050 }
1051
1052
1053 @priority(11)
1054 function max(other:UInt16):Int64 {
1055 if value->builtin_int64 > other.value->builtin_int64 {
1056 return value->builtin_int64
1057 }
1058 return other.value->builtin_int64
1059 }
1060
1061
1062 @priority(13)
1063 function max(other:UInt32):Int64 {
1064 if value->builtin_int64 > other.value->builtin_int64 {
1065 return value->builtin_int64
1066 }
1067 return other.value->builtin_int64
1068 }
1069
1070
1071
1072 @priority(17)
1073 function max(other:UInt):Int64 {
1074 if value->builtin_int64 > other.value->builtin_int64 {
1075 return value->builtin_int64
1076 }
1077 return other.value->builtin_int64
1078 }
1079
1080 @override
1081 function get_hash():Int {
1082 return Int(value)
1083 }
1084
1085
1086 property bitCount:Int
1087 @external(frostInt_get_bitCount)
1088 function get_bitCount():Int
1089
1090
1091 @class
1092 @pre(radix >= 2 & radix <= 36)
1093 function parse(str:String, radix:Int):Int? {
1094 if str.startsWith("-") {
1095 def abs := Frost.parse(str[1..], radix)
1096 if abs == null {
1097 return null
1098 }
1099 return -(abs.asInt)
1100 }
1101 else {
1102 def result := Frost.parse(str, radix)
1103 if result == null {
1104 return null
1105 }
1106 return result.asInt
1107 }
1108 }
1109
1110
1114 property asInt8:Int8
1115 function get_asInt8():Int8 {
1116 assert self >= Int8.MIN.toInt & self <= Int8.MAX.toInt, "Int(\{self}) cannot be safely converted to Int8"
1117 return Int8(value->builtin_int8)
1118 }
1119
1120
1124 property toInt8:Int8
1125 function get_toInt8():Int8 {
1126 return Int8(value->builtin_int8)
1127 }
1128
1129
1133 property asInt16:Int16
1134 function get_asInt16():Int16 {
1135 assert self >= Int16.MIN.toInt & self <= Int16.MAX.toInt, "Int(\{self}) cannot be safely converted to Int16"
1136 return Int16(value->builtin_int16)
1137 }
1138
1139
1143 property toInt16:Int16
1144 function get_toInt16():Int16 {
1145 return Int16(value->builtin_int16)
1146 }
1147
1148
1152 property asInt32:Int32
1153 function get_asInt32():Int32 {
1154 assert self >= Int32.MIN.toInt & self <= Int32.MAX.toInt, "Int(\{self}) cannot be safely converted to Int32"
1155 return Int32(value->builtin_int32)
1156 }
1157
1158
1162 property toInt32:Int32
1163 function get_toInt32():Int32 {
1164 return Int32(value->builtin_int32)
1165 }
1166
1167
1170 property asInt64:Int64
1171 function get_asInt64():Int64 {
1172 return Int64(value->builtin_int64)
1173 }
1174
1175
1178 property toInt64:Int64
1179 function get_toInt64():Int64 {
1180 return Int64(value->builtin_int64)
1181 }
1182
1183
1187 property asUInt:UInt
1188 function get_asUInt():UInt {
1189 assert self >= UInt.MIN.toInt, "Int(\{self}) cannot be safely converted to UInt"
1190 return UInt(value->builtin_uint)
1191 }
1192
1193
1197 property toUInt:UInt
1198 function get_toUInt():UInt {
1199 return UInt(value->builtin_uint)
1200 }
1201
1202
1206 property asUInt8:UInt8
1207 function get_asUInt8():UInt8 {
1208 assert self >= UInt8.MIN.toInt & self <= UInt8.MAX.toInt, "Int(\{self}) cannot be safely converted to UInt8"
1209 return UInt8(value->builtin_uint8)
1210 }
1211
1212
1216 property toUInt8:UInt8
1217 function get_toUInt8():UInt8 {
1218 return UInt8(value->builtin_uint8)
1219 }
1220
1221
1225 property asUInt16:UInt16
1226 function get_asUInt16():UInt16 {
1227 assert self >= UInt16.MIN.toInt & self <= UInt16.MAX.toInt, "Int(\{self}) cannot be safely converted to UInt16"
1228 return UInt16(value->builtin_uint16)
1229 }
1230
1231
1235 property toUInt16:UInt16
1236 function get_toUInt16():UInt16 {
1237 return UInt16(value->builtin_uint16)
1238 }
1239
1240
1244 property asUInt32:UInt32
1245 function get_asUInt32():UInt32 {
1246 assert self >= UInt32.MIN.toInt & self.toUInt64 <= UInt32.MAX.toUInt64, "Int(\{self}) cannot be safely converted to UInt32"
1247 return UInt32(value->builtin_uint32)
1248 }
1249
1250
1254 property toUInt32:UInt32
1255 function get_toUInt32():UInt32 {
1256 return UInt32(value->builtin_uint32)
1257 }
1258
1259
1263 property asUInt64:UInt64
1264 function get_asUInt64():UInt64 {
1265 assert self >= UInt64.MIN.toInt, "Int(\{self}) cannot be safely converted to UInt64"
1266 return UInt64(value->builtin_uint64)
1267 }
1268
1269
1273 property toUInt64:UInt64
1274 function get_toUInt64():UInt64 {
1275 return UInt64(value->builtin_uint64)
1276 }
1277
1278
1281 property asReal32:Real32
1282 function get_asReal32():Real32 {
1283 return Real32(value->builtin_float32)
1284 }
1285
1286
1289 property toReal32:Real32
1290 function get_toReal32():Real32 {
1291 return Real32(value->builtin_float32)
1292 }
1293
1294
1297 property asReal64:Real64
1298 function get_asReal64():Real64 {
1299 return Real64(value->builtin_float64)
1300 }
1301
1302
1305 property toReal64:Real64
1306 function get_toReal64():Real64 {
1307 return Real64(value->builtin_float64)
1308 }
1309
1310
1311 @override
1312 function get_toString():String {
1313 constant max := 20
1314 def chars := Pointer<Char8>.alloc(max)
1315 var index := max - 1
1316 var value := self
1317 if value >= 0 {
1318 do {
1319 chars[index] := Char8((value % 10 + 48).asUInt8)
1320 value := (value // 10)
1321 index -= 1
1322 }
1323 while value > 0
1324 index += 1
1325 }
1326 else {
1327 do {
1328 chars[index] := Char8((48 - value % 10).asUInt8)
1329 value := (value // 10)
1330 index -= 1
1331 }
1332 while value < 0< 0
1333 chars[index] := "-"
1334 }
1335 def size := max - index
1336 for i in 0 .. size {
1337 chars[i] := chars[i + index]
1338 }
1339 return String(chars, size)
1340 }
1341
1342
1343 @override
1344 function format(fmt:String):String {
1345 return Frost.format(value < 0< 0, abs.toUInt64, 0xFFFFFFFFFFFFFFFF, fmt)
1346 }
1347 }
1348