diff options
author | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-16 00:48:37 +0000 |
---|---|---|
committer | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-16 00:48:37 +0000 |
commit | de3bbbc0981bde7a02f7f5398ce921e0beb4c174 (patch) | |
tree | 88813af01d0d16a19a205f4bd0f07fcc555d5a81 /print.c | |
parent | f02e90b27e37f91d4409842dd21cd00c999c805d (diff) |
Implement floats
Diffstat (limited to 'print.c')
-rw-r--r-- | print.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -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; |