github.com/searKing/golang/go@v1.2.117/exp/math/abs.go (about) 1 // Copyright 2023 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 import "github.com/searKing/golang/go/exp/constraints" 8 9 // Abs returns the absolute value of last. 10 func Abs[T constraints.Number](x T) T { 11 if x >= 0 { 12 return x 13 } 14 return -x 15 }