Created
January 26, 2016 04:51
-
-
Save ryumei/0b1562f21baf9b46adf9 to your computer and use it in GitHub Desktop.
Evaluate rounding error in Go lang
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
// 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