improve •ParseFloat error message on argument with codepoints ≥256

This commit is contained in:
dzaima 2025-05-01 22:48:12 +03:00
parent b1ef72039c
commit e32d41eb61
2 changed files with 18 additions and 2 deletions

View File

@ -121,7 +121,10 @@ B parseFloat_c1(B t, B x) {
if (isAtm(x)) thrM("•ParseFloat 𝕩: Expected a character list argument");
if (TI(x,elType)!=el_c8) {
x = chr_squeeze(x);
if (TI(x,elType)!=el_c8) thrM("•ParseFloat 𝕩: Expected a character list argument");
if (TI(x,elType)!=el_c8) {
if (elChr(TI(x,elType))) malformed: thrM("•ParseFloat 𝕩: Malformed input");
thrM("•ParseFloat 𝕩: Expected a character list argument");
}
}
usz ia = IA(x);
if (RNK(x)!=1) thrM("•ParseFloat 𝕩: Input must have rank 1");
@ -129,7 +132,7 @@ B parseFloat_c1(B t, B x) {
if (ia >= (1<<20)) thrM("•ParseFloat 𝕩: Input too long"); // assumption by ryu_s2d_n
u8* data = c8any_ptr(x);
f64 res;
if (!ryu_s2d_n(data, ia, &res)) thrM("•ParseFloat 𝕩: Malformed input");
if (!ryu_s2d_n(data, ia, &res)) goto malformed;
decG(x);
return m_f64(res);
}

View File

@ -202,9 +202,22 @@ v←1 ⋄ ! •BQN∘•Repr⊸≡ ⟨+,1‿2,+¨,(+V)(V+V),2‿2⥊↕4⟩
641•bit._cast •ParseFloat¨ "123.456000000000000""123.45600000000002" %% "11101110011111011111100101011000111101001011101101111010000000100001111001111101111110010101100011110100101110110111101000000010"-'0'
! ´'e'=•ParseFloat'e'¨ "-""e2""-e2""."".e2""123e""123e-""123e+"
•ParseFloat "0."(n'0')"1234e"•Repr n1000000 %% 0.1234
•ParseFloat 1e6'1' %%
!"•ParseFloat 𝕩: Input too long" % •ParseFloat 2e6'1'
•Repr•ParseFloat¨ "1.23516411460311636e-323", "1.23516411460311637e-323" %% "1e¯323","1.5e¯323"
•Repr•ParseFloat¨ "1.235164114603116360e-323", "1.235164114603116361e-323" %% "1e¯323","1e¯323"
•Repr•ParseFloat¨ "1.2351641146031163604e-323", "1.2351641146031163605e-323" %% "1e¯323","1e¯323"
!"•ParseFloat 𝕩: Input was empty" % •ParseFloat ""
!"•ParseFloat 𝕩: Input was empty" % •ParseFloat 0
!"•ParseFloat 𝕩: Input must have rank 1" % •ParseFloat <@
!"•ParseFloat 𝕩: Input must have rank 1" % •ParseFloat 11'1'
!"•ParseFloat 𝕩: Expected a character list argument" % •ParseFloat 4849
!"•ParseFloat 𝕩: Expected a character list argument" % •ParseFloat <48
!"•ParseFloat 𝕩: Malformed input" % •ParseFloat "1e1e1"
!"•ParseFloat 𝕩: Malformed input" % •ParseFloat @
!"•ParseFloat 𝕩: Malformed input" % •ParseFloat @+254
!"•ParseFloat 𝕩: Malformed input" % •ParseFloat @+1111
!"•ParseFloat 𝕩: Malformed input" % •ParseFloat @+1114111
# •Fmt
•Fmt 123 %% "123"