- Notifications
You must be signed in to change notification settings - Fork 117
/
Copy path50.c
33 lines (25 loc) · 591 Bytes
/
50.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<stdio.h>
doublemyPow(doublex, intn) {
if (x==1||n==0) return1;
if (n==1) returnx;
doubleans=1.0;
unsignedun;
un= (n>0) ? (n) : (-n);
x= (n>0) ? (x) : (1 / x);
while (un) {
if (un&1) {
ans=ans*x;
}
x *= x;
un >>= 1;
}
returnans;
}
intmain() {
doublex=9.125;
printf("%f\n", myPow(x, 1));
printf("%f\n", myPow(x, 5));
printf("%f\n", myPow(x, -5));
printf("%f\n", myPow(1.0, -2147483648));
return0;
}