#! /usr/bin/env python # -*- coding: utf-8 -*- # vim:fenc=utf-8 # # Copyright © 2017 lafrite # # Distributed under terms of the MIT license. from mapytex.calculus.core.tree import Tree from .mo import MO, MOError __all__ = ["MOFraction"] class MOFraction(MO): """ Fraction math object""" def __init__(self, numerator, denominator, negative=False): """ Initiate the MOFraction It can't be indempotent. :param numerator: Numerator of the Fraction :param denominator: Denominator of the Fraction :param negative: Is the fraction negative (not concidering sign of numerator or denominator. >>> f = MOFraction(2, 3) >>> f >>> f = MOFraction(2, 3, negative = True) >>> f """ base_value = Tree("/", MO.factory(numerator), MO.factory(denominator), ) if negative: value = Tree("-", None, base_value) else: value = base_value MO.__init__(self, value) self._numerator = numerator self._denominator = denominator self.negative = negative # ----------------------------- # Reglages pour 'vim' # vim:set autoindent expandtab tabstop=4 shiftwidth=4: # cursor: 16 del