-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_bigint_mult.c
39 lines (36 loc) · 1.35 KB
/
ft_bigint_mult.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bigint_mult.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ylagtab <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/27 22:07:26 by ylagtab #+# #+# */
/* Updated: 2020/02/27 22:07:27 by ylagtab ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_bigint *ft_bigint_mult(t_bigint *a, t_bigint *b)
{
t_bigint *res;
unsigned int i;
unsigned int j;
if (a == NULL || b == NULL)
return (NULL);
if ((res = ft_bigint_new(a->length + b->length)) == NULL)
return (NULL);
i = 0;
while (i < b->length)
{
j = 0;
while (j < a->length)
{
res->digits[i + j] += b->digits[i] * a->digits[j];
res->digits[i + j + 1] += res->digits[i + j] / 10;
res->digits[i + j] %= 10;
j++;
}
i++;
}
return (res);
}