On Nov 29, 2007 7:44 PM, Dan Bron <[EMAIL PROTECTED]> wrote:
> Ambrus observed:
> >  Phrases 8C. has this verb:
> >     d0=: >:@<[EMAIL PROTECTED]  NB.  Length to represent y in base x
> >  This verb is imprecise.
> >
> >  Could you tell me what the best way to do this calculation correctly is?
>
> The fix for this problem is to have zero tolerance in the first place:
>
>            d0m=: >:@(<.!.0)@^.

That one can't work.  In fact, it breaks for smaller numbers than the
tolerant version (there's a good reason why <. is tolerant).

   d0m=: >:@(<.!.0)@^.
   ]p =: ]10*^:(<50)10
10 100 1000 10000 100000 1e6 1e7 1e8 1e9 1e10 1e11 1e12 1e13 1e14 1e15
1e16 1e17 1e18 1e19 1e20 1e21 1e22 1e23 1e24 1e25 1e26 1e27 1e28 1e29
1e30 1e31 1e32 1e33 1e34 1e35 1e36 1e37 1e38 1e39 1e40 1e41 1e42 1e43
1e44 1e45 1e46 1e47 1e48 1e49 1e50
   10 d0m p
2 3 3 5 6 6 8 9 9 11 12 12 13 15 15 17 18 18 20 21 21 23 23 24 26 26
27 29 29 30 31 33 33 35 36 36 38 39 39 41 42 42 44 45 45 46 48 48 49
51

> verbs like these will also work:
>
>           d0f0=: 1 +  <[EMAIL PROTECTED]&x:
>           d0f1=: 1 + (<[EMAIL PROTECTED] x:)

Thanks, those do seem to work.

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

Reply via email to