xref: /inferno-os/libmp/port/mpcmp.c (revision 7ef44d652ae9e5e1f5b3465d73684e4a54de73c0)
1 #include "os.h"
2 #include <mp.h>
3 #include "dat.h"
4 
5 // return neg, 0, pos as abs(b1)-abs(b2) is neg, 0, pos
6 int
7 mpmagcmp(mpint *b1, mpint *b2)
8 {
9 	int i;
10 
11 	i = b1->top - b2->top;
12 	if(i)
13 		return i;
14 
15 	return mpveccmp(b1->p, b1->top, b2->p, b2->top);
16 }
17 
18 // return neg, 0, pos as b1-b2 is neg, 0, pos
19 int
20 mpcmp(mpint *b1, mpint *b2)
21 {
22 	if(b1->sign != b2->sign)
23 		return b1->sign - b2->sign;
24 	if(b1->sign < 0)
25 		return mpmagcmp(b2, b1);
26 	else
27 		return mpmagcmp(b1, b2);
28 }
29