Skip to content

Commit 6e86d20

Browse files
committed
Ensure that integer values used in SIMD Codable test are representable as JS "integers"
1 parent 5c42761 commit 6e86d20

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

test/stdlib/SIMD.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ import StdlibUnittest
77

88
let SIMDCodableTests = TestSuite("SIMDCodable")
99

10+
// Round an integer to the closest representable JS integer value
11+
func jsInteger<T>(_ value: T) -> T where T : FixedWidthInteger {
12+
// Attempt to round-trip though Double; if that fails it's because the
13+
// rounded value is too large to fit in T, so use the largest value that
14+
// does fit instead.
15+
return T(exactly: Double(value)) ?? T(Double(T.max).nextDown)
16+
}
17+
1018
func testRoundTrip<T>(_ for: T.Type)
1119
where T : SIMD, T.Scalar : FixedWidthInteger {
12-
let input = T.random(in: T.Scalar.min ... T.Scalar.max)
20+
let input = jsInteger(T.random(in: T.Scalar.min ... T.Scalar.max))
1321
let encoder = JSONEncoder()
1422
let decoder = JSONDecoder()
1523
do {

0 commit comments

Comments
 (0)