Skip to content

Commit 1355fdb

Browse files
committed
FIX: log-* functions should not return positive number required errors
fixes: Oldes/Rebol-issues#2432
1 parent 2164430 commit 1355fdb

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/core/n-math.c

+6
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,9 @@ enum {SINE, COSINE, TANGENT};
352352
***********************************************************************/
353353
{
354354
REBDEC dval = AS_DECIMAL(D_ARG(1));
355+
#ifdef USE_NO_INFINITY
355356
if (dval <= 0) Trap0(RE_POSITIVE);
357+
#endif
356358
SET_DECIMAL(D_RET, log10(dval));
357359
return R_RET;
358360
}
@@ -365,7 +367,9 @@ enum {SINE, COSINE, TANGENT};
365367
***********************************************************************/
366368
{
367369
REBDEC dval = AS_DECIMAL(D_ARG(1));
370+
#ifdef USE_NO_INFINITY
368371
if (dval <= 0) Trap0(RE_POSITIVE);
372+
#endif
369373
SET_DECIMAL(D_RET, log(dval) / LOG2);
370374
return R_RET;
371375
}
@@ -378,7 +382,9 @@ enum {SINE, COSINE, TANGENT};
378382
***********************************************************************/
379383
{
380384
REBDEC dval = AS_DECIMAL(D_ARG(1));
385+
#ifdef USE_NO_INFINITY
381386
if (dval <= 0) Trap0(RE_POSITIVE);
387+
#endif
382388
SET_DECIMAL(D_RET, log(dval));
383389
return R_RET;
384390
}

src/tests/units/decimal-test.r3

+22
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,28 @@ Rebol [
125125
===end-group===
126126

127127

128+
===start-group=== "log"
129+
--test-- "log-* -1"
130+
;@@ https://github.com/Oldes/Rebol-issues/issues/2431
131+
--assert "1.#NaN" = mold try [log-2 -1]
132+
--assert "1.#NaN" = mold try [log-e -1]
133+
--assert "1.#NaN" = mold try [log-10 -1]
134+
135+
--test-- "log-* 0"
136+
--assert "-1.#INF" = mold try [log-2 0]
137+
--assert "-1.#INF" = mold try [log-e 0]
138+
--assert "-1.#INF" = mold try [log-10 0]
139+
140+
--test-- "log-2 32"
141+
--assert 5.0 = log-2 32
142+
--test-- "log-10 100"
143+
--assert 2.0 = log-10 100
144+
--test-- "log-e 123"
145+
--assert 4.812184355372417 = log-e 123
146+
147+
===end-group===
148+
149+
128150
===start-group=== "decimal issues"
129151
--test-- "issue-1753"
130152
;@@ https://github.com/Oldes/Rebol-issues/issues/1753

0 commit comments

Comments
 (0)