Skip to content

Instantly share code, notes, and snippets.

@ericlagergren
Created June 28, 2016 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericlagergren/af4215805a0d88e426fde0c55696df3c to your computer and use it in GitHub Desktop.
Save ericlagergren/af4215805a0d88e426fde0c55696df3c to your computer and use it in GitHub Desktop.
$ cat test.go
package main
import "fmt"
var x int64 = +1
func main() {
m := signum(x)
fmt.Println(m)
}
//go:noinline
func signum(x int64) int {
return int((x >> 63) | int64(uint64(-x)>>63))
}
vagrant@vagrant-ubuntu-trusty-32:~/gopath/src/github.com/EricLagergren/decimal$ go run test.go
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment