1 package frost.core
6
7
10 class Real32 : Value, HashKey<Real32>, Comparable<Real32>, Formattable {
11 constant PI := 3.14159265358979323846
12 constant E := 2.71828182845904523536
13
14 @package
15 def value:builtin_float32
16
17
18 @implicit
19 init(value:builtin_float32) {
20 self.value := value
21 }
22
23
24 @implicit
25 @priority(-5)
26 init(value:Int8) {
27 self.value := value.value->builtin_float32
28 }
29
30
31 @implicit
32 @priority(-4)
33 init(value:Int16) {
34 self.value := value.value->builtin_float32
35 }
36
37
38 @implicit
39 @priority(-3)
40 init(value:Int32) {
41 self.value := value.value->builtin_float32
42 }
43
44
45 @implicit
46 @priority(-3)
47 init(value:Int64) {
48 self.value := value.value->builtin_float32
49 }
50
51
52 @implicit
53 @priority(-3)
54 init(value:Int) {
55 self.value := value.value->builtin_float32
56 }
57
58
59 @implicit
60 @priority(-2)
61 init(value:UInt8) {
62 self.value := value.value->builtin_float32
63 }
64
65
66 @implicit
67 @priority(-1)
68 init(value:UInt16) {
69 self.value := value.value->builtin_float32
70 }
71
72
73 @implicit
74 @priority(0)
75 init(value:UInt32) {
76 self.value := value.value->builtin_float32
77 }
78
79
80 @implicit
81 @priority(0)
82 init(value:UInt64) {
83 self.value := value.value->builtin_float32
84 }
85
86
87 @implicit
88 @priority(0)
89 init(value:UInt) {
90 self.value := value.value->builtin_float32
91 }
92
93
94 @priority(20)
95 function +(other:Real32):Real32 {
96 return value + other.value
97 }
98
99
100 @priority(21)
101 function +(other:Real64):Real64 {
102 return value->builtin_float64 + other.value
103 }
104
105
106 @priority(20)
107 function -(other:Real32):Real32 {
108 return value - other.value
109 }
110
111
112 @priority(21)
113 function -(other:Real64):Real64 {
114 return value->builtin_float64 - other.value
115 }
116
117
118 function -():Real32 {
119 return Real32(-value)
120 }
121
122
123 @priority(20)
124 function *(other:Real32):Real32 {
125 return value * other.value
126 }
127
128
129 @priority(21)
130 function *(other:Real64):Real64 {
131 return value->builtin_float64 * other.value
132 }
133
134
135 @priority(11)
136 function /(other:Int8):Real32 {
137 return value / other.value->builtin_float32
138 }
139
140
141 @priority(13)
142 function /(other:Int16):Real32 {
143 return value / other.value->builtin_float32
144 }
145
146
147 @priority(15)
148 function /(other:Int32):Real32 {
149 return value / other.value->builtin_float32
150 }
151
152
153 @priority(17)
154 function /(other:Int64):Real64 {
155 return value->builtin_float64 / other.value->builtin_float64
156 }
157
158
159 @priority(10)
160 function /(other:UInt8):Real32 {
161 return value / other.value->builtin_float32
162 }
163
164
165 @priority(12)
166 function /(other:UInt16):Real32 {
167 return value / other.value->builtin_float32
168 }
169
170
171 @priority(14)
172 function /(other:UInt32):Real32 {
173 return value / other.value->builtin_float32
174 }
175
176
177 @priority(16)
178 function /(other:UInt64):Real64 {
179 return value->builtin_float64 / other.value->builtin_float64
180 }
181
182
183 @priority(20)
184 function /(other:Real32):Real32 {
185 return value / other.value
186 }
187
188
189 @priority(21)
190 function /(other:Real64):Real64 {
191 return value->builtin_float64 / other.value
192 }
193
194
195 @override
196 @priority(20)
197 function =(other:Real32):Bit {
198 return value = other.value
199 }
200
201
202 @priority(21)
203 function =(other:Real64):Bit {
204 return value->builtin_float64 = other.value
205 }
206
207
208 @override
209 @priority(20)
210 function !=(other:Real32):Bit {
211 return value != other.value
212 }
213
214
215 @priority(21)
216 function !=(other:Real64):Bit {
217 return value->builtin_float64 != other.value
218 }
219
220
221 @override
222 @priority(20)
223 function <(other:Real32):Bit {
224 return value < other.value
225 }< other.value
226 }
227
228
229 @priority(21)
230 function <(other:Real64):Bit {
231 return value->builtin_float64 < other.value
232 }< other.value
233 }
234
235
236 @override
237 @priority(20)
238 function >(other:Real32):Bit {
239 return value > other.value
240 }
241
242
243 @priority(21)
244 function >(other:Real64):Bit {
245 return value->builtin_float64 > other.value
246 }
247
248
249 @override
250 @priority(20)
251 function >=(other:Real32):Bit {
252 return value >= other.value
253 }
254
255
256 @priority(21)
257 function >=(other:Real64):Bit {
258 return value->builtin_float64 >= other.value
259 }
260
261
262 @override
263 @priority(20)
264 function <=(other:Real32):Bit {
265 return value <= other.value
266 }
267
268
269 @priority(21)
270 function <=(other:Real64):Bit {
271 return value->builtin_float64 <= other.value
272 }
273
274
275 property abs:Real32
276 function get_abs():Real32 {
277 if self < 0 {
278 return -self
279 }
280 return self
281 }
282
283
284 @priority(11)
285 function min(other:Int8):Real32 {
286 if value < other.value->< other.value->builtin_float32 {
287 return value
288 }
289 return other.value->builtin_float32
290 }
291
292
293 @priority(13)
294 function min(other:Int16):Real32 {
295 if value < other.value->< other.value->builtin_float32 {
296 return value
297 }
298 return other.value->builtin_float32
299 }
300
301
302 @priority(15)
303 function min(other:Int32):Real32 {
304 if value < other.value->< other.value->builtin_float32 {
305 return value
306 }
307 return other.value->builtin_float32
308 }
309
310
311 @priority(17)
312 function min(other:Int64):Real64 {
313 if value->builtin_float64 < other.value->< other.value->builtin_float64 {
314 return value->builtin_float64
315 }
316 return other.value->builtin_float64
317 }
318
319
320 @priority(19)
321 function min(other:Int):Real32 {
322 if value < other.value->< other.value->builtin_float32 {
323 return value
324 }
325 return other.value->builtin_float32
326 }
327
328
329 @priority(10)
330 function min(other:UInt8):Real32 {
331 if value < other.value->< other.value->builtin_float32 {
332 return value
333 }
334 return other.value->builtin_float32
335 }
336
337
338 @priority(12)
339 function min(other:UInt16):Real32 {
340 if value < other.value->< other.value->builtin_float32 {
341 return value
342 }
343 return other.value->builtin_float32
344 }
345
346
347 @priority(14)
348 function min(other:UInt32):Real32 {
349 if value < other.value->< other.value->builtin_float32 {
350 return value
351 }
352 return other.value->builtin_float32
353 }
354
355
356 @priority(16)
357 function min(other:UInt64):Real64 {
358 if value->builtin_float64 < other.value->< other.value->builtin_float64 {
359 return value->builtin_float64
360 }
361 return other.value->builtin_float64
362 }
363
364
365 @priority(18)
366 function min(other:UInt):Real32 {
367 if value < other.value->< other.value->builtin_float32 {
368 return value
369 }
370 return other.value->builtin_float32
371 }
372
373
374 @priority(11)
375 function max(other:Int8):Real32 {
376 if value > other.value->builtin_float32 {
377 return value
378 }
379 return other.value->builtin_float32
380 }
381
382
383 @priority(13)
384 function max(other:Int16):Real32 {
385 if value > other.value->builtin_float32 {
386 return value
387 }
388 return other.value->builtin_float32
389 }
390
391
392 @priority(15)
393 function max(other:Int32):Real32 {
394 if value > other.value->builtin_float32 {
395 return value
396 }
397 return other.value->builtin_float32
398 }
399
400
401 @priority(17)
402 function max(other:Int64):Real64 {
403 if value->builtin_float64 > other.value->builtin_float64 {
404 return value->builtin_float64
405 }
406 return other.value->builtin_float64
407 }
408
409
410 @priority(19)
411 function max(other:Int):Real32 {
412 if value > other.value->builtin_float32 {
413 return value
414 }
415 return other.value->builtin_float32
416 }
417
418
419 @priority(10)
420 function max(other:UInt8):Real32 {
421 if value > other.value->builtin_float32 {
422 return value
423 }
424 return other.value->builtin_float32
425 }
426
427
428 @priority(12)
429 function max(other:UInt16):Real32 {
430 if value > other.value->builtin_float32 {
431 return value
432 }
433 return other.value->builtin_float32
434 }
435
436
437 @priority(14)
438 function max(other:UInt32):Real32 {
439 if value > other.value->builtin_float32 {
440 return value
441 }
442 return other.value->builtin_float32
443 }
444
445
446 @priority(16)
447 function max(other:UInt64):Real64 {
448 if value->builtin_float64 > other.value->builtin_float64 {
449 return value->builtin_float64
450 }
451 return other.value->builtin_float64
452 }
453
454
455 @priority(18)
456 function max(other:UInt):Real32 {
457 if value > other.value->builtin_float32 {
458 return value
459 }
460 return other.value->builtin_float32
461 }
462
463
464 property floor:Real32
465 @external(frostReal32_get_floor)
466 function get_floor():Real32
467
468
469 property ceiling:Real32
470 @external(frostReal32_get_ceiling)
471 function get_ceiling():Real32
472
473
474 property sqrt:Real32
475 @external(frostReal32_get_sqrt)
476 function get_sqrt():Real32
477
478
479 property sin:Real32
480 @external(frostReal32_get_sin)
481 function get_sin():Real32
482
483
484 property cos:Real32
485 @external(frostReal32_get_cos)
486 function get_cos():Real32
487
488
489 property tan:Real32
490 @external(frostReal32_get_tan)
491 function get_tan():Real32
492
493
494 property asin:Real32
495 @external(frostReal32_get_asin)
496 function get_asin():Real32
497
498
499 property acos:Real32
500 @external(frostReal32_get_acos)
501 function get_acos():Real32
502
503
504 property atan:Real32
505 @external(frostReal32_get_atan)
506 function get_atan():Real32
507
511 @class
512 @external(frostReal32_atan2)
513 function atan2(y:Real32, x:Real32):Real32
514
515
516 @override
517 function get_hash():Int {
518 return Int(value->builtin_int)
519 }
520
521
525 property asInt:Int
526 function get_asInt():Int {
527 return Int(value->builtin_int)
528 }
529
530
533 property toInt:Int
534 function get_toInt():Int {
535 return Int(value->builtin_int)
536 }
537
538
542 property asInt8:Int8
543 @post(@return.toReal32 = self)
544 function get_asInt8():Int8 {
545 return Int8(value->builtin_int8)
546 }
547
548
551 property toInt8:Int8
552 function get_toInt8():Int8 {
553 return Int8(value->builtin_int8)
554 }
555
556
560 property asInt16:Int16
561 @post(@return.toReal32 = self)
562 function get_asInt16():Int16 {
563 return Int16(value->builtin_int16)
564 }
565
566
569 property toInt16:Int16
570 function get_toInt16():Int16 {
571 return Int16(value->builtin_int16)
572 }
573
574
578 property asInt32:Int32
579 function get_asInt32():Int32 {
580 return Int32(value->builtin_int32)
581 }
582
583
586 property toInt32:Int32
587 function get_toInt32():Int32 {
588 return Int32(value->builtin_int32)
589 }
590
591
595 property asInt64:Int64
596 function get_asInt64():Int64 {
597 return Int64(value->builtin_int64)
598 }
599
600
603 property toInt64:Int64
604 function get_toInt64():Int64 {
605 return Int64(value->builtin_int64)
606 }
607
608
612 property asUInt:UInt
613 @post(@return.toReal32 = self)
614 function get_asUInt():UInt {
615 return UInt(value->builtin_uint)
616 }
617
618
621 property toUInt:UInt
622 function get_toUInt():UInt {
623 return UInt(value->builtin_uint)
624 }
625
626
630 property asUInt8:UInt8
631 @post(@return.toReal32 = self)
632 function get_asUInt8():UInt8 {
633 return UInt8(value->builtin_uint8)
634 }
635
636
639 property toUInt8:UInt8
640 function get_toUInt8():UInt8 {
641 return UInt8(value->builtin_uint8)
642 }
643
644
648 property asUInt16:UInt16
649 @post(@return.toReal32 = self)
650 function get_asUInt16():UInt16 {
651 return UInt16(value->builtin_uint16)
652 }
653
654
657 property toUInt16:UInt16
658 function get_toUInt16():UInt16 {
659 return UInt16(value->builtin_uint16)
660 }
661
662
666 property asUInt32:UInt32
667 @post(@return.toReal32 = self)
668 function get_asUInt32():UInt32 {
669 return UInt32(value->builtin_uint32)
670 }
671
672
675 property toUInt32:UInt32
676 function get_toUInt32():UInt32 {
677 return UInt32(value->builtin_uint32)
678 }
679
680
684 property asUInt64:UInt64
685 @post(@return.toReal32 = self)
686 function get_asUInt64():UInt64 {
687 return UInt64(value->builtin_uint64)
688 }
689
690
693 property toUInt64:UInt64
694 function get_toUInt64():UInt64 {
695 return UInt64(value->builtin_uint64)
696 }
697
698
701 property asReal32:Real32
702 function get_asReal32():Real32 {
703 return Real32(value->builtin_float32)
704 }
705
706
709 property toReal32:Real32
710 function get_toReal32():Real32 {
711 return Real32(value->builtin_float32)
712 }
713
714
717 property asReal64:Real64
718 function get_asReal64():Real64 {
719 return Real64(value->builtin_float64)
720 }
721
722
725 property toReal64:Real64
726 function get_toReal64():Real64 {
727 return Real64(value->builtin_float64)
728 }
729
730 @override
731 @external(frostReal32ToString)
732 function get_toString():String
733
734
735 @override
736 function format(fmt:String):String {
737 return Frost.format(value < 0< 0, abs.toUInt64, 0xFFFFFFFF, fmt)
738 }
739 }
740