Skip to content

Instantly share code, notes, and snippets.

@ryumei
Created January 26, 2016 04:51
Show Gist options
  • Save ryumei/0b1562f21baf9b46adf9 to your computer and use it in GitHub Desktop.
Save ryumei/0b1562f21baf9b46adf9 to your computer and use it in GitHub Desktop.
Evaluate rounding error in Go lang
// It diverges 4611686022000000000 -1.024000e+03
package main
import "fmt"
const gigaInt = 1000000000
const gigaExp = 1e9
func main() {
var i = uint64(0)
var e = float64(0.0)
var err = float64(0.0)
for err == 0.0 {
i += gigaInt
e += gigaExp
err = e - float64(i)
}
fmt.Printf("%d %e\n", i, err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment