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