|
@ -1,4 +1,4 @@ |
|
|
from src.main.py.more_advanced_calculations import gcd |
|
|
|
|
|
|
|
|
from src.main.py.more_advanced_calculations import gcd, lcm |
|
|
|
|
|
|
|
|
def frac_to_dec(num, denom): |
|
|
def frac_to_dec(num, denom): |
|
|
return num/denom |
|
|
return num/denom |
|
@ -10,5 +10,13 @@ def reduceFraction(num, denom): |
|
|
return (num, denom) |
|
|
return (num, denom) |
|
|
|
|
|
|
|
|
def addFractions(num1, denom1, num2, denom2): |
|
|
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 |
|
|
result_num = num1 + num2 |
|
|
return (result_num, denom1) |
|
|
return (result_num, denom1) |