question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to parse values larger than 1.7976931348623157E+308

See original GitHub issue

Hi,

when trying to parse a JSON-String which contains a very very big number, I get the following error message: “Bad number”. The reason is, that you use isFinite() to check if the number is a finite one. However, according to the specification, Infinity is determined, as following:

“Infinity is displayed when a number exceeds the upper limit of the floating point numbers, which is 1.797693134862315E+308.”

As a result, whenever a numeric value that will be parsed is larger than 1.797693134862315E+308, json-bigint is unable to parse the JSON file.

Nevertheless, bignumber.js also has a function isFinite(), which is able to handle values larger than 1.797693134862315E+308. Since from my point of view, this module should be used to parse JSON-files containing any numeric value, I would appreciate if the currently used function isFinite() will be replaced by the function isFinite() of bignumber.js. Find the different results of these function in the following example:

const BigNumber = require('bignumber.js');

console.log(isFinite(1.797693134862316E+308)) // false

console.log(BigNumber('1.797693134862316E+308').isFinite()) //true

I also added a small example, where you can see the value 3e+500 will not be parsed appropriately with json-bigint. However, when using the standard JSON parser, the value can be parsed, even though the returned value is of course incorrect.

var JSONbig = require('json-bigint')

let veryBigDecimal = `3e+500`

try {
    let jsonBigResult = JSONbig.parse(veryBigDecimal)
    console.log(`JSONbig result: ${jsonBigResult.toString()}`)
} catch (e) {
    console.log(`JSONbig error thrown: ${e.message}`)
}

try {
    let jsonResult = JSON.parse(veryBigDecimal)
    console.log(`JSON result: ${jsonResult.toString()}`)
} catch (e) {
    console.log(`JSON error thrown: ${e.message}`)
}

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
SebastianG77commented, Mar 17, 2019

Hey guys,

I am afraid I might lack of context regarding your discussion, but I also fixed this error in this PR: https://github.com/sidorares/json-bigint/pull/26 . I also published my changes to npm (https://www.npmjs.com/package/true-json-bigint) as I needed them at that time. Feel free to try them out and give some feedback. Let me know if your problems still appear while using this package.

0reactions
nickkolokcommented, Mar 16, 2019

@Almenon I believe that the appropriate solution is to pass any number-like string to a user-defined function and the deal with the stuff which the function returns.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why maximum double number is 1.7976931348623157E308?
All floating point numbers (double is a double-precision float) are written as a product of two values, the mantissa and the exponent.
Read more >
Bugs in miloyip/nativejson-benchmark: roundtrips #187 - GitHub
I checked the library with the latest https://github.com/miloyip/nativejson-benchmark benchmark suite. There are several errors in the round ...
Read more >
Int/str conversions broken in latest Python bugfix releases
I think it would be very reasonable for a JSON parser to turn any number greater than 1.7976931348623157e308 to Inf.
Read more >
How to handle numbers greater than Double.MAX_VALUE
However the maximum value of average that I can store is Double.MAX_VALUE i.e 1.7976931348623157E308 after which the value becomes INFINITY.
Read more >
Bisecting Intervals of floating point numbers containing 0 and ...
One approach is to enumerate all numeric floating-point encodings for a given floating-point type, then find the enumeration that is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found