Continued fraction/Arithmetic/Construct from rational number: Difference between revisions
Continued fraction/Arithmetic/Construct from rational number (view source)
Revision as of 17:19, 12 June 2022
, 2 years ago→{{header|ALGOL 68}}: Let's use the Algol 68 MOD operator after all
m (→{{header|ALGOL 68}}: Typo) |
(→{{header|ALGOL 68}}: Let's use the Algol 68 MOD operator after all) |
||
Line 71:
{{Trans|C}}
...with code from the Arithmetic/Rational task.<br>
The continued fraction expansion of -151/77 is sensitive to whether the language modulo operator follows the mathematical definition or the C definition.<br>
Algol 68's MOD operator uses the mathematical definition (rounds towards -infinity), so the results for -157//77 agree with the EDSAC, J and a few other sdamples. Most other samples calculate the remainder using the C definotion.
<lang algol68>BEGIN # construct continued fraction representations of rational numbers #
# Translated from the C sample #
Line 131 ⟶ 132:
INT prev numerator = numerator;
numerator := denominator;
denominator := prev numerator
quotient
FI # r2cf # ;
Line 163 ⟶ 164:
For N = 13, D = 11 : 1 5 2
For N = 22, D = 7 : 3 7
For N = -151, D = 77 : -1
Running for root2 :
|