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

Number values get rounded #277

Closed
theganyo opened this issue Apr 4, 2016 · 6 comments
Closed

Number values get rounded #277

theganyo opened this issue Apr 4, 2016 · 6 comments

Comments

@theganyo
Copy link

theganyo commented Apr 4, 2016

A scalar in the yaml of:

value: 8421999999999995999

Will be represented as a rounded number value of 8421999999999996000 in the Javascript once parsed.

Please see: apigee-127/magic#21 for more information.

Thanks!

@puzrin
Copy link
Member

puzrin commented Apr 4, 2016

http://stackoverflow.com/a/307200

That's JS restriction, not parser bug.

@puzrin puzrin closed this as completed Apr 4, 2016
@theganyo
Copy link
Author

theganyo commented Apr 4, 2016

Yes, and I pointed that out in the other thread. That said, I respectfully disagree that one should so cavalierly write off confusing and platform-specific behavior in the parsing of a platform-independent format. Arbitrary rounding is not part of the YAML spec and misrepresents the actual value specified. A simple load and dump of any given YAML should create equivalent YAML and this fails that simple test.

I would suggest that there are a number of ways this could be handled better including: warnings, errors, or adaptive behavior depending on the actual value in the YAML.

@puzrin
Copy link
Member

puzrin commented Apr 4, 2016

I would suggest that there are a number of ways this could be handled better including: warnings, errors, or adaptive behavior depending on the actual value in the YAML.

That may be resonable, but needs an issue with clear suggestion. Current one just says about problem that can not be fixed anyhow.

@confuser
Copy link

confuser commented Apr 5, 2016

@puzrin The main premise of using YAML for configuration files is that they provide static values. Having large integers being rounded without any warnings causes unexpected behaviour, regardless of the fact JS only supports 32bit integer operations. The fix for this would be to interpret it as a string, which is how many other JS Yaml based parsers handle this.

@puzrin
Copy link
Member

puzrin commented Apr 5, 2016

JS has known limitations, for example with types set & pair. As i said - create an issue with your suggestions and refer to other implementations/spec as proof for possible workarounds.

@qgustavor
Copy link

How about handling this adding a option similat to mysql's bigNumberStrings? When this option is enabled numbers larger than Number.MAX_SAFE_INTEGER (and lower than Number.MIN_SAFE_INTEGER) are returned as strings instead of numbers.

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

4 participants