Skip to content

Commit

Permalink
FIX: throw an error when converting 1.#NaN value to integer
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Jan 11, 2024
1 parent 45b358f commit aa7aa41
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/t-integer.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
case A_TO:
val = D_ARG(2);
if (IS_DECIMAL(val) || IS_PERCENT(val)) {
if (VAL_DECIMAL(val) < MIN_D64 || VAL_DECIMAL(val) >= MAX_D64)
if (VAL_DECIMAL(val) < MIN_D64 || VAL_DECIMAL(val) >= MAX_D64 || isnan(VAL_DECIMAL(val)))
Trap0(RE_OVERFLOW);
num = (REBI64)VAL_DECIMAL(val);
}
Expand Down
8 changes: 8 additions & 0 deletions src/tests/units/make-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ Rebol [
;@@ https://github.com/Oldes/Rebol-issues/issues/2099
--assert 302961000000 = to integer! "3.02961E+11"

--test-- "make/to integer! 1.#NaN and 1.#INF"
--assert error? try [to integer! 1.#NaN]
--assert error? try [to integer! 1.#INF]
--assert error? try [to integer! -1.#INF]
--assert error? try [make integer! 1.#NaN]
--assert error? try [make integer! 1.#INF]
--assert error? try [make integer! -1.#INF]

===end-group===

===start-group=== "make/to decimal!"
Expand Down

0 comments on commit aa7aa41

Please sign in to comment.