Continued fraction/Arithmetic/Construct from rational number: Difference between revisions
Continued fraction/Arithmetic/Construct from rational number (view source)
Revision as of 13:32, 12 June 2022
, 2 years ago→{{header|ALGOL 68}}: Fix negative numbers
(Added Algol 68) |
(→{{header|ALGOL 68}}: Fix negative numbers) |
||
Line 70:
=={{header|ALGOL 68}}==
{{Trans|C}}
...with code from the Arithmetic/Rational task.<br>
Note that Algol 68's MOD operator uses the mathematical definition (rounds towards -infinity) which differs from C and many other languages. The remainder is calculated here as it would be in C, so the results for -157//77 agree with the other samples.
<lang algol68>BEGIN # construct continued fraction representations of rational numbers #
# Translated from the C sample #
Line 130 ⟶ 131:
INT prev numerator = numerator;
numerator := denominator;
denominator := prev numerator
quotient
FI # r2cf # ;
Line 162 ⟶ 163:
For N = 13, D = 11 : 1 5 2
For N = 22, D = 7 : 3 7
For N = -151, D = 77 : -1
Running for root2 :
|