-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathFloatingPointConversionTraps.swift.gyb
116 lines (90 loc) · 3.12 KB
/
FloatingPointConversionTraps.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
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: %S/../../utils/gyb %s -o %t/FloatingPointConversionTraps.swift
// RUN: %S/../../utils/line-directive %t/FloatingPointConversionTraps.swift -- %target-build-swift %t/FloatingPointConversionTraps.swift -Xfrontend -disable-access-control -o %t/a.out_Debug
// RUN: %S/../../utils/line-directive %t/FloatingPointConversionTraps.swift -- %target-build-swift %t/FloatingPointConversionTraps.swift -Xfrontend -disable-access-control -o %t/a.out_Release -O
//
// RUN: %S/../../utils/line-directive %t/FloatingPointConversionTraps.swift -- %target-run %t/a.out_Debug
// RUN: %S/../../utils/line-directive %t/FloatingPointConversionTraps.swift -- %target-run %t/a.out_Release
// REQUIRES: executable_test
import StdlibUnittest
%{
from SwiftIntTypes import all_integer_types
# Test cases are written in a way that they don't depend on the word size.
word_bits = 4
}%
func getInfiniteOrNaNMessage(_ floatType: String) -> String {
if _isDebugAssertConfiguration() {
return "either infinite or NaN"
}
return ""
}
func getTooSmallMessage() -> String {
if _isDebugAssertConfiguration() {
return "would be less than"
}
return ""
}
func getTooLargeMessage() -> String {
if _isDebugAssertConfiguration() {
return "would be greater than"
}
return ""
}
var FloatingPointConversion = TestSuite("FloatingPointConversion")
% for FloatSelf in ['Float32', 'Float64', 'Float80']:
% for int_ty in all_integer_types(word_bits):
% IntSelf = int_ty.stdlib_name
% if FloatSelf == 'Float80':
#if arch(i386) || arch(x86_64)
% end
FloatingPointConversion.test("${FloatSelf}/${IntSelf}/+inf")
.crashOutputMatches(getInfiniteOrNaNMessage("${FloatSelf}")).code {
do {
var a = get${IntSelf}(${IntSelf}(get${FloatSelf}(0.0)))
expectEqual(0, a)
}
do {
var a = get${IntSelf}(${IntSelf}(get${FloatSelf}(123.0)))
expectEqual(123, a)
}
expectCrashLater()
get${IntSelf}(${IntSelf}(get${FloatSelf}(+${FloatSelf}.infinity)))
}
% if int_ty.is_signed:
FloatingPointConversion.test("${FloatSelf}/${IntSelf}/-inf")
.crashOutputMatches(getInfiniteOrNaNMessage("${FloatSelf}")).code {
do {
var a = get${IntSelf}(${IntSelf}(get${FloatSelf}(-0.0)))
expectEqual(0, a)
}
do {
var a = get${IntSelf}(${IntSelf}(get${FloatSelf}(-123.0)))
expectEqual(-123, a)
}
expectCrashLater()
get${IntSelf}(${IntSelf}(get${FloatSelf}(-${FloatSelf}.infinity)))
}
% else:
FloatingPointConversion.test("${FloatSelf}/${IntSelf}/negative")
.crashOutputMatches(getTooSmallMessage()).code {
expectCrashLater()
get${IntSelf}(${IntSelf}(get${FloatSelf}(-123.0)))
}
FloatingPointConversion.test("${FloatSelf}/${IntSelf}/-inf")
.crashOutputMatches(getInfiniteOrNaNMessage("${FloatSelf}")).code {
expectCrashLater()
get${IntSelf}(${IntSelf}(get${FloatSelf}(-${FloatSelf}.infinity)))
}
% end
FloatingPointConversion.test("${FloatSelf}/${IntSelf}/NaN")
.crashOutputMatches(getInfiniteOrNaNMessage("${FloatSelf}")).code {
expectCrashLater()
get${IntSelf}(${IntSelf}(get${FloatSelf}(${FloatSelf}.nan)))
}
% if FloatSelf == 'Float80':
#endif
% end
% end
% end
runAllTests()