|
|
@ -16,13 +16,13 @@ def reduceFraction(num, denom): |
|
|
|
def addFractions(num1, denom1, num2, denom2): |
|
|
|
if denom1 != denom2: |
|
|
|
fractionExpansionFactor = lcm(denom1, denom2) |
|
|
|
frac1Offset = fractionExpansionFactor / denom1 |
|
|
|
frac2Offset = fractionExpansionFactor /denom2 |
|
|
|
num1 *= frac1Offset |
|
|
|
denom1 *= frac1Offset |
|
|
|
num2 *= frac2Offset |
|
|
|
denom2 *= frac2Offset |
|
|
|
result_num = num1 + num2 |
|
|
|
frac1Offset = divide(fractionExpansionFactor, denom1) |
|
|
|
frac2Offset = divide(fractionExpansionFactor, denom2) |
|
|
|
num1 = multiply(num1, frac1Offset) |
|
|
|
denom1 = multiply(denom1, frac1Offset) |
|
|
|
num2 = multiply(num2, frac2Offset) |
|
|
|
denom2 = multiply(denom2, frac2Offset) |
|
|
|
result_num = add(num1, num2) |
|
|
|
return reduceFraction(result_num, denom1) |
|
|
|
|
|
|
|
def multiplyFractions(num1, denom1, num2, denom2): |
|
|
|