From 1355fdbfaf2262204d63bb6cfaee80c0b0b6d65f Mon Sep 17 00:00:00 2001 From: Oldes Date: Fri, 16 Oct 2020 00:22:07 +0200 Subject: [PATCH] FIX: `log-*` functions should not return `positive number required` errors fixes: https://github.com/Oldes/Rebol-issues/issues/2432 --- src/core/n-math.c | 6 ++++++ src/tests/units/decimal-test.r3 | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/core/n-math.c b/src/core/n-math.c index 7ed50170e0..2a2f5304e3 100644 --- a/src/core/n-math.c +++ b/src/core/n-math.c @@ -352,7 +352,9 @@ enum {SINE, COSINE, TANGENT}; ***********************************************************************/ { REBDEC dval = AS_DECIMAL(D_ARG(1)); +#ifdef USE_NO_INFINITY if (dval <= 0) Trap0(RE_POSITIVE); +#endif SET_DECIMAL(D_RET, log10(dval)); return R_RET; } @@ -365,7 +367,9 @@ enum {SINE, COSINE, TANGENT}; ***********************************************************************/ { REBDEC dval = AS_DECIMAL(D_ARG(1)); +#ifdef USE_NO_INFINITY if (dval <= 0) Trap0(RE_POSITIVE); +#endif SET_DECIMAL(D_RET, log(dval) / LOG2); return R_RET; } @@ -378,7 +382,9 @@ enum {SINE, COSINE, TANGENT}; ***********************************************************************/ { REBDEC dval = AS_DECIMAL(D_ARG(1)); +#ifdef USE_NO_INFINITY if (dval <= 0) Trap0(RE_POSITIVE); +#endif SET_DECIMAL(D_RET, log(dval)); return R_RET; } diff --git a/src/tests/units/decimal-test.r3 b/src/tests/units/decimal-test.r3 index 5fe7e1eeb0..f080950454 100644 --- a/src/tests/units/decimal-test.r3 +++ b/src/tests/units/decimal-test.r3 @@ -125,6 +125,28 @@ Rebol [ ===end-group=== +===start-group=== "log" + --test-- "log-* -1" + ;@@ https://github.com/Oldes/Rebol-issues/issues/2431 + --assert "1.#NaN" = mold try [log-2 -1] + --assert "1.#NaN" = mold try [log-e -1] + --assert "1.#NaN" = mold try [log-10 -1] + + --test-- "log-* 0" + --assert "-1.#INF" = mold try [log-2 0] + --assert "-1.#INF" = mold try [log-e 0] + --assert "-1.#INF" = mold try [log-10 0] + + --test-- "log-2 32" + --assert 5.0 = log-2 32 + --test-- "log-10 100" + --assert 2.0 = log-10 100 + --test-- "log-e 123" + --assert 4.812184355372417 = log-e 123 + +===end-group=== + + ===start-group=== "decimal issues" --test-- "issue-1753" ;@@ https://github.com/Oldes/Rebol-issues/issues/1753