copysign.go 378 B

12345678910111213
  1. // Copyright 2010 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. package math
  5. // Copysign returns a value with the magnitude
  6. // of x and the sign of y.
  7. func Copysign(x, y float64) float64 {
  8. const sign = 1 << 63
  9. return Float64frombits(Float64bits(x)&^sign | Float64bits(y)&sign)
  10. }