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