-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atof.c
41 lines (38 loc) · 1.43 KB
/
ft_atof.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atof.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rtavabil <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/22 15:06:20 by rtavabil #+# #+# */
/* Updated: 2024/01/23 12:32:19 by rtavabil ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
double ft_atof(char *arr)
{
long integer_part;
double fractional_part;
double pow;
int sign;
integer_part = 0;
fractional_part = 0;
sign = +1;
pow = 1;
while ((*arr >= 9 && *arr <= 13) || 32 == *arr)
++arr;
while ('+' == *arr || '-' == *arr)
if ('-' == *arr++)
sign = -sign;
while (*arr != '.' && *arr)
integer_part = (integer_part * 10) + (*arr++ - 48);
if ('.' == *arr)
++arr;
while (*arr)
{
pow /= 10;
fractional_part = fractional_part + (*arr++ - 48) * pow;
}
return ((integer_part + fractional_part) * sign);
}