Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / libgo / go / math / ldexp.go
blobd04bf1581ad5fbb85dec98956f7435ba0c58e0c4
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.
5 package math
7 // Ldexp is the inverse of Frexp.
8 // It returns frac × 2**exp.
9 func Ldexp(frac float64, exp int) float64 {
10 // TODO(rsc): Remove manual inlining of IsNaN, IsInf
11 // when compiler does it for us
12 // special cases
13 switch {
14 case frac == 0:
15 return frac // correctly return -0
16 case frac != frac: // IsNaN(frac):
17 return NaN()
19 x := Float64bits(frac)
20 exp += int(x>>shift) & mask
21 if exp <= 0 {
22 return 0 // underflow
24 if exp >= mask { // overflow
25 if frac < 0 {
26 return Inf(-1)
28 return Inf(1)
30 x &^= mask << shift
31 x |= uint64(exp) << shift
32 return Float64frombits(x)