Skip to content

Commit 64bc1d1

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 1678200 commit 64bc1d1

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/CoinRational.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// Returns closest (or almost, anyway) rational to val with denominator less
2121
// than or equal to maxdnom. Return value is true if within tolerance, false
2222
// otherwise.
23-
bool CoinRational::nearestRational_(double val, double maxdelta, long maxdnom)
23+
bool CoinRational::nearestRational_(double val, double maxdelta, int64_t maxdnom)
2424
{
2525
double intpart;
2626
if (floor(val)==val) {
@@ -31,7 +31,7 @@ bool CoinRational::nearestRational_(double val, double maxdelta, long maxdnom)
3131
double fracpart = fabs(modf(val, &intpart));
3232
// Consider using remainder() instead?
3333

34-
long a = 0, b = 1, c = 1, d = 1;
34+
int64_t a = 0, b = 1, c = 1, d = 1;
3535
#define DEBUG_X 1
3636
#if DEBUG_X
3737
bool shouldBeOK = false;
@@ -83,7 +83,7 @@ bool CoinRational::nearestRational_(double val, double maxdelta, long maxdnom)
8383
numerator_ *= -1;
8484
#if DEBUG_X > 1
8585
if (shouldBeOK) {
86-
printf("val %g is %ld/%ld to accuracy %g\n", val, numerator_, denominator_,
86+
printf("val %g is %lld/%lld to accuracy %g\n", val, numerator_, denominator_,
8787
fabs(val - numerator_ / double(denominator_)));
8888
}
8989
#endif

src/CoinRational.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ class COINUTILSLIB_EXPORT CoinRational
1414
{
1515

1616
public:
17-
long getDenominator() { return denominator_; }
18-
long getNumerator() { return numerator_; }
17+
int64_t getDenominator() { return denominator_; }
18+
int64_t getNumerator() { return numerator_; }
1919

2020
CoinRational()
2121
: numerator_(0)
2222
, denominator_(1) {};
2323

24-
CoinRational(long n, long d)
24+
CoinRational(int64_t n, int64_t d)
2525
: numerator_(n)
2626
, denominator_(d) {};
2727

28-
CoinRational(double val, double maxdelta, long maxdnom)
28+
CoinRational(double val, double maxdelta, int64_t maxdnom)
2929
{
3030
if (!nearestRational_(val, maxdelta, maxdnom)) {
3131
numerator_ = 0;
@@ -34,10 +34,10 @@ class COINUTILSLIB_EXPORT CoinRational
3434
};
3535

3636
private:
37-
long numerator_;
38-
long denominator_;
37+
int64_t numerator_;
38+
int64_t denominator_;
3939

40-
bool nearestRational_(double val, double maxdelta, long maxdnom);
40+
bool nearestRational_(double val, double maxdelta, int64_t maxdnom);
4141
};
4242

4343
#endif

0 commit comments

Comments
 (0)