Skip to content

Instantly share code, notes, and snippets.

@mroth
Last active June 11, 2022 14:39
Show Gist options
  • Save mroth/46352108b35275bb307d7d9156156221 to your computer and use it in GitHub Desktop.
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
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)
}
❯ 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