From b8c362247b8dd3af81bf43477e8fcc4ceb8e3906 Mon Sep 17 00:00:00 2001 From: dzaima Date: Tue, 1 Jun 2021 17:13:43 +0300 Subject: [PATCH] fix F`fillarr leaking fill element also print higher precision numbers --- src/builtins/md1.c | 2 +- src/builtins/sysfn.c | 2 +- src/core/harr.c | 1 + src/core/stuff.c | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/builtins/md1.c b/src/builtins/md1.c index d3a31942..a8faa591 100644 --- a/src/builtins/md1.c +++ b/src/builtins/md1.c @@ -87,10 +87,10 @@ B each_c2(B d, B w, B x) { B f = c(Md1D,d)->f; B scan_c1(B d, B x) { B f = c(Md1D,d)->f; if (isAtm(x) || rnk(x)==0) thrM("`: Argument cannot have rank 0"); - B xf = getFillQ(x); ur xr = rnk(x); usz ia = a(x)->ia; if (ia==0) return x; + B xf = getFillQ(x); if (xr==1 && TI(x).elType==el_i32 && isFun(f) && v(f)->flags) { u8 rtid = v(f)->flags-1; i32* xp = i32any_ptr(x); diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index d0eed0af..c09ed4d0 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -41,7 +41,7 @@ B repr_c1(B t, B x) { #define BL 100 if (isF64(x)) { char buf[BL]; - snprintf(buf, BL, "%g", x.f); + snprintf(buf, BL, "%.14g", x.f); return m_str8(strlen(buf), buf); } else { #ifdef FORMATTER diff --git a/src/core/harr.c b/src/core/harr.c index 13fb437f..fa2b7708 100644 --- a/src/core/harr.c +++ b/src/core/harr.c @@ -85,6 +85,7 @@ NOINLINE void harr_pfree(B x, usz am) { // am - item after last written assert(v(x)->type==t_harr); B* p = harr_ptr(x); for (usz i = 0; i < am; i++) dec(p[i]); + if (rnk(x)>1) ptr_dec(shObj(x)); mm_free(v(x)); } diff --git a/src/core/stuff.c b/src/core/stuff.c index f8721d2c..36239eaf 100644 --- a/src/core/stuff.c +++ b/src/core/stuff.c @@ -99,7 +99,7 @@ NOINLINE void print(B x) { NOINLINE void printRaw(B x) { if (isAtm(x)) { - if (isF64(x)) printf("%g", x.f); + if (isF64(x)) printf("%.14g", x.f); else if (isC32(x)) printUTF8((u32)x.u); else thrM("bad printRaw argument: atom arguments should be either numerical or characters"); } else { @@ -196,7 +196,7 @@ NOINLINE B append_fmt(B s, char* p, ...) { AU("¯"); f=-f; } - snprintf(buf, 30, "%g", f); + snprintf(buf, 30, "%.14g", f); A8(buf); break; }