Skip to content

Commit de53996

Browse files
committed
Additional test coverage of saturating values.
Also skip out of tests that won't compile and wouldn't make sense anyway on 32b systems.
1 parent f7842a7 commit de53996

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Tests/RealTests/RealTests.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,26 @@ extension Float {
139139
sanityCheck(-7.0064924138100205091278464932003585e-46, Float.pow(-d, 1744361943))
140140
sanityCheck( 7.0064919961905290625123586120258840e-46, Float.pow(-d, 1744361944))
141141
sanityCheck(-7.0064915785710625079583096856510544e-46, Float.pow(-d, 1744361945))
142+
// Just hammer max/min exponents, these always saturate, but this will reveal
143+
// errors in some implementations that one could try.
144+
sanityCheck( .infinity, Self.pow(-u, Int.max - 1))
145+
sanityCheck( 0.0, Self.pow(-d, Int.max - 1))
146+
sanityCheck( 0.0, Self.pow(-u, -Int.max + 1))
147+
sanityCheck( .infinity, Self.pow(-d, -Int.max + 1))
148+
sanityCheck(-.infinity, Self.pow(-u, Int.max))
149+
sanityCheck(-0.0, Self.pow(-d, Int.max))
150+
sanityCheck(-0.0, Self.pow(-u, -Int.max))
151+
sanityCheck(-.infinity, Self.pow(-d, -Int.max))
152+
sanityCheck( 0.0, Self.pow(-u, Int.min))
153+
sanityCheck( .infinity, Self.pow(-d, Int.min))
142154
}
143155
}
144156

145157
extension Double {
146158
static func testPown() {
147159
testPownCommon()
160+
// Following tests only make sense (and are only necessary) on 64b platforms.
161+
#if arch(arm64) || arch(x86_64)
148162
let u: Double = 1.nextUp
149163
let d: Double = 1.nextDown
150164
// Smallest exponent not exactly representable as Double.
@@ -166,6 +180,19 @@ extension Double {
166180
sanityCheck(-2.4703282292062332640976590913373022e-324, Double.pow(-d, 6711563375777760775))
167181
sanityCheck( 2.4703282292062329898361312467121758e-324, Double.pow(-d, 6711563375777760776))
168182
sanityCheck(-2.4703282292062327155746034020870799e-324, Double.pow(-d, 6711563375777760777))
183+
// Just hammer max/min exponents, these always saturate, but this will reveal
184+
// errors in some implementations that one could try.
185+
sanityCheck( .infinity, Self.pow(-u, Int.max - 1))
186+
sanityCheck( 0.0, Self.pow(-d, Int.max - 1))
187+
sanityCheck( 0.0, Self.pow(-u, -Int.max + 1))
188+
sanityCheck( .infinity, Self.pow(-d, -Int.max + 1))
189+
sanityCheck(-.infinity, Self.pow(-u, Int.max))
190+
sanityCheck(-0.0, Self.pow(-d, Int.max))
191+
sanityCheck(-0.0, Self.pow(-u, -Int.max))
192+
sanityCheck(-.infinity, Self.pow(-d, -Int.max))
193+
sanityCheck( 0.0, Self.pow(-u, Int.min))
194+
sanityCheck( .infinity, Self.pow(-d, Int.min))
195+
#endif
169196
}
170197
}
171198

0 commit comments

Comments
 (0)