Last active
June 11, 2022 14:39
-
-
Save mroth/46352108b35275bb307d7d9156156221 to your computer and use it in GitHub Desktop.
Inconsistent overflow behavior between amd64 and arm64 on a float64->int64 conversion following math.Ceil
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
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func main() { | |
var f float64 = math.MaxInt64 + 1 | |
c := math.Ceil(f) | |
fInt64 := int64(f) | |
cInt64 := int64(c) | |
fmt.Printf("f=%.1f math.Ceil(f)=%.1f int64(f)=%d int64(math.Ceil(f))=%d\n", f, c, fInt64, cInt64) | |
} |
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
❯ GOARCH=arm64 go run . && GOARCH=amd64 go run . | |
f=9223372036854775808.0 math.Ceil(f)=9223372036854775808.0 int64(f)=9223372036854775807 int64(math.Ceil(f))=9223372036854775807 | |
f=9223372036854775808.0 math.Ceil(f)=9223372036854775808.0 int64(f)=9223372036854775807 int64(math.Ceil(f))=-9223372036854775808 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment