public static RationalPolinomDiv Divide(this RationalPolinom polinom, RationalPolinom divider) { var power = polinom.Power - divider.Power; var result = new RationalPolinom(); var reminder = polinom; (power + 1).ForEachNum(i => { if (reminder.Power + i == polinom.Power) { var c = reminder.Root / divider.Root; var subRationalPolinom = (c * divider).PowerShiftUp(power - i); reminder = reminder - subRationalPolinom; result.PowerUp(c); } else { result.PowerUp(0); } }); return(new RationalPolinomDiv() { Result = result, Remainder = reminder }); }
public void RationalPolinomDivTest() { var a = new RationalPolinom(1, (1, 2), 5, 7, 0, 0, 3, 5); log.Debug($"a = {a}"); var b = new RationalPolinom(1, 2); log.Debug($"b = {b}"); var c = a / b; log.Debug($"a / b = {c}"); var cR = a % b; log.Debug($"a % b = {cR}"); var aa = c * b + cR; log.Debug($"a = c*b + a%b = {aa}"); Assert.AreEqual(a, aa, "Incorrect"); }