-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_powl.c
executable file
·59 lines (56 loc) · 1.74 KB
/
ft_powl.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
52
53
54
55
56
57
58
59
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_powl.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/19 08:42:20 by akharrou #+# #+# */
/* Updated: 2019/03/18 10:11:11 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
/*
** NAME
** ft_powl -- power function.
**
** SYNOPSIS
** #include "math_42.h"
**
** long double
** ft_powl(long double x, long double y);
**
** PARAMETERS
**
** long double x Number, of type double, that is to be raised
** to the power of 'y'.
**
** long double y Number, of type double, used to raise 'x'.
**
** DESCRIPTION
** The ft_powl() functions computes 'x' raised to the power 'y'.
**
** RETURN VALUES
** Returns 'x' raised to the power 'y'.
*/
long double ft_powl(long double x, long double y)
{
long double val;
double sign;
if (y == 0)
return (1.0);
sign = (x < 0) ? -1.0 : 1.0;
x = (x < 0) ? (-x) : (x);
val = x;
if (y < 0)
{
y = -y;
while (--y > -2)
val /= x;
}
else
{
while (--y > 0)
val *= x;
}
return (val * sign);
}