separate out simple comparison

This commit is contained in:
dzaima 2021-05-24 18:05:35 +03:00
parent 200456ac72
commit b2e65cc9b7
3 changed files with 9 additions and 4 deletions

View File

@ -196,9 +196,7 @@ NOINLINE B append_fmt(B s, char* p, ...) {
}
#define CMP(W,X) ({ AUTO wt = (W); AUTO xt = (X); (wt>xt?1:0)-(wt<xt?1:0); })
i32 compare(B w, B x) {
if (isNum(w) & isNum(x)) return CMP(o2fu(w), o2fu(x));
if (isC32(w) & isC32(x)) return CMP(o2cu(w), o2cu(x));
NOINLINE i32 compareR(B w, B x) {
if (isNum(w) & isC32(x)) return -1;
if (isC32(w) & isNum(x)) return 1;
if (isAtm(w) & isAtm(x)) thrM("Invalid comparison");

View File

@ -157,6 +157,14 @@ static B def_m2_uc1(B t, B o, B f, B g, B x) { B t2 = m2_d(inc(t),inc(f),in
static B def_m2_ucw(B t, B o, B f, B g, B w, B x) { B t2 = m2_d(inc(t),inc(f),inc(g)); B r = rtUnder_cw(o, t2, w, x); dec(t2); return r; }
static B def_decompose(B x) { return m_v2(m_i32(isCallable(x)? 0 : -1),x); }
#define CMP(W,X) ({ AUTO wt = (W); AUTO xt = (X); (wt>xt?1:0)-(wt<xt?1:0); })
NOINLINE i32 compareR(B w, B x);
static i32 compare(B w, B x) { // doesn't consume; -1 if w<x, 1 if w>x, 0 if w≡x; 0==compare(NaN,NaN)
if (isNum(w) & isNum(x)) return CMP(o2fu(w), o2fu(x));
if (isC32(w) & isC32(x)) return CMP(o2cu(w), o2cu(x));
return compareR(w, x);
}
#undef CMP

View File

@ -265,7 +265,6 @@ void print(B x); // doesn't consume
void arr_print(B x); // doesn't consume
bool equal(B w, B x); // doesn't consume
bool eequal(B w, B x); // doesn't consume
i32 compare(B w, B x); // doesn't consume; -1 if w<x, 1 if w>x, 0 if w≡x; 0==compare(NaN,NaN)
bool atomEqual(B w, B x); // doesn't consume
u64 depth(B x); // doesn't consume
B toCells(B x); // consumes