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: math.E returns incorrect result #66198
Comments
I'm pretty sure when you go to print it, the constant is converted from an untyped float into a float64, and a float64 does not have anywhere near 64 decimal digits of precision. https://pkg.go.dev/math/big#Float on the other hand may be able to do what you want. For example, https://go.dev/play/p/XysLL10W6GL. (I copied the constant from the I'm not sure there's anything actionable here. This seems working as intended. CC @griesemer but closing for now. |
e is inaccurate to the requested 64 significant digits. |
The Go See https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html for more background. |
relates to:
Therefore using "out of the box" golang math/flag you are limited to 15 significant digits. |
Fortunately the flag package is extensible. |
Go version
go version go1.20.11 linux/amd64
Output of
go env
in your module/workspace:What did you do?
Attempted to print e with 64 significant digits.
command:
fmt.Printf(("%"+"."+"64"+"f"), math.E)
What did you see happen?
output:
2.7182818284590450907955982984276488423347473144531250000000000000
precision:
inaccurate past 15 digits of precision
What did you expect to see?
command:
echo "scale=64;e(1)" | bc -l
output:
2.7182818284590452353602874713526624977572470936999595749669676277
precision:
accurate to requested 64 significant digits.
relates to:
#9545 #9546 #25270
The text was updated successfully, but these errors were encountered: