Skip to content

Commit

Permalink
FIX: handle 1.INF and 1.#NaN cases of its percent type
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Apr 9, 2023
1 parent be1edd2 commit 96eb7da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/f-math.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@
cp += digits_obtained - 1;
} else if (e > 0) {
if (e <= digits_obtained) {
/* handle 1.INF and 1.#NaN cases (issue #2544) */
if (sig[1] == '#') {
*cp++ = *sig++;
*cp++ = point;
memcpy(cp, sig, 4);
cp += 4;
goto end;
}
/* insert digits preceding point */
memcpy (cp, sig, e);
cp += e;
Expand Down Expand Up @@ -321,6 +329,7 @@
}

if (trim == DEC_MOLD_PERCENT) *cp++ = '%';
end:
*cp = 0;
return cp - start;
}
10 changes: 10 additions & 0 deletions src/tests/units/mold-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -559,4 +559,14 @@ Rebol [

===end-group===


===start-group=== "mold percent!"
--test-- "1.#INF and 1.#NaN percents"
;@@ https://github.com/Oldes/Rebol-issues/issues/2544
--assert "1.#INF" == mold to percent! 1.#INF
--assert "-1.#INF" == mold to percent! -1.#INF
--assert "1.#NaN" == mold to percent! 1.#NaN
--assert "1.#NaN" == mold to percent! -1.#NaN
===end-group===

~~~end-file~~~

0 comments on commit 96eb7da

Please sign in to comment.