]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libmp/port/mpcmp.c
merge
[plan9front.git] / sys / src / libmp / port / mpcmp.c
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->flags | b2->flags;
12         if(i & MPtimesafe)
13                 return mpvectscmp(b1->p, b1->top, b2->p, b2->top);
14         if(i & MPnorm){
15                 i = b1->top - b2->top;
16                 if(i)
17                         return i;
18         }
19         return mpveccmp(b1->p, b1->top, b2->p, b2->top);
20 }
21
22 // return neg, 0, pos as b1-b2 is neg, 0, pos
23 int
24 mpcmp(mpint *b1, mpint *b2)
25 {
26         int sign;
27
28         sign = (b1->sign - b2->sign) >> 1;      // -1, 0, 1
29         return sign | (sign&1)-1 & mpmagcmp(b1, b2)*b1->sign;
30 }