const PaperSize* getPaperSize(const qreal wi, const qreal hi) { if (wi < minSize || hi < minSize) return &paperSizes[0]; for (int i = 0; paperSizes[i].name; ++i) { if (sizeError(wi, paperSizes[i].w) < maxError && sizeError(hi, paperSizes[i].h) < maxError) return &paperSizes[i]; if (sizeError(wi, paperSizes[i].h) < maxError && sizeError(hi, paperSizes[i].w) < maxError) return &paperSizes[i]; } qDebug("unknown paper size for %f x %f", wi, hi); //return custom return &paperSizes[0]; }
void CheckStl::size() { if (!_settings->_checkCodingStyle || !_settings->inconclusive) return; for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { if (Token::Match(tok, "%var% . size ( )")) { if (Token::Match(tok->tokAt(5), "==|!=|> 0")) { if (isStlContainer(tok)) sizeError(tok); } else if ((tok->tokAt(5)->str() == ")" || tok->tokAt(5)->str() == "&&" || tok->tokAt(5)->str() == "||" || tok->tokAt(5)->str() == "!") && (tok->tokAt(-1)->str() == "(" || tok->tokAt(-1)->str() == "&&" || tok->tokAt(-1)->str() == "||" || tok->tokAt(-1)->str() == "!")) { if (tok->tokAt(-1)->str() == "(" && tok->tokAt(5)->str() == ")") { // check for passing size to function call if (Token::Match(tok->tokAt(-2), "if|while")) { if (isStlContainer(tok)) sizeError(tok); } } else if (isStlContainer(tok)) sizeError(tok); } } } }
int main() { /* Add your implementation here */ int i; int j; int size; int colNum; int rowNum; char * pointless; double ** mat; char * input = getInput(); if(strIsNum(input)){ size = strtod(input, &pointless);//strToNum(input); } else sizeError(); rowNum = size; colNum = size + 1; //Create matrix array mat = malloc(sizeof(double *) * rowNum); for(i = 0; i < size; i++){ mat[i] = malloc(sizeof(double) * colNum); for(j = 0; j < colNum; j++){ input = getInput(); if((strlen(input) == 0)||!strIsNum(input)) printMissingEl(i, j ); else mat[i][j] = strtod(input, &pointless); } } printf("initial matrix\n"); printMatrix(rowNum, colNum, mat); for(i = 0; i < rowNum; i++){ int maxPos = i; //find the maximum value of abs(r[j][i]) where j >= i for(j = i + 1; j < rowNum; j++){ if(fabs(mat[j][i]) > fabs(mat[maxPos][i])){ maxPos = j; } } // this makes the pivot nonzero if possible int isSingular = 1; for(j = 0; j < rowNum; j++){ if(mat[i][j] != 0){ isSingular = 0; break; } } if(isSingular){ printf("Error: Matrix is singular\n"); exit(0); } printf("swapped %d and %d\n", i, maxPos); swapRows(maxPos, i, mat); printMatrix(rowNum, colNum, mat); printf("row %d /= %f\n", i, mat[i][i]); divideRow(i, colNum, mat); printMatrix(rowNum, colNum, mat); for(j = 0; j < rowNum; j++){ if(i != j){ printf("row %d -= %f row %d\n", j, mat[j][i], i); makeZero(j, i, colNum, mat); printMatrix(rowNum, colNum, mat); } } } for(i = 0; i < rowNum; i++){ printf("%f ",mat[i][size]); } printf("\n"); return 0; }