Skip to content

Decoding large Double #49

@VasilyKrainov

Description

@VasilyKrainov

This code makes the exception:

struct Response: Codable {
  let success: Bool
  let value: Double
}
func testJASON() {
  let string: String =
    """
    {"success":true,"value":100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000≥0}
    """
  let data = string.data(using: .utf8)!
  let json = JASON.JSON(data)
  let val = json["value"].double
  print("\(val)")
}

If you remove one of zeroes in "string" then the decoding will be OK. So the limit is 1e165, after which the decoding fails regardless of Double type can really fit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions