Skip to content

Commit

Permalink
FIX: enhanced precision in comparison of time with integer
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Nov 19, 2021
1 parent dc91bdf commit 5f9695d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/core/n-math.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,8 @@ enum {SINE, COSINE, TANGENT};
else if (tb == REB_INTEGER || tb == REB_CHAR) // special negative?, zero?, ...
goto compare;
else if (tb == REB_TIME) {
SET_INTEGER(b, (REBI64)SECS_IN(VAL_TIME(b)));
SET_DECIMAL(a, (REBDEC)VAL_INT64(a));
SET_DECIMAL(b, (REBDEC)VAL_TIME(b) * NANO);
goto compare;
}
break;
Expand Down Expand Up @@ -710,12 +711,12 @@ enum {SINE, COSINE, TANGENT};
goto compare;
break;
case REB_TIME:
SET_DECIMAL(a, (REBDEC)VAL_TIME(a) * NANO);
if (tb == REB_INTEGER) {
SET_INTEGER(a, (REBI64)SECS_IN(VAL_TIME(a)));
SET_DECIMAL(b, (REBDEC)VAL_INT64(b));
goto compare;
}
else if (tb == REB_DECIMAL || tb == REB_PERCENT) {
SET_DECIMAL(a, (REBDEC)VAL_TIME(a) * NANO);
goto compare;
}
break;
Expand Down
9 changes: 9 additions & 0 deletions src/tests/units/time-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ Rebol [
; --assert 12:34:56.1 = round/to 12:34:56 0.3
; --assert 12:34:56.1 = round/to 12:34:56 30%

--test-- "compare with 0"
;@@ https://github.com/Oldes/Rebol-issues/issues/2463
--assert 0 < 0:0:0.1
--assert 0:0:0.1 > 0
--assert 0.0 < 0:0:0.1
--assert 0:0:0.1 > 0.0
--assert 0% < 0:0:0.1
--assert 0:0:0.1 > 0%

--test-- "issue-90"
;@@ https://github.com/Oldes/Rebol-issues/issues/90
--assert -23:00 = (1:0:0 - 24:00)
Expand Down

0 comments on commit 5f9695d

Please sign in to comment.