-
Notifications
You must be signed in to change notification settings - Fork 0
/
operator.c
93 lines (86 loc) · 1.82 KB
/
operator.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
/*
** operator.c for Projet-Bistro in /home/giallo_n/rendu/Projet-C-Bistro
**
** Made by nathan giallombardo
** Login <giallo_n@epitech.net>
**
** Started on Mon Oct 28 22:43:44 2013 nathan giallombardo
** Last update Sun Nov 10 19:49:44 2013 nathan giallombardo
*/
#include <stdlib.h>
#include "my.h"
#include "bistromathique.h"
t_nb *my_add(t_nb *nb1, t_nb *nb2, char *base)
{
t_nb *nb;
int size;
int c;
c = 0;
size = my_strlen(base);
nb = make_nb_empty(nb1->size + 1);
while (nb2->poss >= 0)
{
c = c + nb1->nbr[nb1->poss--] - *base + nb2->nbr[nb2->poss--] - *base;
nb->nbr[nb->poss++] = get_digit(base, c % size);
c = c / size;
}
while (nb1->poss >= 0)
{
c = c + nb1->nbr[nb1->poss--] - *base;
nb->nbr[nb->poss++] = get_digit(base, c % size);
c = c / size;
}
if (c > 0)
nb->nbr[nb->poss] = get_digit(base, c);
if (nb1->neg < 0 && nb1->neg < 0)
nb->neg = 1;
return (nb);
}
t_nb *my_sub(t_nb *nb1, t_nb *nb2, char*base)
{
t_nb *nb;
int c;
c = 0;
nb = make_nb_empty(nb1->size);
while (nb2->poss >= 0)
{
c = (nb1->nbr[nb1->poss--] - *base) - (nb2->nbr[nb2->poss--] - *base) - c;
if (c < 0)
{
nb->nbr[nb->poss++] = get_digit(base, c + 10);
c = 1;
}
else
{
nb->nbr[nb->poss++] = get_digit(base, c);
c = 0;
}
}
while (nb1->poss >= 0)
{
c = nb1->nbr[nb1->poss--] - *base - c;
if (c < 0)
{
nb->nbr[nb->poss++] = get_digit(base, c + 10);
c = 1;
}
else
{
nb->nbr[nb->poss++] = get_digit(base, c);
c = 0;
}
}
if (nb1->neg < 0 && nb->nbr[0] != *base)
nb->neg = 1;
return (nb);
}
t_nb *my_multi(t_nb *nb1, t_nb *nb2, char *base)
{
my_putstr("multiplication\n");
return (NULL);
}
t_nb *my_div(t_nb *nb1, t_nb *nb2, char *base)
{
my_putstr("division\n");
return (NULL);
}