Using the stuff in "Extended Precision Function" is much easier than you described. For example:
T=: 10000000000000306999999999997669x sqrt T 6324555320336855745921954256628698742902673933907667687147821 ... 0j40 ": sqrt T NB. convert to decimal (40 decimal places) 3162277660168427.8729609771283143493714513369669538338436 *: sqrt T 40000000000001227999999999990675999999999999999999999999999999999999999999999999999999878085398044497550868239384896111082068133938864281704403424300608775651882688760729r4000000000000000000000000000000000000000000000000000000000000000000000000000000000000... 0j40 ": *: sqrt T NB. convert to decimal (40 decimal places) 10000000000000306999999999997669.0000000000000000000000000000000000000000 By the way, to post URLs containing blanks from the J wiki, substituting _ for blanks makes it more convenient. Thus: http://www.jsoftware.com/jwiki/Essays/Extended_Precision_Functions ----- Original Message ----- From: Devon McCormick <[email protected]> Date: Tuesday, January 19, 2010 10:10 Subject: Re: [Jprogramming] difficulty with extended precision arithmetic To: Programming forum <[email protected]> > It looks like the "sqrt" function on the wiki at > http://www.jsoftware.com/jwiki/Essays/Extended Precision > Functions works for > the extended case (with some fiddling necessary to make it decimal): > > DP=: 40 NB. 40 digits > of precision. > > sqrt=: DP&$: : (4 : 0) " 0 > assert. 0<:y > %/ <....@%: (2 x: (2*x) round y)*10x^2*x+0>.>.10^.y > ) > > round=: DP&$: : (4 : 0) > b %~ <.1r2+y*b=. 10x^x > ) > > T=. 10000000000000306999999999997669x > sqrt T > 6324555320336855745921954256628698742902673933907667687147821604985701262525202059973r2000000000000000000000000000000000000000000000000000000000000000000000 > > NB. Oh, you want it as a _decimal_ fraction? > > > x:6324555320336855745921954256628698742902673933907667687147821604985701262525202059973%2 > 3162277660168427874729612940583299986722926510279479157298130884847194278152739225600 > NB. Decimal ^ point > before this digit (between "427" and "874") > > NB. But this isn't quite right either (starting a > few places after the > decimal > NB. point.) It's actually surprising that > it's correct as far as it > goes. > NB. And this isn't helpful: > > 6324555320336855745921954256628698742902673933907667687147821604985701262525202059973x%2x > 6324555320336855745921954256628698742902673933907667687147821604985701262525202059973r2 > > NB. This almost does it but loses some internal zeros: > -:".&>(3 : 'y<;.1~1,}:(<"0 ''02468'') e.~ > <"0 y') > '6324555320336855745921954256628698742902673933907667687147821604985701262525202059973' > 3 16 2 27766 0 168 4 2787 296 977 1 28 3 1 4 3 49 37 1 45 1 3 > 3696695 38 3 > 38 4 357 39 1 8 0 2 49 285 6 3 1 26 26 0 1 0 29986.5 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
