Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct compilation warnings for 'int' casts with correct types #75

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OndselSolver/GEFullMat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void GEFullMat::backSubstituteIntoDU()
{
answerX = std::make_shared<FullColumn<double>>(n);
answerX->at(n - 1) = rightHandSideB->at(m - 1) / matrixA->at(m - 1)->at(n - 1);
for (int i = (int)n - 2; i >= 0; i--) //Use int because of decrement
for (ssize_t i = (ssize_t)n - 2; i >= 0; i--) //Use ssize_t because of decrement
{
auto rowi = matrixA->at(i);
double sum = answerX->at(n) * rowi->at(n);
Expand Down
4 changes: 2 additions & 2 deletions OndselSolver/GESpMatFullPv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ void GESpMatFullPv::backSubstituteIntoDU()
auto jn = colOrder->at(n);
answerX->at(jn) = rightHandSideB->at(m) / matrixA->at(m)->at(jn);
//auto rhsZeroElement = this->rhsZeroElement();
for (int i = (int)n - 2; i >= 0; i--) //Use int because of decrement
for (ssize_t i = (ssize_t)n - 2; i >= 0; i--) //Use ssize_t because of decrement
{
auto& rowi = matrixA->at(i);
sum = 0.0; // rhsZeroElement copy.
for (auto const& keyValue : *rowi) {
auto jj = keyValue.first;
auto j = positionsOfOriginalCols->at(jj);
if ((int) j > i) {
if ((ssize_t) j > i) {
duij = keyValue.second;
sum += answerX->at(jj) * duij;
}
Expand Down
4 changes: 2 additions & 2 deletions OndselSolver/GESpMatParPv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ void GESpMatParPv::backSubstituteIntoDU()
answerX = std::make_shared<FullColumn<double>>(m);
answerX->at(n - 1) = rightHandSideB->at(m - 1) / matrixA->at(m - 1)->at(n - 1);
//auto rhsZeroElement = this->rhsZeroElement();
for (int i = (int)n - 2; i >= 0; i--) //Use int because of decrement
for (ssize_t i = (ssize_t)n - 2; i >= 0; i--) //Use ssize_t because of decrement
{
auto rowi = matrixA->at(i);
sum = 0.0; // rhsZeroElement copy.
for (auto const& keyValue : *rowi) {
auto j = keyValue.first;
if ((int)j > i) {
if ((ssize_t)j > i) {
duij = keyValue.second;
sum += answerX->at(j) * duij;
}
Expand Down
8 changes: 4 additions & 4 deletions OndselSolver/GESpMatParPvMarko.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ void GESpMatParPvMarko::doPivoting(size_t p)
//"Do scaling. Do partial pivoting."
//"criterion := mag / (2.0d raisedTo: rowiCount)."
//| lookForFirstNonZeroInPivotCol i rowi aip criterionMax rowPivoti criterion max |
int i; //Use int because of decrement
ssize_t i; //Use ssize_t because of decrement
size_t rowPivoti;
double aip, mag, max, criterion, criterionMax;
SpRowDsptr spRowi;
rowPositionsOfNonZerosInPivotColumn->clear();
auto lookForFirstNonZeroInPivotCol = true;
i = (int)m - 1;
i = (ssize_t)m - 1;
while (lookForFirstNonZeroInPivotCol) {
spRowi = matrixA->at(i);
if (spRowi->find(p) == spRowi->end()) {
if (i <= (int)p) throwSingularMatrixError(""); //Use int because i can be negative
if (i <= (ssize_t)p) throwSingularMatrixError(""); //Use ssize_t because i can be negative
}
else {
markowitzPivotColCount = 0;
Expand All @@ -44,7 +44,7 @@ void GESpMatParPvMarko::doPivoting(size_t p)
}
i--;
}
while (i >= (int)p) { //Use int because i can be negative
while (i >= (ssize_t)p) { //Use ssize_t because i can be negative
spRowi = matrixA->at(i);
if (spRowi->find(p) == spRowi->end()) {
aip = std::numeric_limits<double>::min();
Expand Down
8 changes: 4 additions & 4 deletions OndselSolver/GESpMatParPvMarkoFast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ void GESpMatParPvMarkoFast::doPivoting(size_t p)
//"Pivot size are nieither checked nor stored."

//| lookForFirstNonZeroInPivotCol i rowi aip criterionMax rowPivoti criterion max |
int i; //Use int because of decrement
ssize_t i; //Use ssize_t because of decrement
size_t rowPivoti;
double aip, max, criterion, criterionMax;
SpRowDsptr spRowi;
rowPositionsOfNonZerosInPivotColumn->clear();
auto lookForFirstNonZeroInPivotCol = true;
i = (int)m - 1;
i = (ssize_t)m - 1;
while (lookForFirstNonZeroInPivotCol) {
spRowi = matrixA->at(i);
if (spRowi->find(p) == spRowi->end()) {
if (i <= (int)p) throwSingularMatrixError(""); //Use int because i can be negative
if (i <= (ssize_t)p) throwSingularMatrixError(""); //Use ssize_t because i can be negative
}
else {
markowitzPivotColCount = 0;
Expand All @@ -74,7 +74,7 @@ void GESpMatParPvMarkoFast::doPivoting(size_t p)
}
i--;
}
while (i >= (int)p) { //Use int because i can be negative
while (i >= (ssize_t)p) { //Use ssize_t because i can be negative
spRowi = matrixA->at(i);
if (spRowi->find(p) == spRowi->end()) {
aip = std::numeric_limits<double>::min();
Expand Down
8 changes: 4 additions & 4 deletions OndselSolver/GESpMatParPvPrecise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ void GESpMatParPvPrecise::doPivoting(size_t p)
//"Check for singular pivot."
//"Do scaling. Do partial pivoting."
//| max rowPivot aip mag lookForFirstNonZeroInPivotCol i |
int i; //Use int because of decrement
ssize_t i; //Use ssize_t because of decrement
size_t rowPivoti;
double aip, mag, max;
SpRowDsptr spRowi;
rowPositionsOfNonZerosInPivotColumn->clear();
auto lookForFirstNonZeroInPivotCol = true;
i = (int)m - 1;
i = (ssize_t)m - 1;
while (lookForFirstNonZeroInPivotCol) {
spRowi = matrixA->at(i);
if (spRowi->find(p) == spRowi->end()) {
if (i <= (int)p) throwSingularMatrixError("doPivoting"); //Use int because i can be negative
if (i <= (ssize_t)p) throwSingularMatrixError("doPivoting"); //Use ssize_t because i can be negative
}
else {
markowitzPivotColCount = 0;
Expand All @@ -44,7 +44,7 @@ void GESpMatParPvPrecise::doPivoting(size_t p)
}
i--;
}
while (i >= (int)p) { //Use int because i can be negative
while (i >= (ssize_t)p) { //Use ssize_t because i can be negative
spRowi = matrixA->at(i);
if (spRowi->find(p) == spRowi->end()) {
aip = std::numeric_limits<double>::min();
Expand Down
4 changes: 2 additions & 2 deletions OndselSolver/GeneralSpline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ double MbD::GeneralSpline::derivativeAt(size_t n, double xxx)
calcIndexAndDeltaFor(xxx);
auto& derivsi = derivs->at(index);
double sum = 0.0;
for (int j = (int)degree; j >= (int) n + 1; j--) //Use int because of decrement
for (ssize_t j = (ssize_t)degree; j >= (ssize_t) n + 1; j--) //Use ssize_t because of decrement
{
sum = (sum + derivsi->at((size_t)j - 1)) * delta / (j - n);
}
Expand Down Expand Up @@ -231,7 +231,7 @@ double MbD::GeneralSpline::y(double xxx)
calcIndexAndDeltaFor(xxx);
auto& derivsi = derivs->at(index);
double sum = 0.0;
for (int j = (int)degree; j >= 1; j--) //Use int because of decrement
for (ssize_t j = (ssize_t)degree; j >= 1; j--) //Use ssize_t because of decrement
{
sum = (sum + derivsi->at((size_t)j - 1)) * delta / j;
}
Expand Down
6 changes: 3 additions & 3 deletions OndselSolver/LDUFullMat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ void LDUFullMat::backSubstituteIntoDU()
//| rowi sum |
answerX = std::make_shared<FullColumn<double>>(n);
answerX->at(n - 1) = rightHandSideB->at(m - 1) / matrixA->at(m - 1)->at(n - 1);
for (int i = (int)n - 2; i >= 0; i--) //Use int because of decrement
for (ssize_t i = (ssize_t)n - 2; i >= 0; i--) //Use ssize_t because of decrement
{
auto& rowi = matrixA->at(i);
double sum = answerX->at((size_t)n - 1) * rowi->at((size_t)n - 1);
for (int j = i + 1; j < (int)n - 1; j++)
double sum = answerX->at(n - 1) * rowi->at(n - 1);
for (size_t j = i + 1; j < n - 1; j++)
{
sum += answerX->at(j) * rowi->at(j);
}
Expand Down
2 changes: 1 addition & 1 deletion OndselSolver/LDUSpMat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void LDUSpMat::backSubstituteIntoDU()
}
answerX = std::make_shared<FullColumn<double>>(m);
answerX->at(n - 1) = rightHandSideB->at(m - 1);
for (int i = (int)n - 2; i >= 0; i--) //Use int because of decrement
for (ssize_t i = (ssize_t)n - 2; i >= 0; i--) //Use ssize_t because of decrement
{
auto& rowi = matrixU->at(i);
sum = 0.0;
Expand Down
8 changes: 4 additions & 4 deletions OndselSolver/LDUSpMatParPvMarko.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ void LDUSpMatParPvMarko::doPivoting(size_t p)
//"Do scaling. Do partial pivoting."
//"criterion := mag / (2.0d raisedTo: rowiCount)."
//| lookForFirstNonZeroInPivotCol i rowi aip criterionMax rowPivoti criterion max |
int i; //Use int because of decrement
ssize_t i; //Use ssize_t because of decrement
size_t rowPivoti;
double aip, mag, max, criterion, criterionMax;
SpRowDsptr spRowi;
rowPositionsOfNonZerosInPivotColumn->clear();
auto lookForFirstNonZeroInPivotCol = true;
i = (int)m - 1;
i = (ssize_t)m - 1;
while (lookForFirstNonZeroInPivotCol) {
spRowi = matrixA->at(i);
if (spRowi->find(p) == spRowi->end()) {
if (i <= (int)p) throwSingularMatrixError(""); //Use int because i can be negative
if (i <= (ssize_t)p) throwSingularMatrixError(""); //Use ssize_t because i can be negative
}
else {
markowitzPivotColCount = 0;
Expand All @@ -42,7 +42,7 @@ void LDUSpMatParPvMarko::doPivoting(size_t p)
}
i--;
}
while (i >= (int)p) { //Use int because i can be negative
while (i >= (ssize_t)p) { //Use ssize_t because i can be negative
spRowi = matrixA->at(i);
if (spRowi->find(p) == spRowi->end()) {
aip = std::numeric_limits<double>::min();
Expand Down
8 changes: 4 additions & 4 deletions OndselSolver/LDUSpMatParPvPrecise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ void LDUSpMatParPvPrecise::doPivoting(size_t p)
//"Check for singular pivot."
//"Do scaling. Do partial pivoting."
//| max rowPivot aip mag lookForFirstNonZeroInPivotCol i |
int i; //Use int because of decrement
ssize_t i; //Use ssize_t because of decrement
size_t rowPivoti;
double aip, mag, max;
SpRowDsptr spRowi;
rowPositionsOfNonZerosInPivotColumn->clear();
auto lookForFirstNonZeroInPivotCol = true;
i = (int)m - 1;
i = (ssize_t)m - 1;
while (lookForFirstNonZeroInPivotCol) {
spRowi = matrixA->at(i);
if (spRowi->find(p) == spRowi->end()) {
if (i <= (int)p) throwSingularMatrixError(""); //Use int because i can be negative
if (i <= (ssize_t)p) throwSingularMatrixError(""); //Use ssize_t because i can be negative
}
else {
markowitzPivotColCount = 0;
Expand All @@ -41,7 +41,7 @@ void LDUSpMatParPvPrecise::doPivoting(size_t p)
}
i--;
}
while (i >= (int)p) { //Use int because i can be negative
while (i >= (ssize_t)p) { //Use ssize_t because i can be negative
spRowi = matrixA->at(i);
if (spRowi->find(p) == spRowi->end()) {
aip = std::numeric_limits<double>::min();
Expand Down
6 changes: 6 additions & 0 deletions OndselSolver/Numeric.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
#include <cstddef>
#include <limits>

// For Windows platforms only, cstddef includes size_t but not ssize_t
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif

#include "MbDMath.h"

namespace MbD {
Expand Down
2 changes: 1 addition & 1 deletion OndselSolver/StableBackwardDifference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void StableBackwardDifference::formTaylorRowwithTimeNodederivative(size_t i, siz
//| rowi hi hipower aij |
auto& rowi = taylorMatrix->at(i);
if (k > 0) {
for (int j = 0; j < (int)k - 2; j++) //Use int because of subtraction
for (ssize_t j = 0; j < (ssize_t)k - 2; j++)
{
rowi->at(j) = 0.0;
}
Expand Down
7 changes: 3 additions & 4 deletions OndselSolver/SymbolicParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,16 @@ bool MbD::SymbolicParser::peekForTypeNoPush(const std::string& c)

std::string MbD::SymbolicParser::scanToken()
{
prevEnd = (int)source->tellg(); //Use int because of decrement
prevEnd--;
prevEnd = source->tellg() - std::streamoff(1);
while (std::isspace(hereChar) || isNextLineTag(hereChar)) {
hereChar = source->get();
}
if (hereChar == EOF) {
mark = prevEnd + 1;
mark = prevEnd + std::streamoff(1);;
tokenType = "end";
return token = "";
}
mark = (int)source->tellg();
mark = source->tellg();
if (std::isalpha(hereChar)) {
xLetter();
}
Expand Down
2 changes: 1 addition & 1 deletion OndselSolver/SymbolicParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace MbD {
std::shared_ptr<std::map<std::string, Symsptr>> variables;
std::shared_ptr<std::vector<ASMTItemIJ>> geoIJs;
std::shared_ptr<Units> units;
int mark = -1, prevEnd = -1;
std::streampos mark = 0, prevEnd = 0;
char hereChar = '\0';
std::string token, tokenType;
double tokenNum = -1.0e100;
Expand Down