Created
November 8, 2024 20:40
-
-
Save channyeintun/4f2b7a6b055f53d77ccbae98f0692020 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
func main() { | |
// Let's prevent compile-time optimization by using variables | |
a := 0.1 | |
b := 0.2 | |
c := 0.3 | |
result := a + b | |
fmt.Printf("%.20f\n", result) // 0.30000000000000004440 | |
fmt.Printf("result == c: %v\n", result == c) // false | |
// But direct literals are optimized | |
fmt.Printf("(0.1 + 0.2) == 0.3: %v\n", (0.1+0.2) == 0.3) // true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment