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-15172] Lossless double conversion with JSONDecoder #3358

Open
macdrevx opened this issue Sep 8, 2021 · 2 comments
Open

[SR-15172] Lossless double conversion with JSONDecoder #3358

macdrevx opened this issue Sep 8, 2021 · 2 comments

Comments

@macdrevx
Copy link

macdrevx commented Sep 8, 2021

Previous ID SR-15172
Radar rdar://82884961
Original Reporter @macdrevx
Type Bug
Environment

Xcode 13.0 beta 5; also reproducible on Xcode 12.5.1 (12E507)

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 5729415c881e6956ae9ae0435ca86e35

Issue Description:

let str = "0.027121761950711698"
let dbl = Double(str)!
dbl == Double(dbl.description) // true
try! dbl.description == String(data: JSONEncoder().encode(dbl), encoding: .utf8)! // true
try! dbl == JSONDecoder().decode(Double.self, from: JSONEncoder().encode(dbl)) // false

JSONDecoder decodes the double differently than Double.

I would expect it to decode to the same value.

@macdrevx
Copy link
Author

macdrevx commented Sep 8, 2021

Realizing that this test was running on macOS, and probably needs to be filed with Apple instead of here since it'd be using Foundation, not corelibs foundation.

@macdrevx
Copy link
Author

macdrevx commented Sep 8, 2021

Filed as FB9609503

@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

1 participant