From 5f9695d9defe2bf3bcf6f07e1c0988471028d4c7 Mon Sep 17 00:00:00 2001 From: Oldes Date: Fri, 19 Nov 2021 22:09:41 +0100 Subject: [PATCH] FIX: enhanced precision in comparison of time with integer resolves: https://github.com/Oldes/Rebol-issues/issues/2463 --- src/core/n-math.c | 7 ++++--- src/tests/units/time-test.r3 | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/core/n-math.c b/src/core/n-math.c index aa2fce1674..cca66ee956 100644 --- a/src/core/n-math.c +++ b/src/core/n-math.c @@ -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; @@ -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; diff --git a/src/tests/units/time-test.r3 b/src/tests/units/time-test.r3 index 72201450af..0e4ef9dc93 100644 --- a/src/tests/units/time-test.r3 +++ b/src/tests/units/time-test.r3 @@ -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)