Skip to content

Commit 2164430

Browse files
committed
FIX: square-root -1 should return 1.#NaN instead of an error
fixes: Oldes/Rebol-issues#2431
1 parent b44fca3 commit 2164430

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/core/n-math.c

+2
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,9 @@ enum {SINE, COSINE, TANGENT};
391391
***********************************************************************/
392392
{
393393
REBDEC dval = AS_DECIMAL(D_ARG(1));
394+
#ifdef USE_NO_INFINITY
394395
if (dval < 0) Trap0(RE_POSITIVE);
396+
#endif
395397
SET_DECIMAL(D_RET, sqrt(dval));
396398
return R_RET;
397399
}

src/tests/units/decimal-test.r3

+10
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ Rebol [
115115
]
116116
===end-group===
117117

118+
119+
===start-group=== "square-root"
120+
--test-- "square-root 4"
121+
--assert 2.0 = square-root 4
122+
--test-- "square-root -1"
123+
;@@ https://github.com/Oldes/Rebol-issues/issues/2431
124+
--assert "1.#NaN" = mold try [square-root -1]
125+
===end-group===
126+
127+
118128
===start-group=== "decimal issues"
119129
--test-- "issue-1753"
120130
;@@ https://github.com/Oldes/Rebol-issues/issues/1753

0 commit comments

Comments
 (0)