Hmm... actually there might be a floating point overflow problem for
gigabyte length arguments. I do not have the patience, however, to
find what (for example) adler32 1e9#{:a. is.Thanks, -- Raul On Sun, Aug 24, 2014 at 4:37 AM, Raul Miller <[email protected]> wrote: > I believe this is equivalent, and a bit faster: > > a32=: 65536#. 65521| _1 0+ [:(+/ , {.) 65521| [:+/\. 1,~ a.i. |. > > a32 'Wikipedia' > 300286872 > a32 'The quick brown fox jumps over the lazy dog' > 1541148634 > > Thanks, > > -- > Raul > > > On Sun, Aug 24, 2014 at 4:05 AM, bill lam <[email protected]> wrote: >> Does anyone have a J-ish solution to adler32 checksum >> and avoid overflow to floating points ? >> >> Adler-32 is composed of two sums accumulated per byte: s1 is >> the sum of all bytes, s2 is the sum of all s1 values. Both sums >> are done modulo 65521. s1 is initialized to 1, s2 to zero. The >> Adler-32 checksum is stored as s2*65536 + s1 in most- >> significant-byte first (network) order. >> >> * https://www.ietf.org/rfc/rfc1950.txt >> * http://en.wikipedia.org/wiki/Adler-32 >> >> direct translation to J >> >> adler32=: 3 : 0 >> 's1 s2'=. 1 0 >> for_a. a.i.y do. >> s1=. 65521 | s1 + a >> s2=. 65521 | s2 + s1 >> end. >> s1 + 16 (33 b.) s2 >> ) >> >> test data: >> >> adler32 'Wikipedia' >> 300286872 >> >> adler32 'The quick brown fox jumps over the lazy dog' >> 1541148634 >> >> -- >> regards, >> ==================================================== >> GPG key 1024D/4434BAB3 2008-08-24 >> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3 >> gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3 >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
