Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-9759] JSONEncoder doesn't round-trip floating point values on i386 #3548

Open
stephentyrone opened this issue Jan 25, 2019 · 8 comments
Open

Comments

@stephentyrone
Copy link
Member

Previous ID SR-9759
Radar None
Original Reporter @stephentyrone
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee bendjones (JIRA)
Priority Medium

md5: 8d8255d7caa873b18de3534ebf594aa2

Issue Description:

No real investigation, but we're seeing some SIMD Codable failures on i386 only:

00:10:37 [ RUN      ] SIMDCodable.roundTrip
00:10:37 stdout>>> check failed at /Users/buildnode/jenkins/workspace/swift-PR-osx/branch-swift-5.0-branch/swift/test/stdlib/SIMD.swift, line 34
00:10:37 stdout>>> expected: SIMD2<Float>(0.26298332, -2.4110584) (of type Swift.SIMD2<Swift.Float>)
00:10:37 stdout>>> actual: SIMD2<Float>(0.2629833, -2.411058) (of type Swift.SIMD2<Swift.Float>)
00:10:37 stdout>>> check failed at /Users/buildnode/jenkins/workspace/swift-PR-osx/branch-swift-5.0-branch/swift/test/stdlib/SIMD.swift, line 34
00:10:37 stdout>>> expected: SIMD3<Float>(-12.835825, 1.2614937, -0.21712112) (of type Swift.SIMD3<Swift.Float>)
00:10:37 stdout>>> actual: SIMD3<Float>(-12.83582, 1.261494, -0.2171211) (of type Swift.SIMD3<Swift.Float>)
00:10:37 stdout>>> check failed at /Users/buildnode/jenkins/workspace/swift-PR-osx/branch-swift-5.0-branch/swift/test/stdlib/SIMD.swift, line 34
00:10:37 stdout>>> expected: SIMD4<Float>(3.3120403, 10.199102, 9.498707, 7.4242783) (of type Swift.SIMD4<Swift.Float>)
00:10:37 stdout>>> actual: SIMD4<Float>(3.31204, 10.1991, 9.498707, 7.424278) (of type Swift.SIMD4<Swift.Float>)
00:10:37 stdout>>> check failed at /Users/buildnode/jenkins/workspace/swift-PR-osx/branch-swift-5.0-branch/swift/test/stdlib/SIMD.swift, line 34
00:10:37 stdout>>> expected: SIMD2<Double>(15.633335777865131, -5.08971682968474) (of type Swift.SIMD2<Swift.Double>)
00:10:37 stdout>>> actual: SIMD2<Double>(15.63333577786513, -5.08971682968474) (of type Swift.SIMD2<Swift.Double>)
00:10:37 stdout>>> check failed at /Users/buildnode/jenkins/workspace/swift-PR-osx/branch-swift-5.0-branch/swift/test/stdlib/SIMD.swift, line 34
00:10:37 stdout>>> expected: SIMD3<Double>(6.682962227179768, 2.238796173347538, 10.422819490078087) (of type Swift.SIMD3<Swift.Double>)
00:10:37 stdout>>> actual: SIMD3<Double>(6.682962227179768, 2.238796173347538, 10.42281949007809) (of type Swift.SIMD3<Swift.Double>)
00:10:37 [     FAIL ] SIMDCodable.roundTrip

which suggest that Float and Double values are rounded incorrectly by either JSONEncoder or JSONDecoder only on i386. Maybe an x87 excess-precision bug.

@stephentyrone
Copy link
Member Author

There may be nothing that we can do about this on the Swift side, but I want a bug here to track the issue. It does appear to be i386 only, which makes it less painful.

@belkadan
Copy link

It would be really weird if NSNumber were truncating things to word size, though. @itaiferber, @phausler?

@stephentyrone
Copy link
Member Author

@belkadan It occurs even with `Float`, so it can't be that simple (also the `Double` errors would be larger if that were what's going on).

@itaiferber
Copy link
Contributor

Likely a precision issue with how JSONSerialization writes out floating-point values; we use snprintf on Darwin.

@stephentyrone Is this on Darwin, or a different platform? (If Darwin, can we please get a Radar? bendjones (JIRA User) will investigate.)

@stephentyrone
Copy link
Member Author

@itaiferber i386-simulator, so Darwin.

@stephentyrone
Copy link
Member Author

<rdar://problem/47551161> JSONEncoder doesn't round-trip floats on i386 Simulator (maybe other platforms too?)

@itaiferber
Copy link
Contributor

Excellent, thanks!

@swift-ci
Copy link
Contributor

Comment by Ben D. Jones (JIRA)

Yeah thanks @stephentyrone I'll take a look...

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants