Anonymous user
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
numeric digits 100 /*use a hundred digits for show & tell*/
/*──────────────────────────────────────────────────────────────────────*/
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]
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,
</lang>
'''output'''
<pre style="height:30ex;overflow:scroll">
sqrt(2) = 1.
e = 2.
pi = 3.
phi = 1.
sqrt(3) = 1.
tan(1) = 1.
coth(1) = 1.
coth(½) = 2.
</pre>
|