libft
src
ft_power.c
Go to the documentation of this file.
1
/* ************************************************************************** */
3
/* */
4
/* ::: :::::::: */
5
/* ft_power.c :+: :+: :+: */
6
/* +:+ +:+ +:+ */
7
/* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8
/* +#+#+#+#+#+ +#+ */
9
/* Created: 2019/09/20 16:09:37 by unite #+# #+# */
10
/* Updated: 2020/07/16 02:55:36 by unite ### ########.fr */
11
/* */
12
/* ************************************************************************** */
13
14
#include "
libft.h
"
15
#include <limits.h>
16
24
int
ft_power
(
int
num,
unsigned
int
exponent)
25
{
26
long
long
result;
27
28
result = 1;
29
while
(exponent-- > 0)
30
result *= num;
31
if
(result > INT_MAX)
32
return
(0);
33
else
34
return
((
int
)result);
35
}
ft_power
int ft_power(int num, unsigned int exponent)
Raises a number to a given power.
Definition:
ft_power.c:24
libft.h
Generated by
1.8.16