From de3bbbc0981bde7a02f7f5398ce921e0beb4c174 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Sun, 16 Jan 2022 00:48:37 +0000 Subject: Implement floats --- print.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'print.c') diff --git a/print.c b/print.c index bf1be0c..ae29a01 100644 --- a/print.c +++ b/print.c @@ -4,6 +4,8 @@ #include "apl9.h" +int printprecision = 10; + void strdims(Rune *, int *, int *); Rune *printborder(Rune *, int *, int, int); Rune *strline(Rune *, int); @@ -69,7 +71,7 @@ pparray(Array *a) rowcount *= a->shape[i]; } Rune **rowstrs = mallocz(sizeof(Rune *) * rowcount, 1); - int boxing = a->type == AtypeArray; + int boxing = !simplearray(a); char *align = a->type == AtypeArray ? "-" : ""; for(int i = 0; i < a->size; i++){ @@ -79,6 +81,18 @@ pparray(Array *a) free(arrstr); }else if(a->type == AtypeInt) elemstrs[i] = runesmprint("%lld", a->intdata[i]); + else if(a->type == AtypeFloat){ + char *fmt = smprint("%%.%df", printprecision); + elemstrs[i] = runesmprint(fmt, a->floatdata[i]); + free(fmt); + Rune *p = &elemstrs[i][runestrlen(elemstrs[i])-1]; + int done = 0; + while((*p == '0' || *p == '.') && !done){ + if(*p == '.') + done = 1; + *p-- = 0; /* remove trailing 0's */ + } + } } int lastdim = a->rank ? a->shape[a->rank-1] : 1; -- cgit v1.2.3