blob: df83add69561d719b029033431fafb15382aa77e [file] [log] [blame]
Ken Thompson21810982008-03-28 13:56:47 -07001// 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
Rob Pike43312932008-06-27 17:06:23 -07005package math
Ken Thompson21810982008-03-28 13:56:47 -07006
Rob Pike1a13f9b2011-09-29 09:54:20 -07007// Abs returns the absolute value of x.
Charles L. Doriana0690b62010-02-01 22:21:40 -08008//
9// Special cases are:
Charles L. Dorianc8d25442011-11-28 13:04:52 -080010// Abs(±Inf) = +Inf
Rob Pike1a13f9b2011-09-29 09:54:20 -070011// Abs(NaN) = NaN
Brad Fitzpatrick6f8a6652015-10-29 15:13:58 +000012func Abs(x float64) float64 {
Keith Randallfb059482017-08-24 13:19:40 -070013 return Float64frombits(Float64bits(x) &^ (1 << 63))
Ken Thompson21810982008-03-28 13:56:47 -070014}