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