M2000 Interpreter rational numbers: Difference between revisions

m
(Created page with "=={{header|M2000 Interpreter}}== <lang M2000 Interpreter> Module RationalNumbers { Class Rational { numerator as decimal, denominator as decimal...")
 
 
Line 1:
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module RationalNumbers {
Class Rational {
Line 119:
class:
Module Rational (.numerator, .denominator) {
if .denominator<=0 then Error "Positive onlyZero denominator"
sgn=Sgn(.numerator)*Sgn(.denominator)
.denominator<=abs(.denominator)
.numerator<=abs(.numerator)*sgn
gcd1=lambda (a as decimal, b as decimal) -> {
if a<b then swap a,b
Line 126 ⟶ 129:
a=b:b=g: g=a mod b
}
=abs(b)
}
gdcval=gcd1(abs(.numerator), .denominator)
if gdcval<.denominator and gdcval<>0 then
.denominator/=gdcval
.numerator/=gdcval
end if
.gcd<=gcd1
.lcm<=lambda gcd=gcd1 (a as decimal, b as decimal) -> {
Line 174 ⟶ 182:
}
RationalNumbers
</syntaxhighlight>
</lang>
404

edits