File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -8,11 +8,17 @@ import StdlibUnittest
8
8
let SIMDCodableTests = TestSuite ( " SIMDCodable " )
9
9
10
10
// 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 {
12
13
// Attempt to round-trip though Double; if that fails it's because the
13
14
// rounded value is too large to fit in T, so use the largest value that
14
15
// 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
16
22
}
17
23
18
24
func testRoundTrip< T> ( _ for: T . Type )
You can’t perform that action at this time.
0 commit comments