private static void CheckIsNull(Polynominal p1, Polynominal p2) { if (p1 is null || p2 is null) { throw new NullReferenceException(); } }
private static Polynominal SubtractArrayValues(Polynominal p1, Polynominal p2) { Polynominal result = new Polynominal((int[])p1.Value.Clone()); for (int i = 0; i <= p2.Power; i++) { result[i] -= p2[i]; } return(result); }
public static Polynominal MultiplyPolynominals(Polynominal p1, Polynominal p2) { CheckIsNull(p1, p2); int[] resultCoefs = new int[p1.Power + p2.Power + 1]; for (int i = 0; i <= p2.Power; i++) { for (int j = i; j <= p1.Power + i; j++) { resultCoefs[j] += p1[j - i] * p2[i]; } } return(new Polynominal(resultCoefs)); }
public static Polynominal SubtractPolynominals(Polynominal p1, Polynominal p2) { CheckIsNull(p1, p2); return((p1.Power >= p2.Power) ? SubtractArrayValues(p1, p2) : SubtractArrayValues(p2, p1)); }