more proper error messages for /⁼𝕩

This commit is contained in:
dzaima 2025-03-02 19:47:00 +02:00
parent 17ec5f0a8a
commit bdf9a52625
2 changed files with 13 additions and 6 deletions

View File

@ -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;

View File

@ -130,6 +130,9 @@ w←1‿1⥊1 ⋄ x←2⥊1 ⋄ w‿x <¨↩ ⋄ {! (∾⟨"𝕨",•Repr𝕩,
!"Integer out of range: 1e20" % %USE evar /_evar 1e20(100) 20010
! (//)81525329010115516558459489491213121328135013671391140714691486155915661576158215921599160916161626163540864093411441224141414941694177
/1e412 %% 050005000
!"/⁼𝕩: 𝕩 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¨ {(1002)𝕨𝕩}˜ 0, 1, 2, 127, 128, 32767, 32768, ¯32767, ¯32768, ¯32769, ¯1+231, 231, @, @+1, @+255, @+256, @+1114111, {}, 12 %% (8-(=˜<5)×8-˜) 0011223223345556788