Repository navigation
Expand file tree
/
Copy pathparse.c
More file actions
82 lines (73 loc) · 1.46 KB
/
Copy pathparse.c
File metadata and controls
82 lines (73 loc) · 1.46 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "fractal.h"
int validate_julia_params(char *str)
{
int i;
int has_digit;
int has_decimal;
i = 0;
has_digit = 0;
has_decimal = 0;
if (str[i] == '+' || str[i] == '-')
i++;
while (str[i])
{
if (str[i] >= '0' && str[i] <= '9')
has_digit = 1;
else if (str[i] == '.' && !has_decimal)
has_decimal = 1;
else
return (0);
i++;
}
return (has_digit);
}
void handle_julia(char **av, t_fractal *fractal)
{
if (!validate_julia_params(av[2]) || !validate_julia_params(av[3]))
{
ft_putstr_fd("Error: Invalid Julia parameters.\n", 2);
ft_putstr_fd(ERROR_MESSAGE, 2);
exit(1);
}
fractal->name = av[1];
fractal->julia_x = ft_atof(av[2]);
fractal->julia_y = ft_atof(av[3]);
}
int ft_isspace(int c)
{
return (c == ' ' || (c >= 9 && c <= 13));
}
static double handle_decimal_part(const char *str, int *i)
{
double decimal_part;
double decimal_factor;
decimal_part = 0.0;
decimal_factor = 0.1;
(*i)++;
while (str[*i] >= '0' && str[*i] <= '9')
{
decimal_part += (str[*i] - '0') * decimal_factor;
decimal_factor *= 0.1;
(*i)++;
}
return (decimal_part);
}
double ft_atof(const char *str)
{
double result;
int sign;
int i;
result = 0.0;
sign = 1;
i = 0;
while (ft_isspace(str[i]))
i++;
if (str[i] == '-' || str[i] == '+')
if (str[i++] == '-')
sign = -1;
while (str[i] >= '0' && str[i] <= '9')
result = result * 10 + (str[i++] - '0');
if (str[i] == '.')
result += handle_decimal_part(str, &i);
return (result * sign);
}