3 functions to get a list of extended integers into boxed lists of smaller
bases:
a =. _33 2147483304598340953804093234 234234 434332323 248203948203498203492
83049283402394820
112301928310298310293810293810293810293810293881301982301928310239839482039482834825
112312 1 0 29348239429384729347293874293870923409283498647x
b=.
8213740918273492837491827349182734912834791283741982734982173498127349812749827349812734912873471928479182741928374912873498127491238741923874912387412938741923847928173491287349182737912873912873740192874x
xtoa =: ([ (-@[ |.@:(0&".@:|.\)&.> <@|.@]) ":@:])"0
xtoa2 =: [: (] ([{~leaf ] (>:@[ + |.@i.@]) each {~) 4 + 4 %~ ] {~ 5 + [: i.
4&{) _4 ,@:((_2&ic)\) 1 (3!:1) ]
xtoa3 =: [ (-@[ |.@:(0&".@:|.\) |.@]) ":@:] NB. same but without rank
xtoa2 is cleverest, and near-fastest. It only does base 10000 though, and it
has a bug that only works on lists.
xtoa is faster especially for larger values, works for single numbers, and sets
to any base (4 for compatibility with xtoa2/3!:1, 9 for 32 bit, 18 for 64 bit)
xtoa3 is surprisingly slightly slower than xtoa, even on a single argument.
But it gives a choice of boxing or other adverbs
examples
9 xtoa3 each a
4 xtoa a
18 xtoa3 b
xtoa2 a
----- Original Message -----
From: 'Pascal Jasmin' via Programming <[email protected]>
To: Programming Forum <[email protected]>
Cc:
Sent: Thursday, August 13, 2015 9:23 PM
Subject: [Jprogramming] memory representation of extended integers
for regular integers, memory representation is straightforward
_4 ]\ a. i. 0 ( 3!:1) ] 2147483647
224 0 0 0
0 0 0 4
0 0 0 1
0 0 0 0
127 255 255 255
_4 ]\ a. i. 0 ( 3!:1) ] 2147483647x
224 0 0 0
0 0 0 64
0 0 0 1
0 0 0 0
0 0 0 20
224 0 0 0
0 0 0 4
0 0 0 3
0 0 0 1
0 0 0 3
0 0 14 63
0 0 18 140
0 0 0 21
weird enough, but its:
|. 256 #. inv 10000 #. inv 2147483647
14 63
18 140
0 21
in the last 3 bytes
the header part is a 5 word header
224 0 0 0
0 0 0 4
0 0 0 3
0 0 0 1
0 0 0 3
lines 1 2 4 appear to be fixed. lines 3 and 5 appear to both point to the
count of data words that follow.
I guess the format is optimized for decimal display, but its using 64 bits per
base 10000 digit.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm