Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / mcmp.cpp
blobc72ef3707c78dd26249a06e43cc5501ef1694b31
1 // Bignum compare
2 //
3 // returns
4 //
5 // -1 a < b
6 //
7 // 0 a = b
8 //
9 // 1 a > b
11 #include "stdafx.h"
12 #include "defs.h"
14 int
15 mcmp(unsigned int *a, unsigned int *b)
17 int i;
19 if (MSIGN(a) == -1 && MSIGN(b) == 1)
20 return -1;
22 if (MSIGN(a) == 1 && MSIGN(b) == -1)
23 return 1;
25 // same sign
27 if (MLENGTH(a) < MLENGTH(b)) {
28 if (MSIGN(a) == 1)
29 return -1;
30 else
31 return 1;
34 if (MLENGTH(a) > MLENGTH(b)) {
35 if (MSIGN(a) == 1)
36 return 1;
37 else
38 return -1;
41 // same length
43 for (i = MLENGTH(a) - 1; i > 0; i--)
44 if (a[i] != b[i])
45 break;
47 if (a[i] < b[i]) {
48 if (MSIGN(a) == 1)
49 return -1;
50 else
51 return 1;
54 if (a[i] > b[i]) {
55 if (MSIGN(a) == 1)
56 return 1;
57 else
58 return -1;
61 return 0;
64 int
65 mcmpint(unsigned int *a, int n)
67 int t;
68 unsigned int *b;
69 b = mint(n);
70 t = mcmp(a, b);
71 mfree(b);
72 return t;