-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix unnecessary rounding to float64 precision when JSON-marshaling durations #453
Conversation
Ping - this should be pretty trivial. |
It seems Herbie is OOO. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a test for a negative duration?
I think this might result in -2277.-100626394s for example.
“For durations of one second or more, a non-zero value for the nanos field must be of the same sign as the seconds field. Must be from -999,999,999 to +999,999,999 inclusive.” https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Duration It looks like you’re right, @awalterschulze . And, the negative duration test is a good idea in all cases. Additionally, a negative less-than-one-second test is also going to be important as this would currently write as “0.-100626394s” for example. It looks like we will need to extract the sign and absolute value of both of the integers… some quick and dirty code (not intended as complete solution, I just think in code)…
Even though it’s more work, in the end, this should still work better (no power-of-ten rounding issues) and be faster than using floating points… (?) |
I was just trying to merge this change into gogoprotobuf and ran my tests, which found the bug. I am really glad to hear its not my tests, but an actual bug. Looking forward to merge a fix when its ready. |
This is my fault -- I'll send a PR to fix this in a few minutes. |
…aling durations (golang#453)" (golang#493) The change does not handle negative values correctly. This reverts commit 1e59b77.
No description provided.