Continued fraction: Difference between revisions

m
→‎{{header|REXX}}: corrected misspelling (wrong word) and expanded precision & # of terms, made output easier to eyeball. -- ~~~~
m (→‎{{header|REXX}}: deleted a blank line, expanded ''output'' a wee bit. -- ~~~~)
m (→‎{{header|REXX}}: corrected misspelling (wrong word) and expanded precision & # of terms, made output easier to eyeball. -- ~~~~)
Line 514:
<br>any form of REXX numbers (negative, exponentiated, decimal fractions) can be used.
<br><br>There isn't any realistic limit on the precision that can be used, although 100,000 digits would be a bit unwieldly to display.
<lang rexx>/*REXX program tocalculates calculate& displays values of some continedcontinued fractions. */
numeric digits 100 /*use a hundred digits for show & tell*/
 
numeric terms=digits 60()*10 /*let's use sixty digits for... and an even thousand terms. show&tell*/
terms=100 /* ... and an even one hundred terms. */
/*──────────────────────────────────────────────────────────────────────*/
a=copies(' 2',terms); call tell 'sqrt(2)',$cf(1 a)
Line 546 ⟶ 545:
a=a 4*j+2
end; call tell 'coth(½)',$cf(2 a)
/*also: [e+1] /÷ [e-1] */
exit
/*────────────────────────────────$CF subroutine────────────────────────*/
$cf: procedure; parse arg c x,y; !=0; numeric digits digits()*2
do j=words(x) to 1 by -1
a=word(x,j); b=word(y,j); if b=='' then b=1
d=a+!; if d=0 then call divzero /*just in case divisor is bogus.*/
!=b/d
end
return !+c
/*────────────────────────────────other subroutines─────────────────────*/
 
divzero: say; say '***error!***'; say 'division by zero.'; say; exit 13
tell:parse arg _,v;say right(_,8) '=' format(v) ' "a" terms='left(a,4050);a=;b=;return</lang>
</lang>
'''output'''
<pre style="height:30ex;overflow:scroll">
sqrt(2) = 1.41421356237309504880168872420969807856967187537694807317668414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641573 "a" terms= 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
e = 2.71828182845904523536028747135266249775724709369995957496697718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427 "a" terms= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2
pi = 3.14159241097198067426258886021672643729365090674537669567319141592653340542051900128736253203567152539255317954874674304859504426172618558702218695071137605739 "a" terms= 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
phi = 1.61803398874989484820458683436563811772030781841853559947667618033988749894848204586834365638117720309179805762862135448622705260462818902449707207204189391137 "a" terms= 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
sqrt(3) = 1.73205080756887729352744634150587236694280525381038062805521732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248576 "a" terms= 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1
tan(1) = 1.55740772465490223050697480745836017308725077238152003838395557407724654902230506974807458360173087250772381520038383946605698861397151727289555099965202242984 "a" terms= 1 1 3 1 5 1 7 1 9 1 11 1 13 1 15 1 17 1 19 1 21 1
coth(1) = 1.31303528549933130363616124693084783291201394124045265554315313035285499331303636161246930847832912013941240452655543152967567084270461874382674679241480856303 "a" terms= 3 5 7 9 11 13 15 17 19 21 23 25 27 29 331 33 35 37
coth(½) = 2.16395341373865284877000401021802311709373860215079227253357163953413738652848770004010218023117093738602150792272533574119296087634783339486574409418809750115 "a" terms= 6 10 14 18 22 26 30 34 38 42 46 50 54 558 62 66 70
</pre>