Skip to content

Commit

Permalink
use always 64-bit arithemtics
Browse files Browse the repository at this point in the history
long is only 32-bit on 32-bit systems and on 64-bit Windows
ensure we have consistent behavior
  • Loading branch information
christoph-cullmann committed Feb 13, 2025
1 parent a62c67f commit e8c9dd5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
12 changes: 6 additions & 6 deletions src/CglGMI/CglGMI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,11 +884,11 @@ bool CglGMI::scaleCut(double* cutElem, int* cutIndex, int cutNz,
/************************************************************************/
bool CglGMI::scaleCutIntegral(double* cutElem, int* cutIndex, int cutNz,
double& cutRhs) {
long gcd, lcm;
int64_t gcd, lcm;
double maxdelta = param.getEPS();
double maxscale = 1000;
long maxdnom = 1000;
long numerator = 0, denominator = 0;
int64_t maxdnom = 1000;
int64_t numerator = 0, denominator = 0;
// Initialize gcd and lcm
CoinRational r = CoinRational(cutRhs, maxdelta, maxdnom);
if (r.getNumerator() != 0){
Expand Down Expand Up @@ -933,13 +933,13 @@ bool CglGMI::scaleCutIntegral(double* cutElem, int* cutIndex, int cutNz,
} /* scaleCutIntegral */

/************************************************************************/
long CglGMI::computeGcd(long a, long b) {
int64_t CglGMI::computeGcd(int64_t a, int64_t b) {
// This is the standard Euclidean algorithm for gcd
long remainder = 1;
int64_t remainder = 1;
// Make sure a<=b (will always remain so)
if (a > b) {
// Swap a and b
long temp = a;
int64_t temp = a;
a = b;
b = temp;
}
Expand Down
6 changes: 3 additions & 3 deletions src/CglGMI/CglGMI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ class CGLLIB_EXPORT CglGMI : public CglCutGenerator {
double& cutRhs);

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

/// Compute the greatest common divisor
long computeGcd(long a, long b);
int64_t computeGcd(int64_t a, int64_t b);

/// print a vector of integers
void printvecINT(const char *vecstr, const int *x, int n) const;
Expand Down
12 changes: 6 additions & 6 deletions src/CglGomory/CglGomory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,13 @@ static long long int gcd(long long int a, long long int b)
#define GOMORY_INT int
#endif
#if USE_CGL_RATIONAL>0
static long computeGcd(long a, long b) {
static int64_t computeGcd(int64_t a, int64_t b) {
// This is the standard Euclidean algorithm for gcd
long remainder = 1;
int64_t remainder = 1;
// Make sure a<=b (will always remain so)
if (a > b) {
// Swap a and b
long temp = a;
int64_t temp = a;
a = b;
b = temp;
}
Expand All @@ -448,10 +448,10 @@ static long computeGcd(long a, long b) {
} /* computeGcd */
static bool scaleCutIntegral(double* cutElem, int* cutIndex, int cutNz,
double& cutRhs, double maxdelta) {
long gcd, lcm;
int64_t gcd, lcm;
double maxscale = 1000;
long maxdnom = USE_CGL_RATIONAL;
//long numerator = 0, denominator = 0;
int64_t maxdnom = USE_CGL_RATIONAL;
//int64_t numerator = 0, denominator = 0;
// Initialize gcd and lcm
CoinRational r = CoinRational(cutRhs, maxdelta, maxdnom);
if (r.getNumerator() != 0){
Expand Down
14 changes: 7 additions & 7 deletions src/CglPreProcess/CglPreProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1183,13 +1183,13 @@ static void writeDebugMps(const OsiSolverInterface *solver,
#define USE_CGL_RATIONAL 1
#if USE_CGL_RATIONAL>0
#include "CoinRational.hpp"
static long computeGcd(long a, long b) {
static int64_t computeGcd(int64_t a, int64_t b) {
// This is the standard Euclidean algorithm for gcd
long remainder = 1;
int64_t remainder = 1;
// Make sure a<=b (will always remain so)
if (a > b) {
// Swap a and b
long temp = a;
int64_t temp = a;
a = b;
b = temp;
}
Expand All @@ -1212,15 +1212,15 @@ static long computeGcd(long a, long b) {
} /* computeGcd */
static bool scaleRowIntegral(double* rowElem, int rowNz)
{
long gcd, lcm;
int64_t gcd, lcm;
double maxdelta = 1.0e-13;
double maxscale = 1000;
long maxdnom = 1000;
//long numerator = 0, denominator = 0;
int64_t maxdnom = 1000;
//int64_t numerator = 0, denominator = 0;
// Initialize gcd and lcm
CoinRational r = CoinRational(rowElem[0], maxdelta, maxdnom);
if (r.getNumerator() != 0){
gcd = labs(r.getNumerator());
gcd = llabs(r.getNumerator());
lcm = r.getDenominator();
} else {
return false;
Expand Down

0 comments on commit e8c9dd5

Please sign in to comment.