@@ -47,31 +47,23 @@ func getTooLargeMessage() -> String {
47
47
int_to_int_conversion_template = gyb.parse_template("int_to_int_conversion",
48
48
"""
49
49
%{
50
- from SwiftIntTypes import all_integer_types
50
+ from SwiftIntTypes import all_integer_types, int_max, int_min
51
51
52
52
floatNameToSignificandBits = { 'Float32':24, 'Float64':53, 'Float80':64 }
53
53
54
- def intMax(bits, signed):
55
- bits = bits - 1 if signed else bits
56
- return (1 << bits) - 1
57
-
58
- def intMin(bits, signed):
59
- return -1 * intMax(bits, signed) - 1 if signed else 0
60
-
61
54
}%
62
-
63
55
% for self_ty in all_integer_types(word_bits):
64
56
% selfBits = self_ty.bits
65
57
% selfSigned = self_ty.is_signed
66
- % selfMin = intMin(selfBits, selfSigned)
67
- % selfMax = intMax(selfBits, selfSigned)
58
+ % selfMin = self_ty.min
59
+ % selfMax = self_ty.max
68
60
% Self = self_ty.stdlib_name
69
61
70
62
% for other_ty in all_integer_types(word_bits):
71
63
% otherBits = other_ty.bits
72
64
% otherSigned = other_ty.is_signed
73
- % otherMin = intMin(otherBits, otherSigned)
74
- % otherMax = intMax(otherBits, otherSigned)
65
+ % otherMin = other_ty.min
66
+ % otherMax = other_ty.max
75
67
% Other = other_ty.stdlib_name
76
68
77
69
% for testValue in [selfMin, selfMax, selfMin - 1, selfMax + 1, otherMin, otherMax]:
@@ -85,8 +77,7 @@ def intMin(bits, signed):
85
77
FixedPointConversionTraps.test("${Other}To${Self}Conversion/dest=${testValue}") {
86
78
// Test that nothing interesting happens and we end up with the same result after converting.
87
79
let input = get${Other}(${testValue})
88
- let result = ${Self}(input)
89
- expectEqual(${testValue}, result)
80
+ expectEqual(${testValue}, ${Self}(input))
90
81
}
91
82
92
83
/// Never-nil failable conversion from ${Other}(${testValue}) to ${Self}.
@@ -120,8 +111,8 @@ FixedPointConversionFailure.test("${Other}To${Self}Conversion/dest=${testValue}"
120
111
% end # for in all_integer_types (Other)
121
112
122
113
% for Other, otherSignificandBits in floatNameToSignificandBits.iteritems():
123
- % otherMin = intMin( otherSignificandBits, False)
124
- % otherMax = intMax( otherSignificandBits, False)
114
+ % otherMin = int_min(bits= otherSignificandBits, signed= False)
115
+ % otherMax = int_max(bits= otherSignificandBits, signed= False)
125
116
126
117
% if Other == 'Float80':
127
118
#if !os(Windows) && (arch(i386) || arch(x86_64))
@@ -149,11 +140,13 @@ FloatingPointConversionFailures.test("${Other}To${Self}FailableConversion/dest=$
149
140
% else:
150
141
151
142
% if testValue > selfMax:
152
- FloatingPointConversionTraps.test("${Other}To${Self}Conversion/dest=${testValue}").crashOutputMatches(getTooLargeMessage()).code {
153
- expectCrashLater()
143
+ FloatingPointConversionTraps.test("${Other}To${Self}Conversion/dest=${testValue}")
144
+ .crashOutputMatches(getTooLargeMessage()).code {
145
+ expectCrashLater()
154
146
% elif testValue < selfMin:
155
- FloatingPointConversionTraps.test("${Other}To${Self}Conversion/dest=${testValue}").crashOutputMatches(getTooSmallMessage()).code {
156
- expectCrashLater()
147
+ FloatingPointConversionTraps.test("${Other}To${Self}Conversion/dest=${testValue}")
148
+ .crashOutputMatches(getTooSmallMessage()).code {
149
+ expectCrashLater()
157
150
% else:
158
151
FloatingPointConversionTruncations.test("${Other}To${Self}Conversion/dest=${testValue}") {
159
152
% end
@@ -180,11 +173,10 @@ FloatingPointConversionTraps.test("${Self}/${Other}/negative")
180
173
_blackHole(${Self}(get${Other}(-123.0)))
181
174
}
182
175
183
- FloatingPointConversionFailures.test("${Self}/${Other}/negative")
184
- expectEmpty(${Self}(exactly: get${Other}(-123.0)))
176
+ FloatingPointConversionFailures.test("${Self}/${Other}/negative") {
177
+ expectEmpty(${Self}(exactly: get${Other}(-123.0)))
185
178
}
186
179
187
-
188
180
% end
189
181
190
182
FloatingPointConversionTraps.test("${Self}/${Other}/+inf")
@@ -204,8 +196,7 @@ FloatingPointConversionTraps.test("${Self}/${Other}/-inf")
204
196
}
205
197
206
198
FloatingPointConversionFailures.test("${Self}/${Other}/-inf") {
207
- let result = ${Self}(exactly: get${Other}(-${Other}.infinity))
208
- expectEmpty(result)
199
+ expectEmpty(${Self}(exactly: get${Other}(-${Other}.infinity)))
209
200
}
210
201
211
202
FloatingPointConversionTraps.test("${Self}/${Other}/NaN")
@@ -215,8 +206,7 @@ FloatingPointConversionTraps.test("${Self}/${Other}/NaN")
215
206
}
216
207
217
208
FloatingPointConversionFailures.test("${Self}/${Other}/NaN") {
218
- let result = ${Self}(exactly: get${Other}(${Other}.nan))
219
- expectEmpty(result)
209
+ expectEmpty(${Self}(exactly: get${Other}(${Other}.nan)))
220
210
}
221
211
222
212
% if Other == 'Float80':
0 commit comments