File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -7,9 +7,17 @@ import StdlibUnittest
7
7
8
8
let SIMDCodableTests = TestSuite ( " SIMDCodable " )
9
9
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
+
10
18
func testRoundTrip< T> ( _ for: T . Type )
11
19
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) )
13
21
let encoder = JSONEncoder ( )
14
22
let decoder = JSONDecoder ( )
15
23
do {
You can’t perform that action at this time.
0 commit comments