Golang:计算数字的反日志

时间:2013-04-13 09:14:52

标签: go logarithm

我想知道你是如何计算数字的反对数的。

2 个答案:

答案 0 :(得分:2)

根据您的对数基数使用Pow10()Pow()

如果a = log b (base10),那么a对基数10的反日志为b

答案 1 :(得分:1)

例如:

package main

import (
        "fmt"
        "math"
)

func main() {
        for f := 1.0; f < 10; f *= 1.1 {
                fmt.Printf("10^%15f == %18f\n", f, math.Pow(10, f))
        }
}

Playground


输出

10^       1.000000 ==          10.000000
10^       1.100000 ==          12.589254
10^       1.210000 ==          16.218101
10^       1.331000 ==          21.428906
10^       1.464100 ==          29.113874
10^       1.610510 ==          40.785895
10^       1.771561 ==          59.096397
10^       1.948717 ==          88.862208
10^       2.143589 ==         139.183839
10^       2.357948 ==         228.006743
10^       2.593742 ==         392.412163
10^       2.853117 ==         713.044618
10^       3.138428 ==        1375.397963
10^       3.452271 ==        2833.160736
10^       3.797498 ==        6273.332921
10^       4.177248 ==       15040.011538
10^       4.594973 ==       39352.559693
10^       5.054470 ==      113362.727116
10^       5.559917 ==      363008.933932
10^       6.115909 ==     1305897.362804
10^       6.727500 ==     5339492.112719
10^       7.400250 ==    25133324.832458
10^       8.140275 ==   138125842.074790
10^       8.954302 ==   900124188.827650
10^       9.849733 ==  7075101518.596476