Source file
src/math/ldexp.go
1
2
3
4
5 package math
6
7
8
9
10
11
12
13
14
15 func Ldexp(frac float64, exp int) float64 {
16 if haveArchLdexp {
17 return archLdexp(frac, exp)
18 }
19 return ldexp(frac, exp)
20 }
21
22 func ldexp(frac float64, exp int) float64 {
23
24 switch {
25 case frac == 0:
26 return frac
27 case IsInf(frac, 0) || IsNaN(frac):
28 return frac
29 }
30 frac, e := normalize(frac)
31 exp += e
32 x := Float64bits(frac)
33 exp += int(x>>shift)&mask - bias
34 if exp < -1075 {
35 return Copysign(0, frac)
36 }
37 if exp > 1023 {
38 if frac < 0 {
39 return Inf(-1)
40 }
41 return Inf(1)
42 }
43 var m float64 = 1
44 if exp < -1022 {
45 exp += 53
46 m = 1.0 / (1 << 53)
47 }
48 x &^= mask << shift
49 x |= uint64(exp+bias) << shift
50 return m * Float64frombits(x)
51 }
52
View as plain text