Closed
Description
Previous ID | SR-491 |
Radar | None |
Original Reporter | dankogai (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Done |
Attachment: Download
Additional Detail from JIRA
Votes | 0 |
Component/s | Standard Library |
Labels | Bug |
Assignee | @tbkka |
Priority | Medium |
md5: 1c1d9ebdc5e0745501c97e00c87b6dc7
duplicates:
Issue Description:
In order to stringily a double roundtrip-safe, we need up to 17 decimal digits. But Double#description
of current Swift (on all platforms) gives us one digit short.
import Foundation
let log2 = log(2.0)
let log2Sd = log2.description
let log2Sp17g = String(format:"%.17g",log2)
let log2Spa = String(format:"%a",log2)
Double(log2Sd) == log2 // false
Double(log2Sp17g) == log2 // true
Double(log2Spa) == log2 // true
As you see in the attached screenshot, Playground is okay. So is REPL.
Perl 5 and Python 2 have the same symptom:
-
Perl 5 http://ideone.com/J7kVwv
-
Python 2 https://repl.it/BcF7/0
While most other modern languages do not:
-
JavaScript http://ideone.com/qonDEO
-
Python 3 https://repl.it/BcFb/0
IMHO this is rather an undocumented feature than a bug but with JSON so ubiquitous and all of its numbers are doubles, we should make Double#description roundtrip-safe.