Skip to content

Commit 0c8efcc

Browse files
use always 64-bit arithemtics
long is only 32-bit on 32-bit systems and on 64-bit Windows ensure we have consistent behavior
1 parent a62c67f commit 0c8efcc

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

src/CglGMI/CglGMI.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -884,15 +884,15 @@ bool CglGMI::scaleCut(double* cutElem, int* cutIndex, int cutNz,
884884
/************************************************************************/
885885
bool CglGMI::scaleCutIntegral(double* cutElem, int* cutIndex, int cutNz,
886886
double& cutRhs) {
887-
long gcd, lcm;
887+
int64_t gcd, lcm;
888888
double maxdelta = param.getEPS();
889889
double maxscale = 1000;
890-
long maxdnom = 1000;
891-
long numerator = 0, denominator = 0;
890+
int64_t maxdnom = 1000;
891+
int64_t numerator = 0, denominator = 0;
892892
// Initialize gcd and lcm
893893
CoinRational r = CoinRational(cutRhs, maxdelta, maxdnom);
894894
if (r.getNumerator() != 0){
895-
gcd = labs(r.getNumerator());
895+
gcd = llabs(r.getNumerator());
896896
lcm = r.getDenominator();
897897
}
898898
else{
@@ -933,13 +933,13 @@ bool CglGMI::scaleCutIntegral(double* cutElem, int* cutIndex, int cutNz,
933933
} /* scaleCutIntegral */
934934

935935
/************************************************************************/
936-
long CglGMI::computeGcd(long a, long b) {
936+
int64_t CglGMI::computeGcd(int64_t a, int64_t b) {
937937
// This is the standard Euclidean algorithm for gcd
938-
long remainder = 1;
938+
int64_t remainder = 1;
939939
// Make sure a<=b (will always remain so)
940940
if (a > b) {
941941
// Swap a and b
942-
long temp = a;
942+
int64_t temp = a;
943943
a = b;
944944
b = temp;
945945
}

src/CglGMI/CglGMI.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,11 @@ class CGLLIB_EXPORT CglGMI : public CglCutGenerator {
247247
double& cutRhs);
248248

249249
/// Compute the nearest rational number; used by scale_row_integral
250-
bool nearestRational(double val, double maxdelta, long maxdnom,
251-
long& numerator, long& denominator);
250+
bool nearestRational(double val, double maxdelta, int64_t maxdnom,
251+
int64_t& numerator, int64_t& denominator);
252252

253253
/// Compute the greatest common divisor
254-
long computeGcd(long a, long b);
254+
int64_t computeGcd(int64_t a, int64_t b);
255255

256256
/// print a vector of integers
257257
void printvecINT(const char *vecstr, const int *x, int n) const;

src/CglGomory/CglGomory.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,13 @@ static long long int gcd(long long int a, long long int b)
419419
#define GOMORY_INT int
420420
#endif
421421
#if USE_CGL_RATIONAL>0
422-
static long computeGcd(long a, long b) {
422+
static int64_t computeGcd(int64_t a, int64_t b) {
423423
// This is the standard Euclidean algorithm for gcd
424-
long remainder = 1;
424+
int64_t remainder = 1;
425425
// Make sure a<=b (will always remain so)
426426
if (a > b) {
427427
// Swap a and b
428-
long temp = a;
428+
int64_t temp = a;
429429
a = b;
430430
b = temp;
431431
}
@@ -448,14 +448,14 @@ static long computeGcd(long a, long b) {
448448
} /* computeGcd */
449449
static bool scaleCutIntegral(double* cutElem, int* cutIndex, int cutNz,
450450
double& cutRhs, double maxdelta) {
451-
long gcd, lcm;
451+
int64_t gcd, lcm;
452452
double maxscale = 1000;
453-
long maxdnom = USE_CGL_RATIONAL;
454-
//long numerator = 0, denominator = 0;
453+
int64_t maxdnom = USE_CGL_RATIONAL;
454+
//int64_t numerator = 0, denominator = 0;
455455
// Initialize gcd and lcm
456456
CoinRational r = CoinRational(cutRhs, maxdelta, maxdnom);
457457
if (r.getNumerator() != 0){
458-
gcd = labs(r.getNumerator());
458+
gcd = llabs(r.getNumerator());
459459
lcm = r.getDenominator();
460460
}
461461
else{

src/CglPreProcess/CglPreProcess.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -1183,13 +1183,13 @@ static void writeDebugMps(const OsiSolverInterface *solver,
11831183
#define USE_CGL_RATIONAL 1
11841184
#if USE_CGL_RATIONAL>0
11851185
#include "CoinRational.hpp"
1186-
static long computeGcd(long a, long b) {
1186+
static int64_t computeGcd(int64_t a, int64_t b) {
11871187
// This is the standard Euclidean algorithm for gcd
1188-
long remainder = 1;
1188+
int64_t remainder = 1;
11891189
// Make sure a<=b (will always remain so)
11901190
if (a > b) {
11911191
// Swap a and b
1192-
long temp = a;
1192+
int64_t temp = a;
11931193
a = b;
11941194
b = temp;
11951195
}
@@ -1212,15 +1212,15 @@ static long computeGcd(long a, long b) {
12121212
} /* computeGcd */
12131213
static bool scaleRowIntegral(double* rowElem, int rowNz)
12141214
{
1215-
long gcd, lcm;
1215+
int64_t gcd, lcm;
12161216
double maxdelta = 1.0e-13;
12171217
double maxscale = 1000;
1218-
long maxdnom = 1000;
1219-
//long numerator = 0, denominator = 0;
1218+
int64_t maxdnom = 1000;
1219+
//int64_t numerator = 0, denominator = 0;
12201220
// Initialize gcd and lcm
12211221
CoinRational r = CoinRational(rowElem[0], maxdelta, maxdnom);
12221222
if (r.getNumerator() != 0){
1223-
gcd = labs(r.getNumerator());
1223+
gcd = llabs(r.getNumerator());
12241224
lcm = r.getDenominator();
12251225
} else {
12261226
return false;

0 commit comments

Comments
 (0)