Dear forum,

Is there a way to make 8!:0 use an exponential format for nonzero
numbers with absolute value below 1e_2 or make it use an exponential
format for all numbers?  I find the current default unusable because
there's no way to make it not lose precision:

   8!:0 ] 1.234567e_9
+-----------+
|0.000000001|
+-----------+
   '6' 8!:0 ] 1.234567e_9
+--------+
|0.000000|
+--------+

I could of course work this around by writing my own formatter function, such as

   '-'"_^:('_'&=)"0": 1.234567e_9
1.23457e-9

Or, more generally,

$ cat format.c
#include <stdio.h>
static char formatbuf[128];
char *
formatnumber(int digits, double val) {
        if (0 <= digits)
                snprintf(formatbuf, sizeof(formatbuf), "%.*e", digits, val);
        else
                snprintf(formatbuf, sizeof(formatbuf), "%.*g", -digits, val);
        return formatbuf;
}
$ gcc -fpic -shared -Wall -O2 -o format.so format.c
   $ jconsole
   formatnumber =: ([: < [: 15!:1 (0,_1),~
'/home/ambrus/local/lib/format.so formatnumber > x i d' 15!:0 [;])"0
   42^i:5
7.65162e_9 3.21368e_7 1.34975e_5 0.000566893 0.0238095 1 42 1764 74088
3.1117e6 1.30691e8
   ;,&' '&.> _6 formatnumber 42^i:5
         7.65162e-09 3.21368e-07 1.34975e-05 0.000566893 0.0238095 1
42 1764 74088 3.1117e+06 1.30691e+08
   (9!:14;9!:12)$0
+---------------------+-+
|j602/2008-03-03/16:45|5|
+---------------------+-+

Ambrus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to