CleanJSON icon indicating copy to clipboard operation
CleanJSON copied to clipboard

Fails on decoding large Double

Open VasilyKrainov opened this issue 2 years ago • 0 comments

This code makes the exception:

let str = "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
let data = str.data(using: .utf8)!
let decoder = CleanJSONDecoder()
do {
  let value = try decoder.decode(Double.self, from: data)
  print("OK = \(value)")
} catch {
  print("Error = \(error)")
}

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

VasilyKrainov avatar Jul 15 '22 15:07 VasilyKrainov