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

Better bound on tooManyDigits ("has more than 15 significant digits") #91

Closed
Meekohi opened this issue Mar 3, 2016 · 2 comments
Closed

Comments

@Meekohi
Copy link

Meekohi commented Mar 3, 2016

Was using https://github.com/felixge/node-mysql with supportBigNumbers:true and bigNumberStrings:false, but found that I would still get the tooManyDigits error occasionally:

number type has more than 15 significant digits

After digging in, I was amused to find that mysql is actually using bignumber.js under the hood, but is calculating more precisely when to switch from JS Number to a string. They check the binary representation to see if a number is "too big" to be represented accurately, which makes sense because they have to twiddle bits anyway come from MySQL.

I was wondering if it would make sense in bignumber.js to add a simple test to the constructor to see, if the number is an integer, whether the number is (val < Number.MAX_VALUE && val > Number.MIN_VALUE)? This would allow a wider range of "safe" numbers to be created without throwing an error (in particular, all the 16-digit integers < 9007199254740992 are okay in Javascript).

@Meekohi
Copy link
Author

Meekohi commented Mar 3, 2016

Link to relevant code in mysql for anyone curious. Not proposing we do this since it is probably overkill: https://github.com/felixge/node-mysql/blob/a9cbba154263f9d299ecfe14b97dc5fd51ae1c37/lib/protocol/Parser.js#L224

MikeMcl added a commit that referenced this issue Mar 3, 2016
@MikeMcl
Copy link
Owner

MikeMcl commented Mar 4, 2016

Okay, from v2.2.0, all integers up to Number.MAX_SAFE_INTEGER are now accepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants