1234567891011121314151617181920212223 |
- package main
- import (
- "fmt"
- )
- func myPow(x float64, n int) float64 {
- if n < 0 {
- n = -n
- x = 1 / x
- }
- res := 1.0
- for base := x; n > 0; base, n = base*base, n>>1 {
- if n&1 == 1 {
- res *= base
- }
- }
- return res
- }
- func main() {
- fmt.Println(myPow(2.0, -10))
- }
|