summaryrefslogtreecommitdiff
path: root/print.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2022-01-16 00:48:37 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2022-01-16 00:48:37 +0000
commitde3bbbc0981bde7a02f7f5398ce921e0beb4c174 (patch)
tree88813af01d0d16a19a205f4bd0f07fcc555d5a81 /print.c
parentf02e90b27e37f91d4409842dd21cd00c999c805d (diff)
Implement floats
Diffstat (limited to 'print.c')
-rw-r--r--print.c16
1 files changed, 15 insertions, 1 deletions
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;