Skip to content

Commit b9723de

Browse files
committed
FIX: better handling large number tuple multiplication
related to: Oldes/Rebol-issues#1974
1 parent 4415568 commit b9723de

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/core/t-tuple.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,20 @@
226226
case A_ADD: v += a; break;
227227
case A_SUBTRACT: v -= a; break;
228228
case A_MULTIPLY:
229-
if (IS_DECIMAL(arg) || IS_PERCENT(arg))
229+
if ( v == 0 ) break;
230+
if (IS_DECIMAL(arg) || IS_PERCENT(arg)) {
231+
if (dec > 255.0) {
232+
*vp = (REBYTE)255;
233+
continue;
234+
}
230235
v=(REBI64)(v*dec);
231-
else
236+
} else {
237+
if (a > 255) {
238+
*vp = (REBYTE)255;
239+
continue;
240+
}
232241
v *= a;
242+
}
233243
break;
234244
case A_DIVIDE:
235245
if (IS_DECIMAL(arg) || IS_PERCENT(arg)) {

src/tests/units/tuple-test.r3

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Rebol [
1919

2020
--test-- "tuple multiply"
2121
--assert (1.1.1 * 2147483648.0) == 255.255.255
22+
--assert (1.1.1 * 4.656612873077e+100) == 255.255.255
23+
--assert (1.1.1 * 4656612873077) == 255.255.255
24+
--assert (0.0.0 * 4656612873077) == 0.0.0
2225

2326
===end-group===
2427

0 commit comments

Comments
 (0)