Skip to content

Commit de59c1f

Browse files
committed
FIX: finer decimal equiv? comparison than equal?
resolves: Oldes/Rebol-issues#1134
1 parent 476a74b commit de59c1f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/core/t-decimal.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ REBOOL almost_equal(REBDEC a, REBDEC b, REBCNT max_diff) {
178178
***********************************************************************/
179179
{
180180
if (mode >= 0) {
181-
if (mode <= 1) return almost_equal(VAL_DECIMAL(a), VAL_DECIMAL(b), 21); //O: there was 10, but 21 is the minimum to have: (100% // 3% = 1%) == true
182-
if (mode == 2) return almost_equal(VAL_DECIMAL(a), VAL_DECIMAL(b), 0);
181+
if (mode == 0) return almost_equal(VAL_DECIMAL(a), VAL_DECIMAL(b), 21); //O: there was 10, but 21 is the minimum to have: (100% // 3% = 1%) == true
182+
if (mode == 1) return almost_equal(VAL_DECIMAL(a), VAL_DECIMAL(b), 0);
183183
return VAL_INT64(a) == VAL_INT64(b); // bits are identical
184184
}
185185
if (mode == -1) return VAL_DECIMAL(a) >= VAL_DECIMAL(b);

src/tests/units/compare-test.r3

+9
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ Rebol [
111111
--test-- "decimal! invalid compare"
112112
--assert all [error? e: try [90.0 < "a" ] e/id = 'invalid-compare]
113113
--assert all [error? e: try [90.0 < 1x1 ] e/id = 'invalid-compare]
114+
115+
--test-- "decimal! equal?/equiv?/same?"
116+
;@@ https://github.com/Oldes/Rebol-issues/issues/1134
117+
--assert equal? to decimal! #{3FD3333333333333} to decimal! #{3FD3333333333333}
118+
--assert equiv? to decimal! #{3FD3333333333333} to decimal! #{3FD3333333333333}
119+
--assert same? to decimal! #{3FD3333333333333} to decimal! #{3FD3333333333333}
120+
--assert equal? to decimal! #{3FD3333333333333} to decimal! #{3FD3333333333334}
121+
--assert not equiv? to decimal! #{3FD3333333333333} to decimal! #{3FD3333333333334}
122+
--assert not same? to decimal! #{3FD3333333333333} to decimal! #{3FD3333333333334}
114123
===end-group===
115124

116125

0 commit comments

Comments
 (0)