-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_power.c
31 lines (28 loc) · 1.15 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ademenet <ademenet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/04/11 09:29:07 by ademenet #+# #+# */
/* Updated: 2016/04/13 10:04:52 by ademenet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
float ft_power(int nb, int exp)
{
float result;
if (exp == 0)
return (1);
result = ft_power(nb, exp / 2);
if (exp % 2 == 0)
return (result * result);
else
{
if (exp > 0)
return (nb * result * result);
else
return (result * result) / nb;
}
}