예제 #1
0
Rational Rational::DIV_QQ_Q(const Rational &a, const Rational &c) {
	if (a.Z.getSign() != c.Z.getSign()) {
		Rational result(BigInt::MUL_ZM_Z(BigInt::MUL_ZZ_Z(a.Z, BigInt::TRANS_N_Z(c.N))), Natural::MUL_NN_N(a.N, BigInt::TRANS_Z_N(c.Z)));
		return RED_Q_Q(result);
	}
	Rational result(BigInt::MUL_ZZ_Z(a.Z, BigInt::TRANS_N_Z(c.N)), Natural::MUL_NN_N(a.N, BigInt::TRANS_Z_N(c.Z)));
	return RED_Q_Q(result);
};
예제 #2
0
Rational Rational::SUB_QQ_Q(const Rational &q1, const Rational &q2) {
	Rational sub;
	sub.N = Natural::LCM_NN_N(q1.N, q2.N);

	Rational q3;
	q3.Z = BigInt::TRANS_N_Z(sub.N);
	q3.N = q1.N;

	Rational q4;
	q4.Z = BigInt::TRANS_N_Z(sub.N);
	q4.N = q2.N;

	sub.Z = BigInt::SUB_ZZ_Z(BigInt::MUL_ZZ_Z(q1.Z, TRANS_Q_Z(RED_Q_Q(q3))), BigInt::MUL_ZZ_Z(q2.Z, TRANS_Q_Z(RED_Q_Q(q4))));
	return RED_Q_Q(sub);
};
예제 #3
0
Rational Rational::ADD_QQ_Q(const Rational &q1, const Rational &q2) {
	Rational add;
	add.N = Natural::LCM_NN_N(q1.N, q2.N);

	Rational q3;
	q3.Z = BigInt::TRANS_N_Z(add.N);
	q3.N = q1.N;

	Rational q4;
	q4.Z = BigInt::TRANS_N_Z(add.N);
	q4.N = q2.N;

	add.Z = BigInt::ADD_ZZ_Z(BigInt::MUL_ZZ_Z(q1.Z, TRANS_Q_Z(RED_Q_Q(q3))), BigInt::MUL_ZZ_Z(q2.Z, TRANS_Q_Z(RED_Q_Q(q4))));
	return RED_Q_Q(add);
};
예제 #4
0
fraction MUL_QQ_Q(const fraction& Num1, const fraction& Num2) {  // умножение дробей
    fraction Num3;
    Num3.numerator = MUL_ZZ_Z(Num1.numerator, Num2.numerator);
    // перемножение числителей первой и второй дробей
    Num3.denominator = MUL_NN_N(Num1.denominator, Num2.denominator);
    // перемножение знаменателей первой и второй дробей
    Num3 = RED_Q_Q(Num3);  // упрощение полученной дроби
    return (Num3);
}
예제 #5
0
Rational Rational::MUL_QQ_Q(const Rational &q1, const Rational &q2) {
	Rational result(BigInt::MUL_ZZ_Z(q1.Z, q2.Z), Natural::MUL_NN_N(q1.N, q2.N));
	return RED_Q_Q(result);
};