github.com/searKing/golang/go@v1.2.117/math/abs.go (about)

     1  // Copyright 2020 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package math
     6  
     7  // AbsInt64 returns the absolute value of x.
     8  func AbsInt64(x int64) int64 {
     9  	y := x >> 63       // y <- x>> 63
    10  	return (x ^ y) - y // (x XOR y) - y
    11  }