Created
July 3, 2023 10:37
-
-
Save KEINOS/b76cbfebd000f7810a11e106e2c4edd4 to your computer and use it in GitHub Desktop.
[Golang] Example of float64 addition that doesn't sum up as expected. [IEEE 754]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
// View it online: https://go.dev/play/p/GUuSXWcLUZ- | |
func main() { | |
// IEEE 754 | |
a := 0.1 | |
b := 0.2 | |
fmt.Printf("%.064f\n", a+b) | |
// Output: | |
// 0.3000000000000000444089209850062616169452667236328125000000000000 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment