forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFloatingPoint.swift.gyb
643 lines (565 loc) · 28.8 KB
/
FloatingPoint.swift.gyb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
// RUN: rm -rf %t && mkdir -p %t && %S/../../utils/gyb %s -o %t/FloatingPoint.swift
// RUN: %S/../../utils/line-directive %t/FloatingPoint.swift -- %target-build-swift -parse-stdlib -Xfrontend -disable-access-control %t/FloatingPoint.swift -o %t/a.out
// RUN: %S/../../utils/line-directive %t/FloatingPoint.swift -- %target-run %t/a.out
// REQUIRES: executable_test
// XFAIL: interpret
import Swift
import StdlibUnittest
#if arch(i386) || arch(x86_64)
struct Float80Bits : Equatable, CustomStringConvertible {
var signAndExponent: UInt16
var significand: UInt64
init(_ signAndExponent: UInt16, _ significand: UInt64) {
self.signAndExponent = signAndExponent
self.significand = significand
}
var description: String {
return "(\(String(signAndExponent, radix: 16)) \(String(significand, radix: 16))))"
}
}
func == (lhs: Float80Bits, rhs: Float80Bits) -> Bool {
return
lhs.signAndExponent == rhs.signAndExponent &&
lhs.significand == rhs.significand
}
extension Float80 {
func _toBitPattern() -> Float80Bits {
let bits = Builtin.bitcast_FPIEEE80_Int80(self._value)
let sixtyFour = Builtin.zextOrBitCast_Int64_Int80((64 as Int64)._value)
return Float80Bits(
UInt16(Builtin.truncOrBitCast_Int80_Int16(
Builtin.lshr_Int80(bits, sixtyFour))),
UInt64(Builtin.truncOrBitCast_Int80_Int64(bits)))
}
static func _fromBitPattern(bits: Float80Bits) -> Float80 {
var result = Builtin.shl_Int80(
Builtin.zextOrBitCast_Int16_Int80(bits.signAndExponent._value),
Builtin.zextOrBitCast_Int64_Int80((64 as Int64)._value))
result = Builtin.or_Int80(
result, Builtin.zextOrBitCast_Int64_Int80(bits.significand._value))
return Float80(_bits: Builtin.bitcast_Int80_FPIEEE80(result))
}
}
#endif
var FloatingPoint = TestSuite("FloatingPoint")
func positiveOne<T: IntegerLiteralConvertible>() -> T {
return 1
}
func negativeOne<T: IntegerLiteralConvertible>() -> T {
return -1
}
FloatingPoint.test("Float/IntegerLiteralConvertible") {
expectEqual(positiveOne(), 1.0 as Float)
expectEqual(negativeOne(), -1.0 as Float)
}
// Tests the float and int conversions work correctly. Each case is special.
FloatingPoint.test("Float/UInt8") {
expectEqual(UInt8.min, UInt8(Float(UInt8.min)))
expectEqual(UInt8.max, UInt8(Float(UInt8.max)))
}
FloatingPoint.test("Float/Int8") {
expectEqual(Int8.min, Int8(Float(Int8.min)))
expectEqual(Int8.max, Int8(Float(Int8.max)))
}
FloatingPoint.test("Float/UInt16") {
expectEqual(UInt16.min, UInt16(Float(UInt16.min)))
expectEqual(UInt16.max, UInt16(Float(UInt16.max)))
}
FloatingPoint.test("Float/Int16") {
expectEqual(Int16.min, Int16(Float(Int16.min)))
expectEqual(Int16.max, Int16(Float(Int16.max)))
}
FloatingPoint.test("Float/UInt32") {
expectEqual(UInt32.min, UInt32(Float(UInt32.min)))
expectCrashLater()
expectEqual(UInt32.max, UInt32(Float(UInt32.max)))
}
FloatingPoint.test("Float/Int32") {
expectEqual(Int32.min, Int32(Float(Int32.min)))
expectCrashLater()
expectEqual(Int32.max, Int32(Float(Int32.max)))
}
FloatingPoint.test("Float/UInt64") {
expectEqual(UInt64.min, UInt64(Float(UInt64.min)))
expectCrashLater()
expectEqual(UInt64.max, UInt64(Float(UInt64.max)))
}
FloatingPoint.test("Float/Int64") {
expectEqual(Int64.min, Int64(Float(Int64.min)))
expectCrashLater()
expectEqual(Int64.max, Int64(Float(Int64.max)))
}
FloatingPoint.test("Double/IntegerLiteralConvertible") {
expectEqual(positiveOne(), 1.0 as Double)
expectEqual(negativeOne(), -1.0 as Double)
}
FloatingPoint.test("Double/UInt8") {
expectEqual(UInt8.min, UInt8(Double(UInt8.min)))
expectEqual(UInt8.max, UInt8(Double(UInt8.max)))
}
FloatingPoint.test("Double/Int8") {
expectEqual(Int8.min, Int8(Double(Int8.min)))
expectEqual(Int8.max, Int8(Double(Int8.max)))
}
FloatingPoint.test("Double/UInt16") {
expectEqual(UInt16.min, UInt16(Double(UInt16.min)))
expectEqual(UInt16.max, UInt16(Double(UInt16.max)))
}
FloatingPoint.test("Double/Int16") {
expectEqual(Int16.min, Int16(Double(Int16.min)))
expectEqual(Int16.max, Int16(Double(Int16.max)))
}
FloatingPoint.test("Double/UInt32") {
expectEqual(UInt32.min, UInt32(Double(UInt32.min)))
expectEqual(UInt32.max, UInt32(Double(UInt32.max)))
}
FloatingPoint.test("Double/Int32") {
expectEqual(Int32.min, Int32(Double(Int32.min)))
expectEqual(Int32.max, Int32(Double(Int32.max)))
}
FloatingPoint.test("Double/UInt64") {
expectEqual(UInt64.min, UInt64(Double(UInt64.min)))
expectCrashLater()
expectEqual(UInt64.max, UInt64(Double(UInt64.max)))
}
FloatingPoint.test("Double/Int64") {
expectEqual(Int64.min, Int64(Double(Int64.min)))
expectCrashLater()
expectEqual(Int64.max, Int64(Double(Int64.max)))
}
FloatingPoint.test("Float/HashValueZero") {
let zero: Float = getFloat32(0.0)
let negativeZero: Float = getFloat32(-0.0)
expectNotEqual(zero._toBitPattern(), negativeZero._toBitPattern())
expectEqual(zero.hashValue, negativeZero.hashValue)
}
FloatingPoint.test("Double/HashValueZero") {
let zero: Double = getFloat64(0.0)
let negativeZero: Double = getFloat64(-0.0)
expectNotEqual(zero._toBitPattern(), negativeZero._toBitPattern())
expectEqual(zero.hashValue, negativeZero.hashValue)
}
#if arch(i386) || arch(x86_64)
FloatingPoint.test("Float80/IntegerLiteralConvertible") {
expectEqual(positiveOne(), 1.0 as Float80)
expectEqual(negativeOne(), -1.0 as Float80)
}
FloatingPoint.test("Float80/HashValueZero") {
let zero: Float80 = getFloat80(0.0)
let negativeZero: Float80 = getFloat80(-0.0)
expectNotEqual(zero._toBitPattern(), negativeZero._toBitPattern())
expectEqual(zero.hashValue, negativeZero.hashValue)
}
#endif
func getPositiveSubnormal_Float32() -> Float32 {
var result: Float32 = 1.0
for _ in 0..<127 {
result /= 2.0 as Float32
}
expectTrue(result.isSubnormal)
return result
}
func getPositiveSubnormal_Float64() -> Float64 {
var result: Float64 = 1.0
for _ in 0..<1023 {
result /= 2.0 as Float64
}
expectTrue(result.isSubnormal)
return result
}
// FIXME: Float80
// <rdar://problem/17958458> Int(Float80.quietNaN) is garbage
% for FloatSelf in ['Float32', 'Float64']:
func checkFloatingPointComparison_${FloatSelf}(
expected: ExpectedComparisonResult,
_ lhs: ${FloatSelf}, _ rhs: ${FloatSelf},
//===--- TRACE boilerplate ----------------------------------------------===//
// @autoclosure _ message: ()->String = "",
showFrame: Bool = true,
stackTrace: SourceLocStack = SourceLocStack(),
file: String = __FILE__, line: UInt = __LINE__
) {
let newTrace = stackTrace.pushIf(showFrame, file: file, line: line)
let message = { "expected: lhs=\(lhs) \(expected) rhs=\(rhs)" }
expectEqual(expected.isEQ(), lhs == rhs, message(), stackTrace: newTrace)
expectEqual(expected.isNE(), lhs != rhs, message(), stackTrace: newTrace)
checkHashable(expected.isEQ(), lhs, rhs, message(), stackTrace: newTrace)
expectEqual(expected.isLT(), lhs < rhs, message(), stackTrace: newTrace)
expectEqual(expected.isLE(), lhs <= rhs, message(), stackTrace: newTrace)
expectEqual(expected.isGE(), lhs >= rhs, message(), stackTrace: newTrace)
expectEqual(expected.isGT(), lhs > rhs, message(), stackTrace: newTrace)
checkComparable(expected, lhs, rhs, message(), stackTrace: newTrace)
}
FloatingPoint.test("${FloatSelf}/{Comparable,Hashable,Equatable}") {
// On arm we flush subnormals to zero so testing subnormals won't work.
#if arch(arm)
let interestingValues: [${FloatSelf}] = [
// Interesting floating point values, sorted.
-${FloatSelf}.infinity,
-1.0,
-0.0,
0.0,
1.0,
${FloatSelf}.infinity,
${FloatSelf}.quietNaN,
]
#else
let interestingValues: [${FloatSelf}] = [
// Interesting floating point values, sorted.
-${FloatSelf}.infinity,
-1.0,
-getPositiveSubnormal_${FloatSelf}(),
-0.0,
0.0,
getPositiveSubnormal_${FloatSelf}(),
1.0,
${FloatSelf}.infinity,
${FloatSelf}.quietNaN,
]
#endif
for lhsIdx in interestingValues.indices {
for rhsIdx in interestingValues.indices {
let lhs = interestingValues[lhsIdx]
let rhs = interestingValues[rhsIdx]
if lhs.isZero && rhs.isZero {
// Special case: 0.0 and -0.0 compare equal.
checkFloatingPointComparison_${FloatSelf}(
ExpectedComparisonResult.EQ, lhs, rhs)
} else if lhs.isNaN || rhs.isNaN {
// Special case: NaN is unordered wrt other values.
// - equality comparison with NaN returns false,
// - NaN is not equal to anything, including NaN.
expectFalse(lhs == rhs)
expectTrue(lhs != rhs)
expectFalse(lhs < rhs)
expectFalse(lhs <= rhs)
expectFalse(lhs >= rhs)
expectFalse(lhs > rhs)
} else {
// The sane case.
checkFloatingPointComparison_${FloatSelf}(
lhsIdx < rhsIdx ?
ExpectedComparisonResult.LT :
(lhsIdx == rhsIdx ?
ExpectedComparisonResult.EQ :
ExpectedComparisonResult.GT),
lhs, rhs)
}
}
}
}
% end
% for Self in ['Float32', 'Float64', 'Float80']:
#if ${'arch(i386) || arch(x86_64)' if Self == 'Float80' else 'true'}
FloatingPoint.test("${Self}/Strideable") {
// FIXME: the test data could probably be better chosen here, to
// exercise more cases. Note: NaNs (and possibly Infs) are singular
// values with respect to Strideable conformance and aren't expected
// to pass these tests.
let instances: [${Self}] = [-1.0, 0.0, 0.5, 1.0, 1E20]
checkStrideable(
instances, strides: instances,
distanceOracle: { instances[$1] - instances[$0] },
advanceOracle: { instances[$0] + instances[$1] })
}
#endif
% end
// FIXME: implement Float80 tests after Float80 is implemented.
// <rdar://problem/20005438> Float80 does not conform to FloatingPointType
FloatingPoint.test("Float32/Literals") {
if true {
let f: Float32 = 0.0
expectEqual(0x0000_0000, f._toBitPattern())
}
if true {
let f: Float32 = -0.0
expectEqual(0x8000_0000, f._toBitPattern())
}
if true {
let f: Float32 = 1.0
expectEqual(0x3f80_0000, f._toBitPattern())
}
if true {
let f: Float32 = -1.0
expectEqual(0xbf80_0000, f._toBitPattern())
}
if true {
let f: Float32 = 0.999999
expectEqual(0x3f7fffef, f._toBitPattern())
}
if true {
let f: Float32 = 0.9999999
expectEqual(0x3f7ffffe, f._toBitPattern())
}
if true {
let f: Float32 = 0.99999999
expectEqual(0x3f80_0000, f._toBitPattern())
}
// Infinity.
// FIXME: this should be a compile-time error, not silent overflow.
if true {
let f: Float32 = 1.0e999
expectEqual(0x7f80_0000, f._toBitPattern())
}
if true {
let f: Float32 = -1.0e999
expectEqual(0xff80_0000, f._toBitPattern())
}
// Smallest subnormal.
if true {
let f: Float32 = 1.4e-45
expectEqual(0x0000_0001, f._toBitPattern())
}
if true {
let f: Float32 = -1.4e-45
expectEqual(0x8000_0001, f._toBitPattern())
}
// Rounded to zero.
if true {
let f: Float32 = 0.7e-45
expectEqual(0x0000_0000, f._toBitPattern())
}
if true {
let f: Float32 = -0.7e-45
expectEqual(0x8000_0000, f._toBitPattern())
}
// Second largest normal.
if true {
let f: Float32 = 3.4028232e+38
expectEqual(0x7f7f_fffe, f._toBitPattern())
}
if true {
let f: Float32 = -3.4028232e+38
expectEqual(0xff7f_fffe, f._toBitPattern())
}
// Largest normal.
if true {
let f: Float32 = 3.4028234e+38
expectEqual(0x7f7f_ffff, f._toBitPattern())
}
if true {
let f: Float32 = 340282340000000000000000000000000000000.0
expectEqual(0x7f7f_ffff, f._toBitPattern())
}
if true {
let f: Float32 = 340282340000000000000000000000000000000
expectEqual(0x7f7f_ffff, f._toBitPattern())
}
if true {
let f: Float32 = -3.4028234e+38
expectEqual(0xff7f_ffff, f._toBitPattern())
}
if true {
let f: Float32 = -340282340000000000000000000000000000000.0
expectEqual(0xff7f_ffff, f._toBitPattern())
}
if true {
let f: Float32 = -340282340000000000000000000000000000000
expectEqual(0xff7f_ffff, f._toBitPattern())
}
// Smallest decimal that is rounded to infinity.
// FIXME: this should be a compile-time error, not silent overflow.
if true {
let f: Float32 = 3.4028236e+38
expectEqual(0x7f80_0000, f._toBitPattern())
}
if true {
let f: Float32 = -3.4028236e+38
expectEqual(0xff80_0000, f._toBitPattern())
}
}
FloatingPoint.test("Float64/Literals") {
if true {
let f: Float64 = 0.0
expectEqual(0x0000_0000_0000_0000, f._toBitPattern())
}
if true {
let f: Float64 = -0.0
expectEqual(0x8000_0000_0000_0000, f._toBitPattern())
}
if true {
let f: Float64 = 1.0
expectEqual(0x3ff0_0000_0000_0000, f._toBitPattern())
}
if true {
let f: Float64 = -1.0
expectEqual(0xbff0_0000_0000_0000, f._toBitPattern())
}
if true {
let f: Float64 = 0.999999999999999
expectEqual(0x3fef_ffff_ffff_fff7, f._toBitPattern())
}
if true {
let f: Float64 = 0.9999999999999999
expectEqual(0x3fef_ffff_ffff_ffff, f._toBitPattern())
}
if true {
let f: Float64 = 0.99999999999999999
expectEqual(0x3ff0_0000_0000_0000, f._toBitPattern())
}
// Infinity.
// FIXME: this should be a compile-time error, not silent overflow.
if true {
let f: Float64 = 1.0e999
expectEqual(0x7ff0_0000_0000_0000, f._toBitPattern())
}
if true {
let f: Float64 = -1.0e999
expectEqual(0xfff0_0000_0000_0000, f._toBitPattern())
}
// Smallest subnormal.
if true {
let f: Float64 = 4.0e-324
expectEqual(0x0000_0000_0000_0001, f._toBitPattern())
}
if true {
let f: Float64 = -4.0e-324
expectEqual(0x8000_0000_0000_0001, f._toBitPattern())
}
// Rounded to zero.
if true {
let f: Float64 = 2.4e-324
expectEqual(0x0000_0000_0000_0000, f._toBitPattern())
}
if true {
let f: Float64 = -2.4e-324
expectEqual(0x8000_0000_0000_0000, f._toBitPattern())
}
// Second largest normal.
if true {
let f: Float64 = 1.79769313486231551e+308
expectEqual(0x7fef_ffff_ffff_fffe, f._toBitPattern())
}
if true {
let f: Float64 = -1.79769313486231551e+308
expectEqual(0xffef_ffff_ffff_fffe, f._toBitPattern())
}
// Largest normal.
if true {
let f: Float64 = 1.7976931348623157e+308
expectEqual(0x7fef_ffff_ffff_ffff, f._toBitPattern())
}
if true {
let f: Float64 = 179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0
expectEqual(0x7fef_ffff_ffff_ffff, f._toBitPattern())
}
if true {
let f: Float64 = 179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
expectEqual(0x7fef_ffff_ffff_ffff, f._toBitPattern())
}
if true {
let f: Float64 = -1.7976931348623157e+308
expectEqual(0xffef_ffff_ffff_ffff, f._toBitPattern())
}
if true {
let f: Float64 = -179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0
expectEqual(0xffef_ffff_ffff_ffff, f._toBitPattern())
}
if true {
let f: Float64 = -179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
expectEqual(0xffef_ffff_ffff_ffff, f._toBitPattern())
}
// Smallest decimal that is rounded to infinity.
// FIXME: this should be a compile-time error, not silent overflow.
if true {
let f: Float64 = 1.7976931348623159e+308
expectEqual(0x7ff0_0000_0000_0000, f._toBitPattern())
}
if true {
let f: Float64 = -1.7976931348623159e+308
expectEqual(0xfff0_0000_0000_0000, f._toBitPattern())
}
}
#if arch(i386) || arch(x86_64)
FloatingPoint.test("Float80/Literals") {
if true {
let f: Float80 = 0.0
expectEqual(Float80Bits(0x0000, 0x0000_0000_0000_0000), f._toBitPattern())
}
if true {
let f: Float80 = -0.0
expectEqual(Float80Bits(0x8000, 0x0000_0000_0000_0000), f._toBitPattern())
}
if true {
let f: Float80 = 1.0
expectEqual(Float80Bits(0x3fff, 0x8000_0000_0000_0000), f._toBitPattern())
}
if true {
let f: Float80 = -1.0
expectEqual(Float80Bits(0xbfff, 0x8000_0000_0000_0000), f._toBitPattern())
}
if true {
let f: Float80 = 0.999999999999999999
expectEqual(Float80Bits(0x3ffe, 0xffff_ffff_ffff_ffee), f._toBitPattern())
}
if true {
let f: Float80 = 0.9999999999999999999
expectEqual(Float80Bits(0x3ffe, 0xffff_ffff_ffff_fffe), f._toBitPattern())
}
if true {
let f: Float80 = 0.99999999999999999995
expectEqual(Float80Bits(0x3ffe, 0xffff_ffff_ffff_ffff), f._toBitPattern())
}
if true {
let f: Float80 = 0.99999999999999999999
expectEqual(Float80Bits(0x3fff, 0x8000_0000_0000_0000), f._toBitPattern())
}
// Infinity.
// FIXME: this should be a compile-time error, not silent overflow.
if true {
let f: Float80 = 1.0e19999
expectEqual(Float80Bits(0x7fff, 0x8000_0000_0000_0000), f._toBitPattern())
}
if true {
let f: Float80 = -1.0e19999
expectEqual(Float80Bits(0xffff, 0x8000_0000_0000_0000), f._toBitPattern())
}
// Smallest subnormal.
if true {
// 3.645199531882474602528e-4951
let f: Float80 = 3.6e-4951
expectEqual(Float80Bits(0x0000, 0x0000_0000_0000_0001), f._toBitPattern())
}
if true {
let f: Float80 = -3.6e-4951
expectEqual(Float80Bits(0x8000, 0x0000_0000_0000_0001), f._toBitPattern())
}
// Rounded to zero.
if true {
let f: Float80 = 1.8e-4951
expectEqual(Float80Bits(0x0000, 0x0000_0000_0000_0000), f._toBitPattern())
}
if true {
let f: Float80 = -1.8e-4951
expectEqual(Float80Bits(0x8000, 0x0000_0000_0000_0000), f._toBitPattern())
}
// Largest normal.
if true {
let f: Float80 = 1.189731495357231765e+4932
expectEqual(Float80Bits(0x7ffe, 0xffff_ffff_ffff_ffff), f._toBitPattern())
}
if true {
let f: Float80 = 1189731495357231765000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0
expectEqual(Float80Bits(0x7ffe, 0xffff_ffff_ffff_ffff), f._toBitPattern())
}
if true {
let f: Float80 = -1.189731495357231765e+4932
expectEqual(Float80Bits(0xfffe, 0xffff_ffff_ffff_ffff), f._toBitPattern())
}
if true {
let f: Float80 = -1189731495357231765000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0
expectEqual(Float80Bits(0xfffe, 0xffff_ffff_ffff_ffff), f._toBitPattern())
}
// Smallest decimal that is rounded to infinity.
// FIXME: this should be a compile-time error, not silent overflow.
if true {
let f: Float80 = 1.18973149535723176515e+4932
expectEqual(Float80Bits(0x7fff, 0x8000_0000_0000_0000), f._toBitPattern())
}
if true {
let f: Float80 = -1.18973149535723176515e+4932
expectEqual(Float80Bits(0xffff, 0x8000_0000_0000_0000), f._toBitPattern())
}
}
#endif
runAllTests()