summaryrefslogtreecommitdiff
path: root/sys/src/libmp/port/mpcmp.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libmp/port/mpcmp.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libmp/port/mpcmp.c')
-rwxr-xr-xsys/src/libmp/port/mpcmp.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/sys/src/libmp/port/mpcmp.c b/sys/src/libmp/port/mpcmp.c
new file mode 100755
index 000000000..a2e3cf724
--- /dev/null
+++ b/sys/src/libmp/port/mpcmp.c
@@ -0,0 +1,28 @@
+#include "os.h"
+#include <mp.h>
+#include "dat.h"
+
+// return neg, 0, pos as abs(b1)-abs(b2) is neg, 0, pos
+int
+mpmagcmp(mpint *b1, mpint *b2)
+{
+ int i;
+
+ i = b1->top - b2->top;
+ if(i)
+ return i;
+
+ return mpveccmp(b1->p, b1->top, b2->p, b2->top);
+}
+
+// return neg, 0, pos as b1-b2 is neg, 0, pos
+int
+mpcmp(mpint *b1, mpint *b2)
+{
+ if(b1->sign != b2->sign)
+ return b1->sign - b2->sign;
+ if(b1->sign < 0)
+ return mpmagcmp(b2, b1);
+ else
+ return mpmagcmp(b1, b2);
+}