From bdf9a52625f1d7a12c1ce071da962ad057adaeb0 Mon Sep 17 00:00:00 2001 From: dzaima Date: Sun, 2 Mar 2025 19:47:00 +0200 Subject: [PATCH] =?UTF-8?q?more=20proper=20error=20messages=20for=20/?= =?UTF-8?q?=E2=81=BC=F0=9D=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/slash.c | 16 ++++++++++------ test/cases/prims.bqn | 3 +++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/builtins/slash.c b/src/builtins/slash.c index e863cd74..a87c46ac 100644 --- a/src/builtins/slash.c +++ b/src/builtins/slash.c @@ -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; ixp[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; imax) 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; imax) 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; jmax?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