Skip to content

Instantly share code, notes, and snippets.

@channyeintun
Created November 8, 2024 20:40
Show Gist options
  • Save channyeintun/4f2b7a6b055f53d77ccbae98f0692020 to your computer and use it in GitHub Desktop.
Save channyeintun/4f2b7a6b055f53d77ccbae98f0692020 to your computer and use it in GitHub Desktop.
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