Anonymous user
Continued fraction/Arithmetic/Construct from rational number: Difference between revisions
Continued fraction/Arithmetic/Construct from rational number (view source)
Revision as of 21:31, 28 August 2015
, 8 years ago→{{header|REXX}}: changed extra digits and optimized the sqrt function, added a comment.
(→{{header|XPL0}}: Added zkl) |
m (→{{header|REXX}}: changed extra digits and optimized the sqrt function, added a comment.) |
||
Line 722:
=={{header|REXX}}==
Programming notes:
* Increase <code>numeric digits</code> to a higher value to generate more terms.
* Two subroutines, <code>sqrt</code> & <code>pi</code>, were included here to demonstrate terms for
* The subroutine <code>$maxfact</code> was included and is only needed if the number used for <code>r2cf</code> is a decimal fraction.
* Checks were included to verify that the arguments being passed to <code>r2cf</code> are indeed numeric and also not zero.
* This version also handles negative numbers.
<lang rexx>/*REXX pgm converts decimal or rational fraction to a continued fraction*/
numeric digits 230 /*this determines how many terms */
Line 778:
serr: say; say '***error!***'; say; say arg(1); say; exit
/*─────────────────────────────SQRT subroutine──────────────────────────*/
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits();
do j=0 while h>9; m.j=h; h=h%2+1; end /*j*/
numeric digits d; return g/1▼
do k=j+5 to 0 by -1; numeric digits m.k; g=(g+x/g)*.5; end /*k*/
▲ numeric digits d; return (g/1)i /*make complex if X < 0.*/
/*─────────────────────────────MAXFACT subroutine───────────────────────*/
$maxFact: procedure; parse arg x 1 _x,y; y=10**(digits()-1); b=0; h=1
|