Skip to content

Commit ba2b7e2

Browse files
committed
Fixup jsInteger function.
1 parent 0f89ac2 commit ba2b7e2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

test/stdlib/SIMD.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ import StdlibUnittest
88
let SIMDCodableTests = TestSuite("SIMDCodable")
99

1010
// Round an integer to the closest representable JS integer value
11-
func jsInteger<T>(_ value: T) -> T where T : FixedWidthInteger {
11+
func jsInteger<T>(_ value: T) -> T
12+
where T : SIMD, T.Scalar : FixedWidthInteger {
1213
// Attempt to round-trip though Double; if that fails it's because the
1314
// rounded value is too large to fit in T, so use the largest value that
1415
// does fit instead.
15-
return T(exactly: Double(value)) ?? T(Double(T.max).nextDown)
16+
let upperBound = T.Scalar(Double(T.Scalar.max).nextDown)
17+
var result = T()
18+
for i in result.indices {
19+
result[i] = T.Scalar(exactly: Double(value[i])) ?? upperBound
20+
}
21+
return result
1622
}
1723

1824
func testRoundTrip<T>(_ for: T.Type)

0 commit comments

Comments
 (0)