Source file src/pkg/math/fabs.go
1 // Copyright 2009 The Go Authors. 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 // Fabs returns the absolute value of x. 8 // 9 // Special cases are: 10 // Fabs(+Inf) = +Inf 11 // Fabs(-Inf) = +Inf 12 // Fabs(NaN) = NaN 13 func Fabs(x float64) float64 { 14 switch { 15 case x < 0: 16 return -x 17 case x == 0: 18 return 0 // return correctly fabs(-0) 19 } 20 return x 21 }