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