Skip to content

Instantly share code, notes, and snippets.

@nikolaydubina
Last active June 26, 2024 04:13
Show Gist options
  • Save nikolaydubina/594f2d39ff5cc4457c89e7654235bbcc to your computer and use it in GitHub Desktop.
Save nikolaydubina/594f2d39ff5cc4457c89e7654235bbcc to your computer and use it in GitHub Desktop.

144.96

package main

import "fmt"

func main() {
	var x float32 = 144.96
	var y float64 = 144.96
	fmt.Print(float64(x) > y, x > float32(y))
	// Output: true false
}

0.1

package main

import "fmt"

func main() {
	var x float32 = 0.1 // 0.100000001490116119384765625
	var y float64 = 0.1 // 0.1000000000000000055511151231257827021181583404541015625
	fmt.Print(float64(x) == y)
	// Output: false
}

NaN

package main

import "fmt"

func main() {
	var a float32 = 1
	var x float32 = .0 / (a - 1) // NaN
	fmt.Print(x == x)
	// Output: false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment