Continued fraction/Arithmetic/Construct from rational number: Difference between revisions

→‎{{header|ALGOL 68}}: Let's use the Algol 68 MOD operator after all
(→‎{{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>
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.
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 *MOD denominator );
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 -1 -2425 -1 -2
 
Running for root2 :
3,045

edits