diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 67fa629c..5979cd72 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -147,6 +147,7 @@ B shape_c2(B t, B w, B x) { unkPos = i; if (!isPrim(c)) thrM("⥊: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑"); unkInd = ((i32)v(c)->flags) - 1; + good|= xia==0 | unkInd==n_floor; } } if (bad && !good) thrM("⥊: 𝕨 too large"); @@ -712,36 +713,50 @@ B slash_im(B t, B x) { usz xia = IA(x); if (xia==0) { decG(x); return emptyIVec(); } switch(xe) { default: UD; - case el_i8: { - i8* xp = i8any_ptr(x); - usz i,j; B r; i8 max=-1; - for (i = 0; i < xia; i++) { i8 c=xp[i]; if (c<=max) break; max=c; } - for (j = i; j < xia; j++) { i8 c=xp[j]; max=c>max?c:max; if (c<0) thrM("/⁼: Argument cannot contain negative numbers"); } - usz ria = max+1; - if (i==xia) { - u64* rp; r = m_bitarrv(&rp, ria); for (usz i=0; i0); + f64* rp; B r = m_f64arrv(&rp, ria); + rp[sum>0] = sum; rp[0] = xia - sum; + decG(x); return num_squeeze(r); } - case el_i16: { - i16* xp = i16any_ptr(x); - usz i,j; B r; i16 max=-1; - for (i = 0; i < xia; i++) { i16 c=xp[i]; if (c<=max) break; max=c; } - for (j = i; j < xia; j++) { i16 c=xp[j]; max=c>max?c:max; if (c<0) thrM("/⁼: Argument cannot contain negative numbers"); } - usz ria = max+1; - if (i==xia) { - u64* rp; r = m_bitarrv(&rp, ria); for (usz i=0; ixp[a-1]) a++; \ + max=xp[a-1]; \ + if (a==xia) { /* Sorted unique argument */ \ + usz ria = max + 1; \ + u64* rp; r = m_bitarrv(&rp, ria); \ + for (usz i=0; imax) max=c; } \ + if ((i##N)max<0) thrM("/⁼: Argument cannot contain negative numbers"); \ + usz ria = max+1; \ + i##N* rp; r = m_i##N##arrv(&rp, ria); for (usz i=0; im/2) thrM("/⁼: Argument cannot contain negative numbers"); \ + i32* rp; r = m_i32arrv(&rp, ria); for (usz i=0; ia; } diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 888dae36..a4457d5a 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -468,10 +468,8 @@ B rand_subset_c2(B t, B w, B x) { if (RARE(wi<0)) thrM("(rand).Subset: 𝕨 cannot be negative"); if (RARE(xi<0)) thrM("(rand).Subset: 𝕩 cannot be negative"); if (RARE(wi>xi)) thrM("(rand).Subset: 𝕨 cannot exceed 𝕩"); - if (wi==xi) { - if (wi==0) return emptyIVec(); - return ud_c1(t, x); // Only one complete subset; will hang without this - } + if (wi==0) return emptyIVec(); + if (wi==xi) return ud_c1(t, x); // Only one complete subset; will hang without this B r; RAND_START;