-
Notifications
You must be signed in to change notification settings - Fork 0
/
power.c
51 lines (49 loc) · 799 Bytes
/
power.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#define e 2.71828
#include "myMath.h"
double Exp(int x) {
double ans = e;
int counter = 0;
if(x==0) return 1;
else if(x>0){
while (counter != x-1)
{
ans = ans * e;
counter++;
}
}
else if (x<0)
{
x=x*(-1);
ans=1/ans;
double eDiv1 = 1/e;
while (counter != x-1)
{
ans = ans * eDiv1;
counter++;
}
}
return ans;
}
double Pow(double x , int y){
double ans = x ;
int counter = 0 ;
if(y==0) return 1;
else if(y>0){
while (counter != y-1)
{
counter++;
ans = ans * x;
}
}
else if(y<0){
ans = 1/ans;
x=1/x;
y=y*(-1);
while(counter < y-1)
{
counter++;
ans = ans * x;
}
}
return ans ;
}