Continued fraction/Arithmetic/Construct from rational number: Difference between revisions
Content added Content deleted
(→{{header|REXX}}: added the REXX language. -- ~~~~) |
(→{{header|REXX}}: aligned the output. -- ~~~~) |
||
Line 203: | Line 203: | ||
Programming notes: |
Programming notes: |
||
<br><br>The '''numeric digits''' can be increased to a higher value to generate more terms. |
<br><br>The '''numeric digits''' can be increased to a higher value to generate more terms. |
||
<br>Two subroutines '''sqrt''' & '''pi''' were included here to demonstrate terms for √2 and π. |
<br>Two subroutines '''sqrt''' & '''pi''' were included here to demonstrate terms for √2 and π. |
||
<br>The subroutine '''$maxfact''' was included and is only needed if the number used for '''r2cf''' is a decimal fraction. |
<br>The subroutine '''$maxfact''' was included and is only needed if the number used for '''r2cf''' is a decimal fraction. |
||
<br>Checks were included to verify that the arguments being passed to '''r2cf''' are indeed numeric and also not zero. |
<br>Checks were included to verify that the arguments being passed to '''r2cf''' are indeed numeric and also not zero. |
||
Line 210: | Line 210: | ||
numeric digits 230 /*this determines how many terms */ |
numeric digits 230 /*this determines how many terms */ |
||
/*can be generated for dec fracts*/ |
/*can be generated for dec fracts*/ |
||
say ' 1/2 ──► CF: ' r2cf( '1/2' ) |
say ' 1/2 ──► CF: ' r2cf( '1/2' ) |
||
say ' 3 ──► CF: ' r2cf( 3 ) |
say ' 3 ──► CF: ' r2cf( 3 ) |
||
say '23/8 ──► CF: ' r2cf( '23/8' ) |
say ' 23/8 ──► CF: ' r2cf( '23/8' ) |
||
say '13/11 ──► CF: ' r2cf( '13/11' ) |
say ' 13/11 ──► CF: ' r2cf( '13/11' ) |
||
say '22/7 ──► CF: ' r2cf( '22/7 ' ) |
say ' 22/7 ──► CF: ' r2cf( '22/7 ' ) |
||
say |
say |
||
say '───────── attempts at √2.' |
say '───────── attempts at √2.' |
||
Line 238: | Line 238: | ||
g = $maxfact(g) |
g = $maxfact(g) |
||
end |
end |
||
⚫ | |||
⚫ | |||
parse var g n '/' d |
parse var g n '/' d |
||
if \datatype(n,'W') then call serr "a numerator isn't an integer:" n |
if \datatype(n,'W') then call serr "a numerator isn't an integer:" n |
||
Line 274: | Line 273: | ||
'''output''' |
'''output''' |
||
<pre style="overflow:scroll"> |
<pre style="overflow:scroll"> |
||
1/2 ──► CF: 0 2 |
|||
3 ──► CF: 3 |
3 ──► CF: 3 |
||
23/8 ──► CF: 2 1 7 |
23/8 ──► CF: 2 1 7 |
||
13/11 ──► CF: 1 5 2 |
13/11 ──► CF: 1 5 2 |
||
22/7 ──► CF: 3 7 |
22/7 ──► CF: 3 7 |
||
───────── attempts at √2. |
───────── attempts at √2. |