Beispiel #1
0
def EffectueSommeFractions(fr1, fr2, s, pre, post):
    if s == "+":
        fr = fr1 + fr2
    else:
        fr = fr1 - fr2
    cor = []
    if fr1.n and fr2.n:
        ppcm = Arithmetique.ppcm(fr2.d, fr1.d)
        if abs(fr1.d) - abs(fr2.d):
            cor.append("%s%s%s%s%s" % (pre, Fractions.TeX(fr1, True,
                       coef=ppcm // abs(fr1.d)), s, Fractions.TeX(fr2,
                       True, coef=ppcm // abs(fr2.d)), post))
        if pre.rstrip().endswith('(') and post.lstrip().startswith(')'):
            pre = pre.rstrip()[:len(pre.rstrip()) - 1]
            post = post.lstrip()[1:]
        cor.append("%s%s%s" % (pre, Fractions.TeX(fr, True), post))
        if fr.n:
            frs = Fractions.simplifie(fr)
            if abs(frs.n) != abs(fr.n):
                cor.append("%s%s%s" % (pre, Fractions.TeX(frs, True,
                           coef=fr.d // frs.d), post))
                cor.append("%s%s%s" % (pre, Fractions.TeX(frs, True),
                           post))
    else:
        cor.append("%s%s%s" % (pre, Fractions.TeX(fr, True), post))
    return cor
Beispiel #2
0
 def __add__(self, fraction):
     if (isinstance(fraction,int) or isinstance(fraction,float)):
         fraction=Fractions(fraction)
     if isinstance(fraction,Fractions):
         ppcm = Arithmetique.ppcm(self.d, fraction.d)
         return Fractions((self.n * ppcm) // self.d + (fraction.n * ppcm) //
                      fraction.d, ppcm)
     else:
         return fraction+self