void subtract(float subTo[], float subFrom[]) { int i, j; for(i = 0; i <= maxDegree; ++i) { subTo[i] -= subFrom[i]; } clearZeroes(subTo); }
void add(float addTo[], float addFrom[]) { int i; for (i = 0; i <= maxDegree; ++i) { addTo[i] += addFrom[i]; } clearZeroes(addTo); }
clearZeroesMat(float A[][M][maxDegree]) { int m, n; for(n = 0; n < N; ++n) { for(m = 0; m < M; ++m) { clearZeroes(A[n][m]); } } }
// sets q equal to the polynomial s.t. a = bq + r void eucDiv(float a[], float b[], float q[]) { if (equalsZero(a) == 1) { printf("You are calling eucDiv with a equal to the zero vector\n"); return; } if (equalsZero(b) == 1) { printf("You are calling a division by 0\n"); return; } clearZeroes(a); clearZeroes(b); int i; int degA = degree(a); int degB = degree(b); int d = degA - degB; if (d < 0) { printf("This is a nonsensical call of eucDiv\n"); return; } float tempQ; setZero(q); // creates tempA as a clone of a float tempA[maxDegree+1]; setEquals(tempA, a); float tempB[maxDegree+1]; setEquals(tempB, b); // algorithm for euclidean division of polynomials for (i = d; i >= 0; --i) { tempQ = tempA[degA + i - d] / tempB[degB]; q[i] = tempQ; // runs iff |tempQ| < 0.001 if (isAboutZero(tempQ) == 0) { scale(tempB, tempQ); polyTimesXn(tempB, i); subtract(tempA, tempB); polyTimesXn(tempB, -i); scale(tempB, 1.0/tempQ); } } }
int equalsZero(float poly[]) { int ret = 1; int i; clearZeroes(poly); for (i = 0; i <= maxDegree; ++i) { if (poly[i] != 0) { ret = 0; break; } } return ret; }
void rowOperations2(float A[][M][maxDegree+1], float P[][N][maxDegree+1], float Pinv[][N][maxDegree+1], int n, int tempN, float q[]) { type2rowM(A, n, tempN, q, 1); type2rowN(P, n, tempN, q, 1); type2rowN(Pinv, tempN, n, q, 0); int i, j; for(i = 0; i < N; ++i) { for(j = 0; j < M; ++j) { clearZeroes(A[i][j]); } } }
// multiplies 2 polynomials, overwriting their product as the first argument // this assumes that deg(a*b) <= maxDegree void multiply(float a[], float b[], float c[]) { int i, j; setZero(c); int degA = degree(a); int degB = degree(b); int d = degA + degB; for (i = d; i >= 0; --i) { for (j = i; j >= 0; --j) { c[i] += a[j] * b[i-j]; } } clearZeroes(c); }
void columnOperations2(float A[][M][maxDegree+1], float Q[][M][maxDegree+1], float Qinv[][M][maxDegree+1], int m, int tempM, float q[]) { type2col(A, N, m, tempM, q, 1); type2col(Q, M, m, tempM, q, 1); type2col(Qinv, M, tempM, m, q, 0); // to handle the floating point errors int i, j; for(i = 0; i < N; ++i) { for(j = 0; j < M; ++j) { clearZeroes(A[i][j]); } } }
void subtract(float subTo[], float subFrom[]) { int i, j; for(i = 0; i <= maxDegree; ++i) { subTo[i] -= subFrom[i]; } clearZeroes(subTo); // printf("tempA: "); // printPoly(subTo); // printf("b scaled: "); // printPoly(subFrom); }
// multiplies 2 polynomials, overwriting their product as the first argument // this assumes that deg(a*b) <= maxDegree void multiply(float a[], float b[], float c[]) { int i, j; setZero(c); // int degA = degree(a); // int degB = degree(b); // int d = degA + degB; for (i = maxDegree; i >= 0; --i) { for (j = i; j >= 0; --j) { c[i] += a[j] * b[i-j]; //printf("j = %i, i = %i, a[j] = %f, b[i-j] = %f\n", j, i, a[j], b[i-j]); } } clearZeroes(c); }
int dividesPoly(float a[], float b[]) { int i; // creates tempA as a clone of a float tempA[maxDegree+1]; setEquals(tempA, a); float tempB[maxDegree+1]; setEquals(tempB, b); float q[maxDegree+1]; setZero(q); int degA = degree(a); int degB = degree(b); int d = degA - degB; float tempQ; // algorithm for euclidean division for (i = d; i >= 0; --i) { tempQ = tempA[degA + i - d] / tempB[degB]; q[i] = tempQ; if (tempQ != 0) { scale(tempB, tempQ); polyTimesXn(tempB, i); subtract(tempA, tempB); polyTimesXn(tempB, -i); scale(tempB, 1.0/tempQ); } } multiply(b, q, tempA); subtract(tempA, a); clearZeroes(tempA); if(equalsZero(tempA) == 1) { return 1; } else { return 0; } }
void ChartEditorWindow::showChartTable(){ QVectorIterator<LayerVisualInfo*> lviIt(lvi); QTableWidgetItem* tableItem; int row=0, col=0; m_ui->tableWidget->setRowCount(lvi.count()); m_ui->tableWidget->clearContents(); while(lviIt.hasNext()){ col = 0; LayerVisualInfo* tmpLVI = lviIt.next(); tableItem = new QTableWidgetItem(tmpLVI->getLayerId()); m_ui->tableWidget->setItem(row, col++, tableItem); tableItem = new QTableWidgetItem(QString::number(tmpLVI->getZoomMin())); m_ui->tableWidget->setItem(row, col++, tableItem); tableItem = new QTableWidgetItem(QString::number(tmpLVI->getZoomMax())); m_ui->tableWidget->setItem(row, col++, tableItem); tableItem = new QTableWidgetItem(QString::number(tmpLVI->getStyleId())); m_ui->tableWidget->setItem(row, col++, tableItem); tableItem = new QTableWidgetItem(QString::number(tmpLVI->getSimpLevel())); m_ui->tableWidget->setItem(row, col++, tableItem); tableItem = new QTableWidgetItem(clearZeroes(QString::number(tmpLVI->getEpsilon(), 'f'))); m_ui->tableWidget->setItem(row, col++, tableItem); tableItem = new QTableWidgetItem(tmpLVI->getSrcTableName()); m_ui->tableWidget->setItem(row, col++, tableItem); row++; } }