@@ -40,7 +40,10 @@ int_to_int_conversion_template = gyb.parse_template("int_to_int_conversion",
40
40
"""
41
41
%{
42
42
from SwiftIntTypes import all_integer_types, int_max, int_min
43
- from SwiftFloatingPointTypes import all_floating_point_types
43
+ from SwiftFloatingPointTypes import all_floating_point_types, getFtoIBounds
44
+
45
+ from decimal import Decimal
46
+
44
47
45
48
}%
46
49
% for self_ty in all_integer_types(word_bits):
@@ -105,51 +108,53 @@ FixedPointConversionFailure.test("${Other}To${Self}Conversion/dest=${testValue}"
105
108
% Other = "Float" + str(other_type.bits)
106
109
% otherMin = -int_max(bits=other_type.explicit_significand_bits, signed=False)
107
110
% otherMax = int_max(bits=other_type.explicit_significand_bits, signed=False)
111
+ % (selfFtoIMin, selfFtoIMax) = getFtoIBounds(other_type.bits, selfBits, selfSigned)
108
112
109
113
% if Other == 'Float80':
110
114
#if !os(Windows) && (arch(i386) || arch(x86_64))
111
115
% end
112
116
113
- % for testValue in [repr(value) for value in [selfMin, selfMax, selfMin - 0.1, selfMax + 0.1, otherMin, otherMax, 0.0, -0.0, 0.1, -0.1]]:
117
+ % for testValue in [Decimal(selfMin), Decimal(selfMax), Decimal(selfFtoIMin) - Decimal('0.1'), Decimal(selfFtoIMax) + Decimal('0.1'), Decimal(otherMin), Decimal(otherMax), Decimal('0.0'), Decimal('-0.0'), Decimal('0.1'), Decimal('-0.1')]:
118
+ % testValueStr = str(testValue)
114
119
115
120
% if testValue < otherMin or testValue > otherMax:
116
121
% # Can't construct `other` value to test from, do nothing and continue.
117
122
118
- % elif testValue >= selfMin and testValue <= selfMax and testValue % 1 == 0 and testValue != -0.0 :
123
+ % elif testValue >= selfFtoIMin and testValue <= selfFtoIMax and ( testValue % 1).is_zero() :
119
124
120
- FloatingPointConversionTruncations.test("${Other}To${Self}Conversion/dest=${testValue }") {
121
- let input = get${Other}(${testValue })
125
+ FloatingPointConversionTruncations.test("${Other}To${Self}Conversion/dest=${testValueStr }") {
126
+ let input = get${Other}(${testValueStr })
122
127
let result = ${Self}(input)
123
128
var resultConvertedBack = ${Other}(result)
124
- expectEqual(${testValue }, resultConvertedBack)
129
+ expectEqual(${testValueStr }, resultConvertedBack)
125
130
}
126
131
127
- FloatingPointConversionFailures.test("${Other}To${Self}FailableConversion/dest=${testValue }") {
128
- let input = get${Other}(${testValue })
129
- expectNil (${Self}(exactly: input))
132
+ FloatingPointConversionFailures.test("${Other}To${Self}FailableConversion/dest=${testValueStr }") {
133
+ let input = get${Other}(${testValueStr })
134
+ expectNotNil (${Self}(exactly: input))
130
135
}
131
136
132
137
% else:
133
138
134
- % if testValue > selfMax :
135
- FloatingPointConversionTraps.test("${Other}To${Self}Conversion/dest=${testValue }")
139
+ % if testValue > selfFtoIMax :
140
+ FloatingPointConversionTraps.test("${Other}To${Self}Conversion/dest=${testValueStr }")
136
141
.crashOutputMatches(getTooLargeMessage()).code {
137
142
expectCrashLater()
138
- % elif testValue < selfMin :
139
- FloatingPointConversionTraps.test("${Other}To${Self}Conversion/dest=${testValue }")
143
+ % elif testValue < selfFtoIMin :
144
+ FloatingPointConversionTraps.test("${Other}To${Self}Conversion/dest=${testValueStr }")
140
145
.crashOutputMatches(getTooSmallMessage()).code {
141
146
expectCrashLater()
142
147
% else:
143
- FloatingPointConversionTruncations.test("${Other}To${Self}Conversion/dest=${testValue }") {
148
+ FloatingPointConversionTruncations.test("${Other}To${Self}Conversion/dest=${testValueStr }") {
144
149
% end
145
- let input = get${Other}(${testValue })
150
+ let input = get${Other}(${testValueStr })
146
151
var result = ${Self}(input)
147
152
var resultConvertedBack = ${Other}(result)
148
153
expectNotEqual(input, resultConvertedBack)
149
154
}
150
155
151
- FloatingPointConversionFailures.test("${Other}To${Self}Conversion/dest=${testValue }") {
152
- let input = get${Other}(${testValue })
156
+ FloatingPointConversionFailures.test("${Other}To${Self}Conversion/dest=${testValueStr }") {
157
+ let input = get${Other}(${testValueStr })
153
158
expectNil(${Self}(exactly: input))
154
159
}
155
160
% end
0 commit comments