On Sun, Sep 18, 2011 at 7:11 AM, David Vaughan
<[email protected]> wrote:
> Could you explain how the power (^:2:) part works in plain English?

f^:2: does f twice:

    |.&.": 123450245000
542054321
    |.&.":  |.&.": 123450245000
123450245

Also, using 2: instead of just 2 breaks up the sequence 2 123450245000
into two different words.  And since ^: can use a noun or a verb right
argument, it was just convenient to use 2: there, instead of 2.

That said, I have a 64 bit machine, and so I had no problem with loss
of precision for this particular number.  You apparently have a 32 bit
machine and so numbers greater than about 2 billion (2^31) work
differently for you than they do for me.  On my machine, integers can
be up to 9 quintillion (2^63).  On either machine they become floating
point numbers when the limit is reached, and floating point numbers
can represent integers up to about 9 quadrillion (2^53) before they
start getting rounded to a multiple of a power of 2.

Sadly, ": loses track of whether a number was extended precision which
means that the
    |.&.":^:2: 123450245000x
approach will also fail if the intermediate result is too large to be
represented as an integer by ":

If that is an issue for you, it becomes:
   ('x',~|.)&.":^:2

Though you still need to use a trailing 'x' on the original number or
you get a different value when your number is large enough

   123456789123456789123456789
1.23457e26
   x:123456789123456789123456789
123456789123456791337762816

FYI,

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

Reply via email to