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