-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
math/big: Float.Rat() does not return the same number as Float.String() #66209
Comments
The value 0.025 is not exactly representable as a |
Is there anything actionable here? Based on @randall77's last comment I get the impression that the answer is no. Closing for now, but please comment if you think it should be reopened. Thanks. |
I know that a value of 0.0025 can not be represented exactly as floating point number, but according to the documentation, a big.Float has a precision and a rounding mode, therefore I expected methods of big.Float (like Rat) to take the precision and rounding mode into account. There is no documentation that says that Rat() behaves differently and ignores the rounding mode and precision. I think that's a reasonable assumption and I think that at least a documentation change would be good, however I would prefer full support for precision and rounding mode in Rat(). |
No rounding or precision is required for Are you saying we should do the same-ish thing |
Good point. Both views sound reasonable to me and maybe both variants make sense. I've read the documentation (including the "exact" part), but didn't realized that it meant that the precision and rounding mode (both of which are essential properties of a Currently, there is no easy way to parse a float64 value (which might already contain "rounding errors" because of the floating point representation as well as the limited precision of 53 bits) into a
It might be better to create a proposal at this point, but I think its currently very hard to initialize |
Go version
go version go1.22.0 windows/amd64
Output of
go env
in your module/workspace:What did you do?
playground: https://go.dev/play/p/2xDuiRHMJgn
What did you see happen?
A big.Float with the value "0.025" returns a rational number of 14757395258967641293/590295810358705651712 or 3602879701896397/144115188075855872
What did you expect to see?
I expected that a big.Float with the value of "0.025" (according to its precision and rounding mode) to have a rational number representation of "1/40".
The text was updated successfully, but these errors were encountered: