Continued fraction: Difference between revisions

m
→‎{{header|J}}: Use different decimalization function and print more decimals
(→‎{{header|J}}: Use a decimalize function)
m (→‎{{header|J}}: Use different decimalization function and print more decimals)
Line 276:
e=: cfrac 2 1, , ,~"0 >:i.100x
 
NB. translate from fraction to decimal string
decimalize=: 4 : 0"0 NB. decimalize translated from python
NB. translated from factor
'q y' =. y (<.@% , |~) 1
dec =: (-@:[ (}.,'.',{.) ":@:<.@:(* 10x&^)~)"0
res=. ":q
res=. res,'.'
for. i.x do.
y=. 10*y
'q y'=. y (<.@% , |~) 1
res=. res,":q
end.
)
 
30100 10 30100 decimalizedec sqrt2, pi, e
1.4142135623730950488016887242096980785696718753769480731766797379907324784621205551109457595775322165
1.414213562373095048801688724209
3.1415924109
2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274
2.718281828459045235360287471352
</lang>
 
Anonymous user