Ai
1 Star 0 Fork 0

catyMap/AlgorithmNote

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
myPow.go 474 Bytes
一键复制 编辑 原始数据 按行查看 历史
catyMap 提交于 2021-07-12 07:44 +08:00 . 更新题库
package main
import (
"fmt"
"math"
)
func myPow(x float64, n int) float64 {
res , count , pow := float64(1) , 1 , 0
for n != pow {
tmp := x
count = 1
for pow < n {
res *= tmp
if res == 0 {
return 0
}
tmp *= tmp
pow += count
count *= 2
}
tmp = x
count = 1
for pow > n {
res /= tmp
tmp *= tmp
pow -= count
count *= 2
}
}
return res
}
func main() {
fmt.Println(myPow(2123,-489))
fmt.Println(math.Pow(2123,-489))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dogemap/algorithm-note.git
git@gitee.com:dogemap/algorithm-note.git
dogemap
algorithm-note
AlgorithmNote
dc486f96f6c1

搜索帮助