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