-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_power.c
36 lines (34 loc) · 1.1 KB
/
ft_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ybouzgao <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/09 19:04:19 by ybouzgao #+# #+# */
/* Updated: 2017/11/09 21:19:48 by ybouzgao ### ########.fr */
/* */
/* ************************************************************************** */
float ft_power(float a, int n)
{
int i;
float b;
int j;
i = 1;
b = a;
if (n < 0)
j = -n;
else
j = n;
if (n == 0)
return (1);
while (i < j)
{
a = a * b;
i++;
}
if (n < 0)
return (1 / a);
else
return (a);
}