12345678910111213141516171819 |
- package main
- 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))
- } */
|