2014-04-11 Marc Glisse <marc.glisse@inria.fr>
[official-gcc.git] / libgo / go / math / pow10.go
blobf5ad28bb4b0305bfc58f5961087e58488582d035
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 // This table might overflow 127-bit exponent representations.
8 // In that case, truncate it after 1.0e38.
9 var pow10tab [70]float64
11 // Pow10 returns 10**e, the base-10 exponential of e.
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)
23 if e < 0 {
24 return 1 / Pow10(-e)
26 if e < len(pow10tab) {
27 return pow10tab[e]
29 m := e / 2
30 return Pow10(m) * Pow10(e-m)
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]