-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_math_utils.c
93 lines (83 loc) · 2.33 KB
/
ft_math_utils.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_math_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gusgonza <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/28 14:32:21 by gusgonza #+# #+# */
/* Updated: 2024/09/28 14:45:13 by gusgonza ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
double mapscale(double unsc_num, double n_min, double n_max, double o_max)
{
return ((n_max - n_min) * unsc_num / o_max + n_min);
}
t_complex sum_complex(t_complex z1, t_complex z2)
{
t_complex result;
result.re = z1.re + z2.re;
result.im = z1.im + z2.im;
return (result);
}
t_complex sqr_complex(t_complex z)
{
t_complex res;
res.re = (z.re * z.re) - (z.im * z.im);
res.im = 2 * z.re * z.im;
return (res);
}
double ft_atoidbl(char *str)
{
long int_part;
double decimal_part;
double pow;
int neg;
int_part = 0;
decimal_part = 0;
neg = 1;
pow = 1;
while ((*str >= 9 && *str <= 13) || *str == 32)
str++;
if (*str == '-')
neg = -1;
if (*str == '+' || *str == '-')
str++;
while ((*str >= '0' && *str <= '9') && *str != '.')
int_part = int_part * 10 + (*str++ - '0');
if (*str == '.')
str++;
while (*str >= '0' && *str <= '9')
{
pow /= 10;
decimal_part = decimal_part + (*str++ - '0') * pow;
}
return ((int_part + decimal_part) * neg);
}
int ft_chkr(char *str)
{
int pass;
pass = 1;
while ((*str >= 9 && *str <= 13) || *str == 32)
str++;
if (*str != '+' && *str != '-' && (*str < '0' && *str > '9'))
pass = 0;
if (*str == '+' || *str == '-')
str++;
while ((*str >= '0' && *str <= '9') && *str != '.')
str++;
if (*str != '.' && *str != '\0')
pass = 0;
else if (*str == '.')
{
str++;
while (*str != '\0' && pass == 1)
{
if (*str < '0' || *str > '9')
pass = 0;
str++;
}
}
return (pass);
}