Skip to content

Commit e4b1a8c

Browse files
committed
CHANGE: fine-tune decimal non-strict comparison (to cover also percent datatype)
1 parent 8775144 commit e4b1a8c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/core/t-decimal.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ REBOOL almost_equal(REBDEC a, REBDEC b, REBCNT max_diff) {
177177
***********************************************************************/
178178
{
179179
if (mode >= 0) {
180-
if (mode <= 1) return almost_equal(VAL_DECIMAL(a), VAL_DECIMAL(b), 10);
180+
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
181181
if (mode == 2) return almost_equal(VAL_DECIMAL(a), VAL_DECIMAL(b), 0);
182182
return VAL_INT64(a) == VAL_INT64(b); // bits are identical
183183
}

src/tests/units/decimal-test.r3

+4-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,10 @@ Rebol [
322322
--assert 1000 // #"a" == 30
323323
--assert #"a" // 3 == #"^A"
324324
--assert 10:0 // 3:0 == 1:0
325-
--assert 10% // 3% == 1%
325+
--assert not (100% // 3% == 1%)
326+
--assert (100% // 3% = 1%)
327+
--assert not ( 10% // 3% == 1%)
328+
--assert ( 10% // 3% = 1%)
326329
--assert 10 // 3% == 0 ; because result A was integer, result is also integer!
327330
--assert 0.01 = round/to (10.0 // 3%) 0.00001
328331

0 commit comments

Comments
 (0)