complex-lowering: Better handling of PAREN_EXPR [PR68855]
[official-gcc.git] / libgo / go / math / ldexp.go
blob8775cdbae4d213d5eba353aa68301f2b5afa6c37
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 //
10 // Special cases are:
11 // Ldexp(±0, exp) = ±0
12 // Ldexp(±Inf, exp) = ±Inf
13 // Ldexp(NaN, exp) = NaN
15 //extern ldexp
16 func libc_ldexp(float64, int32) float64
18 func Ldexp(frac float64, exp int) float64 {
19 if exp > MaxInt32 {
20 exp = MaxInt32
21 } else if exp < MinInt32 {
22 exp = MinInt32
24 r := libc_ldexp(frac, int32(exp))
25 return r
28 func ldexp(frac float64, exp int) float64 {
29 // special cases
30 switch {
31 case frac == 0:
32 return frac // correctly return -0
33 case IsInf(frac, 0) || IsNaN(frac):
34 return frac
36 frac, e := normalize(frac)
37 exp += e
38 x := Float64bits(frac)
39 exp += int(x>>shift)&mask - bias
40 if exp < -1075 {
41 return Copysign(0, frac) // underflow
43 if exp > 1023 { // overflow
44 if frac < 0 {
45 return Inf(-1)
47 return Inf(1)
49 var m float64 = 1
50 if exp < -1022 { // denormal
51 exp += 53
52 m = 1.0 / (1 << 53) // 2**-53
54 x &^= mask << shift
55 x |= uint64(exp+bias) << shift
56 return m * Float64frombits(x)