Skip to content

Commit

Permalink
FIX: finer decimal equiv? comparison than equal?
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed May 23, 2023
1 parent 476a74b commit de59c1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/t-decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ REBOOL almost_equal(REBDEC a, REBDEC b, REBCNT max_diff) {
***********************************************************************/
{
if (mode >= 0) {
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
if (mode == 2) return almost_equal(VAL_DECIMAL(a), VAL_DECIMAL(b), 0);
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
if (mode == 1) return almost_equal(VAL_DECIMAL(a), VAL_DECIMAL(b), 0);
return VAL_INT64(a) == VAL_INT64(b); // bits are identical
}
if (mode == -1) return VAL_DECIMAL(a) >= VAL_DECIMAL(b);
Expand Down
9 changes: 9 additions & 0 deletions src/tests/units/compare-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ Rebol [
--test-- "decimal! invalid compare"
--assert all [error? e: try [90.0 < "a" ] e/id = 'invalid-compare]
--assert all [error? e: try [90.0 < 1x1 ] e/id = 'invalid-compare]

--test-- "decimal! equal?/equiv?/same?"
;@@ https://github.com/Oldes/Rebol-issues/issues/1134
--assert equal? to decimal! #{3FD3333333333333} to decimal! #{3FD3333333333333}
--assert equiv? to decimal! #{3FD3333333333333} to decimal! #{3FD3333333333333}
--assert same? to decimal! #{3FD3333333333333} to decimal! #{3FD3333333333333}
--assert equal? to decimal! #{3FD3333333333333} to decimal! #{3FD3333333333334}
--assert not equiv? to decimal! #{3FD3333333333333} to decimal! #{3FD3333333333334}
--assert not same? to decimal! #{3FD3333333333333} to decimal! #{3FD3333333333334}
===end-group===


Expand Down

0 comments on commit de59c1f

Please sign in to comment.