Source file src/pkg/math/pow10.go
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.
4
5 package math
6
7 // This table might overflow 127-bit exponent representations.
8 // In that case, truncate it after 1.0e38.
9 var pow10tab [70]float64
10
11 // Pow10 returns 10**e, the base-10 exponential of e.
12 //
13 // Special cases are:
14 // Pow10(e) = +Inf for e > 309
15 // Pow10(e) = 0 for e < -324
16 func Pow10(e int) float64 {
17 if e <= -325 {
18 return 0
19 } else if e > 309 {
20 return Inf(1)
21 }
22
23 if e < 0 {
24 return 1 / Pow10(-e)
25 }
26 if e < len(pow10tab) {
27 return pow10tab[e]
28 }
29 m := e / 2
30 return Pow10(m) * Pow10(e-m)
31 }
32
33 func init() {
34 pow10tab[0] = 1.0e0
35 pow10tab[1] = 1.0e1
36 for i := 2; i < len(pow10tab); i++ {
37 m := i / 2
38 pow10tab[i] = pow10tab[m] * pow10tab[i-m]
39 }
40 }