-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_floatutil2_bonus.c
85 lines (76 loc) · 1.83 KB
/
ft_printf_floatutil2_bonus.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_floatutil2_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dnakano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/13 15:48:02 by dnakano #+# #+# */
/* Updated: 2020/10/18 12:10:21 by dnakano ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
void ft_mts_divbytwo(int8_t *mts, int size)
{
int i;
i = 0;
while (i < size - 1)
{
mts[i + 1] += (mts[i] % 2) * 10;
mts[i] /= 2;
i++;
}
}
void ft_arr_add(int8_t *a, int8_t *b, int size)
{
int i;
i = size - 1;
while (i >= 0)
{
a[i] += b[i];
if (a[i] >= 10 && i != 0)
{
a[i] -= 10;
a[i - 1] += 1;
}
i--;
}
}
void ft_itg_dbl(int8_t *itg, int size)
{
int i;
i = size - 1;
while (i >= 0)
{
itg[i] *= 2;
if (i < size - 1 && itg[i + 1] >= 10)
{
itg[i] += 1;
itg[i + 1] -= 10;
}
i--;
}
}
void ft_float_roundup(t_float *iflt, int digit)
{
int i;
i = digit;
while (i < 0)
{
iflt->mts_dec[-i - 1]++;
if (iflt->mts_dec[-i - 1] >= 10)
iflt->mts_dec[-i - 1] -= 10;
else
return ;
i++;
}
while (i < FLT_INTSIZE)
{
iflt->int_dec[FLT_INTSIZE - i - 1]++;
if (iflt->int_dec[FLT_INTSIZE - i - 1] >= 10)
iflt->int_dec[FLT_INTSIZE - i - 1] -= 10;
else
return ;
i++;
}
}