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