/i32arr
This commit is contained in:
parent
7df1b5d4a7
commit
81cdfa9cab
18
src/arith.c
18
src/arith.c
@ -139,19 +139,19 @@ CMP(> , gt, 1)
|
||||
|
||||
B decp_c1(B t, B x);
|
||||
#define CMP_IMPL(OP) \
|
||||
if (isF64(w)&isF64(x)) return m_i32(w.f OP x.f); \
|
||||
bool wa = isArr(w); \
|
||||
bool xa = isArr(x); \
|
||||
if (wa|xa) { \
|
||||
u8 we = wa? TI(w).elType : selfElType(w); \
|
||||
u8 xe = xa? TI(x).elType : selfElType(x); \
|
||||
if (we==el_i32 && xe==el_i32) { \
|
||||
if (isF64(w)&isF64(x)) return m_i32(w.f OP x.f); \
|
||||
bool wa = isArr(w); \
|
||||
bool xa = isArr(x); \
|
||||
if (wa|xa) { \
|
||||
u8 we = wa? TI(w).elType : selfElType(w); \
|
||||
u8 xe = xa? TI(x).elType : selfElType(x); \
|
||||
if (we==el_i32 && xe==el_i32) { \
|
||||
i32* rp; B r = m_i32arrc(&rp, isArr(x)? x : w); usz ria=a(r)->ia; \
|
||||
if (!wa) { i32 wv=o2iu(w); i32* xp=i32any_ptr(x); for(usz i=0;i<ria;i++)rp[i]=wv OP xp[i]; } \
|
||||
else if (!xa) { i32 xv=o2iu(x); i32* wp=i32any_ptr(w); for(usz i=0;i<ria;i++)rp[i]=wp[i] OP xv; } \
|
||||
else { i32* wp=i32any_ptr(w); i32* xp=i32any_ptr(x); for(usz i=0;i<ria;i++)rp[i]=wp[i] OP xp[i]; } \
|
||||
if(wa) dec(w); if(xa) dec(x); return r; \
|
||||
} \
|
||||
if(wa) dec(w); if(xa) dec(x); return r; \
|
||||
} \
|
||||
}
|
||||
|
||||
B eq_c2(B t, B w, B x) {
|
||||
|
||||
34
src/sfns.c
34
src/sfns.c
@ -307,27 +307,37 @@ B select_c2(B t, B w, B x) {
|
||||
return c2(rt_select, w, x);
|
||||
}
|
||||
|
||||
static NOINLINE B slash_c1R(B x, u64 s) {
|
||||
usz xia = a(x)->ia;
|
||||
BS2B xgetU = TI(x).getU;
|
||||
f64* rp; B r = m_f64arrv(&rp, s); usz ri = 0;
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
usz c = o2s(xgetU(x, i));
|
||||
for (usz j = 0; j < c; j++) rp[ri++] = i;
|
||||
}
|
||||
dec(x);
|
||||
return r;
|
||||
}
|
||||
B rt_slash;
|
||||
B slash_c1(B t, B x) {
|
||||
if (isAtm(x) || rnk(x)!=1) thrF("/: Argument must have rank 1 (%H ≡ ≢𝕩)", x);
|
||||
if (RARE(isAtm(x)) || RARE(rnk(x)!=1)) thrF("/: Argument must have rank 1 (%H ≡ ≢𝕩)", x);
|
||||
i64 s = isum(x);
|
||||
if(s<0) thrM("/: Argument must consist of natural numbers");
|
||||
usz xia = a(x)->ia;
|
||||
BS2B xgetU = TI(x).getU;
|
||||
usz ri = 0;
|
||||
if (xia<I32_MAX) {
|
||||
i32* rp; B r = m_i32arrv(&rp, s);
|
||||
if (RARE(xia>=I32_MAX)) return slash_c1R(x, s);
|
||||
i32* rp; B r = m_i32arrv(&rp, s); usz ri = 0;
|
||||
if (TI(x).elType==el_i32) {
|
||||
i32* xp = i32any_ptr(x);
|
||||
for (i32 i = 0; i < xia; i++) {
|
||||
if (RARE(xp[i])<0) thrF("/: Argument must consist of natural numbers (contained %i)", xp[i]);
|
||||
for (usz j = 0; j < xp[i]; j++) rp[ri++] = i;
|
||||
}
|
||||
} else {
|
||||
BS2B xgetU = TI(x).getU;
|
||||
for (i32 i = 0; i < xia; i++) {
|
||||
usz c = o2s(xgetU(x, i));
|
||||
for (usz j = 0; j < c; j++) rp[ri++] = i;
|
||||
}
|
||||
dec(x);
|
||||
return r;
|
||||
}
|
||||
f64* rp; B r = m_f64arrv(&rp, s);
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
usz c = o2s(xgetU(x, i));
|
||||
for (usz j = 0; j < c; j++) rp[ri++] = i;
|
||||
}
|
||||
dec(x);
|
||||
return r;
|
||||
|
||||
@ -261,6 +261,7 @@ void printRaw(B x) {
|
||||
}
|
||||
|
||||
B def_decompose(B x) { return m_v2(m_i32(isCallable(x)? 0 : -1),x); }
|
||||
static NOINLINE bool equalR(B w, B x) { return equal(w, x); }
|
||||
bool atomEqual(B w, B x) { // doesn't consume (not that that matters really currently)
|
||||
if(isF64(w)&isF64(x)) return w.f==x.f;
|
||||
if (w.u==x.u) return true;
|
||||
@ -273,7 +274,7 @@ bool atomEqual(B w, B x) { // doesn't consume (not that that matters really curr
|
||||
if (o2i(wdp[0])<=1) { dec(wd);dec(xd); return false; }
|
||||
usz wia = a(wd)->ia;
|
||||
if (wia!=a(xd)->ia) { dec(wd);dec(xd); return false; }
|
||||
for (i32 i = 0; i<wia; i++) if(!equal(wdp[i], xdp[i]))
|
||||
for (i32 i = 0; i<wia; i++) if(!equalR(wdp[i], xdp[i]))
|
||||
{ dec(wd);dec(xd); return false; }
|
||||
dec(wd);dec(xd); return true;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user