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