Ejemplo n.º 1
0
 def on_btn_q_div_released(self):
     try:
         q1 = self.get_q_q(1)
         q2 = self.get_q_q(2)
         result = rational.DIV_QQ_Q(q1, q2)
         self.add_history_record('%s / %s = %s' % (
             pretty.rational(q1),
             pretty.rational(q2),
             pretty.rational(result),
             ))
     except Exception as e:
         self.on_exception(e)
Ejemplo n.º 2
0
 def test_zero(self):
     number = [
         [0, 2, [5, 3]],
         [1, [2]],
     ]
     zero = [
         [0, 1, [0]],
         [1, [1]],
     ]
     expect = zero
     result = rational.DIV_QQ_Q(zero, number)
     self.assertEqual(result, expect)
Ejemplo n.º 3
0
 def test_negative_both(self):
     number1 = [
         [1, 1, [5]],
         [1, [3]],
     ]
     number2 = [
         [1, 1, [2]],
         [1, [7]],
     ]
     expect = [
         [0, 2, [5, 3]],
         [1, [6]],
     ]
     result = rational.DIV_QQ_Q(number1, number2)
     self.assertEqual(result, expect)
def open_window_rat_quot():
    layout = [[sg.Text('Enter two rationals')], [sg.Input(key='dig1')],
              [sg.Button('/', key='start')], [sg.Input(key='dig2')],
              [sg.Text(size=(400, 10), key='out')]]
    window = sg.Window('The quotient of rational numbers',
                       layout,
                       size=(460, 260),
                       resizable=True)
    while True:
        event, values = window.read()
        if event == "start":
            window['out'].update(
                RatToStr(
                    rat.TRANS_Q_Z(
                        rat.DIV_QQ_Q(StrToRat(values['dig1']),
                                     StrToRat(values['dig2'])))))
        if event == sg.WINDOW_CLOSED:
            break
Ejemplo n.º 5
0
def DIV_PP_P(coefficient1, power1, coefficient2, power2):
    # Деление многочленов
    # Аносов Павел
    new_power = []
    new_coefficient = []
    try:
        while integer.SUB_ZZ_Z(power1[0], power2[0]) != ['-', 1] and power1:
            new_power.append(nat.SUB_NN_N(power1[0], power2[0]))
            new_coefficient.append(
                rat.DIV_QQ_Q(coefficient1[0], coefficient2[0]))
            coef, pow = MUL_PP_P(coefficient2, power2, [new_coefficient[-1]],
                                 [new_power[-1]])
            coefficient1, power1 = SUB_PP_P(coefficient1, power1, coef, pow)

            del coefficient1[0]
            del power1[0]
    except:
        pass
    return new_coefficient, new_power