Не понимаю почему выхожу за массив.
public void Div_Polynomials(double[] pol1, double[] pol2, CancellationToken cancelToken) //деление полинмов
{
double[] quotient = { }; // делимое
double[] mod = { }; // остаток от деления
int size_quotient = pol1.Length - pol2.Length;
int size_mod = pol2.Length - 1;
//pol1.Length - n
//pol2.Length - m
Array.Resize(ref quotient, size_quotient);
Array.Resize(ref mod, size_mod);
size_quotient = size_quotient + 1;
size_mod = size_mod + 1; //может быть непраивльно
/*
void division(int* arr1, int n, int* arr2, int m, int* result, int&nm) {
for (int k = (n - m); k >= 0; k--)
{
result[k] = arr1[k + m] / arr2[m];
for (int j = k + m - 1; j >= k; j--)
arr1[j] -= arr2[j - k] * result[k];
}
}
*/
for (int k = size_quotient-1; k >= 0 && !cancelToken.IsCancellationRequested; k--) //+
{ //первый многочлен
quotient[k] = pol1[pol2.Length - 1 + k] / pol2[pol2.Length - 1]; // коэфи
for (int j = pol2.Length + k - 1; j >= k; j--)
{ //второй многчлен
pol1[j] = pol1[j] - quotient[k] * pol2[j - k];
}
}
int g = 0;
for (int i = 0; i < size_mod - 1; i++)
{ //остаток
mod[i] = pol1[i];
g++;
}
result_polynomial = quotient;
result_quotient = quotient;
result_mod = mod;
}
pol1[pol2.Length - 1 + k]=>pol1[pol2.Length - 1 - k]? – tym32167 Dec 14 '22 at 17:23