Skip to content

Commit

Permalink
FIX: log-* functions should not return positive number required e…
Browse files Browse the repository at this point in the history
…rrors

fixes: Oldes/Rebol-issues#2432
  • Loading branch information
Oldes committed Oct 15, 2020
1 parent 2164430 commit 1355fdb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/n-math.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
22 changes: 22 additions & 0 deletions src/tests/units/decimal-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1355fdb

Please sign in to comment.