more proper error messages for /⁼𝕩
This commit is contained in:
parent
17ec5f0a8a
commit
bdf9a52625
@ -866,6 +866,10 @@ static B finish_sorted_count(B r, usz* ov, usz* oc, usz on) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static NORETURN void slash_im_bad(f64 c) {
|
||||
if (c < 0) thrM("/⁼𝕩: 𝕩 cannot contain negative numbers");
|
||||
else thrM("/⁼𝕩: 𝕩 must consist of natural numbers");
|
||||
}
|
||||
B slash_im(B t, B x) {
|
||||
if (!isArr(x) || RNK(x)!=1) thrM("/⁼𝕩: 𝕩 must be a list");
|
||||
u8 xe = TI(x,elType);
|
||||
@ -886,7 +890,7 @@ B slash_im(B t, B x) {
|
||||
i##N* rp; r = m_i##N##arrv(&rp, RIA); \
|
||||
for (usz i=0; i<RIA; i++) rp[i]=0;
|
||||
#define TRY_SMALL_OUT(N) \
|
||||
if (xp[0]<0) thrM("/⁼𝕩: 𝕩 cannot contain negative numbers"); \
|
||||
if (xp[0]<0) thrM("/⁼𝕩: 𝕩 cannot contain negative numbers"); \
|
||||
usz a=1; while (a<xia && xp[a]>xp[a-1]) a++; \
|
||||
u##N max=xp[a-1]; \
|
||||
usz rmax=xia; \
|
||||
@ -902,7 +906,7 @@ B slash_im(B t, B x) {
|
||||
break; \
|
||||
} \
|
||||
for (usz i=a; i<xia; i++) { u##N c=xp[i]; if (c>max) max=c; } \
|
||||
if ((i##N)max<0) thrM("/⁼𝕩: 𝕩 cannot contain negative numbers"); \
|
||||
if ((i##N)max<0) thrM("/⁼𝕩: 𝕩 cannot contain negative numbers"); \
|
||||
usz ria = max + 1; \
|
||||
if (xia < ria/8) { \
|
||||
u8 maxcount = 0; \
|
||||
@ -939,7 +943,7 @@ B slash_im(B t, B x) {
|
||||
usz os = xia>>15; \
|
||||
TALLOC(u16, ov, os+1); \
|
||||
i##N max = simd_count_i##N((u16*)rp, (u16*)ov, xp, xia, 0); \
|
||||
if (max < 0) thrM("/⁼𝕩: 𝕩 cannot contain negative numbers"); \
|
||||
if (max < 0) thrM("/⁼𝕩: 𝕩 cannot contain negative numbers"); \
|
||||
usz ria = (usz)max + 1; \
|
||||
if (ria < sa) r = C2(take, m_f64(ria), r); \
|
||||
r = finish_small_count(r, ov); \
|
||||
@ -963,7 +967,7 @@ B slash_im(B t, B x) {
|
||||
i##N* xp = i##N##any_ptr(x); \
|
||||
u##N max=xp[0]; \
|
||||
for (usz i=1; i<xia; i++) { u##N c=xp[i]; if (c>max) max=c; } \
|
||||
if ((i##N)max<0) thrM("/⁼𝕩: 𝕩 cannot contain negative numbers"); \
|
||||
if ((i##N)max<0) thrM("/⁼𝕩: 𝕩 cannot contain negative numbers"); \
|
||||
usz ria = max + 1; \
|
||||
TALLOC(usz, t, ria); \
|
||||
for (usz j=0; j<ria; j++) t[j]=0; \
|
||||
@ -978,8 +982,8 @@ B slash_im(B t, B x) {
|
||||
case el_f64: {
|
||||
f64* xp = f64any_ptr(x);
|
||||
usz i,j; f64 max=-1;
|
||||
for (i = 0; i < xia; i++) { f64 c=xp[i]; if (c!=(usz)c) thrM("/⁼𝕩: 𝕩 must consist of natural numbers"); if (c<=max) break; max=c; }
|
||||
for (j = i; j < xia; j++) { f64 c=xp[j]; if (c!=(usz)c) thrM("/⁼𝕩: 𝕩 must consist of natural numbers"); max=c>max?c:max; if (c<0) thrM("/⁼: Argument cannot contain negative numbers"); }
|
||||
for (i = 0; i < xia; i++) { f64 c=xp[i]; if (!q_fusz(c)) slash_im_bad(c); if (c<=max) break; max=c; }
|
||||
for (j = i; j < xia; j++) { f64 c=xp[j]; if (!q_fusz(c)) slash_im_bad(c); max=c>max?c:max; }
|
||||
usz ria = max+1; if (ria==0) thrOOM();
|
||||
if (i==xia) {
|
||||
u64* rp; r = m_bitarrv(&rp, ria); for (usz i=0; i<BIT_N(ria); i++) rp[i]=0;
|
||||
|
||||
@ -130,6 +130,9 @@ w←1‿1⥊1 ⋄ x←2⥊1 ⋄ w‿x <¨↩ ⋄ {! (∾⟨"𝕨",•Repr𝕩,
|
||||
!"Integer out of range: 1e20" % %USE evar ⋄ /_evar 1e20⌾(100⊸⊑) 200⥊10
|
||||
! (//⁼)⊸≡8‿15‿25‿32‿90‿101‿155‿165‿584‿594‿894‿912‿1312‿1328‿1350‿1367‿1391‿1407‿1469‿1486‿1559‿1566‿1576‿1582‿1592‿1599‿1609‿1616‿1626‿1635‿4086‿4093‿4114‿4122‿4141‿4149‿4169‿4177
|
||||
/⁼1e4⥊1‿2 %% 0‿5000‿5000
|
||||
!"/⁼𝕩: 𝕩 cannot contain negative numbers" % %USE evar ⋄ /⁼_evar (↕10) ∾ ¯2 ∾ 20+↕10
|
||||
!"/⁼𝕩: 𝕩 must consist of natural numbers" % %USE evar ⋄ /⁼_evar (↕10) ∾ 2.2 ∾ 20+↕10
|
||||
!"/⁼𝕩: 𝕩 must consist of natural numbers" % %USE evar ⋄ /⁼_evar (↕10) ∾ 1e20 ∾ 20+↕10
|
||||
|
||||
# 𝕨⊏𝕩
|
||||
•internal.ElType¨ {(100⥊↕2)⊏𝕨‿𝕩}⌜˜ ⟨0, 1, 2, 127, 128, 32767, 32768, ¯32767, ¯32768, ¯32769, ¯1+2⋆31, 2⋆31, @, @+1, @+255, @+256, @+1114111, {⇐}, 1‿2⟩ %% (8-(=⌜˜<⟜5)×8-⌈⌜˜) 0‿0‿1‿1‿2‿2‿3‿2‿2‿3‿3‿4‿5‿5‿5‿6‿7‿8‿8
|
||||
|
||||
Loading…
Reference in New Issue
Block a user