當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


GO Pow用法及代碼示例

GO語言"math"包中"Pow"函數的用法及代碼示例。

用法:

func Pow(x, y float64) float64

Pow 返回 x**y,即 y 的 base-x index 。

特殊情況是(按順序):

Pow(x, ±0) = 1 for any x
Pow(1, y) = 1 for any y
Pow(x, 1) = x for any x
Pow(NaN, y) = NaN
Pow(x, NaN) = NaN
Pow(±0, y) = ±Inf for y an odd integer < 0
Pow(±0, -Inf) = +Inf
Pow(±0, +Inf) = +0
Pow(±0, y) = +Inf for finite y < 0 and not an odd integer
Pow(±0, y) = ±0 for y an odd integer > 0
Pow(±0, y) = +0 for finite y > 0 and not an odd integer
Pow(-1, ±Inf) = 1
Pow(x, +Inf) = +Inf for |x| > 1
Pow(x, -Inf) = +0 for |x| > 1
Pow(x, +Inf) = +0 for |x| < 1
Pow(x, -Inf) = +Inf for |x| < 1
Pow(+Inf, y) = +Inf for y > 0
Pow(+Inf, y) = +0 for y < 0
Pow(-Inf, y) = Pow(-0, -y)
Pow(x, y) = NaN for finite x < 0 and finite non-integer y

例子:

package main

import (
    "fmt"
    "math"
)

func main() {
    c := math.Pow(2, 3)
    fmt.Printf("%.1f", c)
}

輸出:

8.0

相關用法


注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Pow。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。