Skip to content

Commit

Permalink
FIX: square-root -1 should return 1.#NaN instead of an error
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Oct 15, 2020
1 parent b44fca3 commit 2164430
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/n-math.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,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, sqrt(dval));
return R_RET;
}
Expand Down
10 changes: 10 additions & 0 deletions src/tests/units/decimal-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ Rebol [
]
===end-group===


===start-group=== "square-root"
--test-- "square-root 4"
--assert 2.0 = square-root 4
--test-- "square-root -1"
;@@ https://github.com/Oldes/Rebol-issues/issues/2431
--assert "1.#NaN" = mold try [square-root -1]
===end-group===


===start-group=== "decimal issues"
--test-- "issue-1753"
;@@ https://github.com/Oldes/Rebol-issues/issues/1753
Expand Down

0 comments on commit 2164430

Please sign in to comment.