Skip to content

Commit aa7aa41

Browse files
committed
FIX: throw an error when converting 1.#NaN value to integer
1 parent 45b358f commit aa7aa41

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/core/t-integer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@
274274
case A_TO:
275275
val = D_ARG(2);
276276
if (IS_DECIMAL(val) || IS_PERCENT(val)) {
277-
if (VAL_DECIMAL(val) < MIN_D64 || VAL_DECIMAL(val) >= MAX_D64)
277+
if (VAL_DECIMAL(val) < MIN_D64 || VAL_DECIMAL(val) >= MAX_D64 || isnan(VAL_DECIMAL(val)))
278278
Trap0(RE_OVERFLOW);
279279
num = (REBI64)VAL_DECIMAL(val);
280280
}

src/tests/units/make-test.r3

+8
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ Rebol [
140140
;@@ https://github.com/Oldes/Rebol-issues/issues/2099
141141
--assert 302961000000 = to integer! "3.02961E+11"
142142

143+
--test-- "make/to integer! 1.#NaN and 1.#INF"
144+
--assert error? try [to integer! 1.#NaN]
145+
--assert error? try [to integer! 1.#INF]
146+
--assert error? try [to integer! -1.#INF]
147+
--assert error? try [make integer! 1.#NaN]
148+
--assert error? try [make integer! 1.#INF]
149+
--assert error? try [make integer! -1.#INF]
150+
143151
===end-group===
144152

145153
===start-group=== "make/to decimal!"

0 commit comments

Comments
 (0)