Skip to content

Commit 6b47c24

Browse files
committed
FEAT: implemented odd? and even? on pair!
resolves: Oldes/Rebol-issues#1884
1 parent dac7ed4 commit 6b47c24

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

src/core/t-pair.c

+15-11
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
REBINT n = 0;
182182
REBD32 x1, x2 = 0.0;
183183
REBD32 y1, y2 = 0.0;
184+
REBINT x, y;
184185

185186
val = D_ARG(1);
186187
x1 = VAL_PAIR_X(val);
@@ -239,13 +240,6 @@
239240
else {
240241
switch(action) {
241242

242-
#ifdef temp
243-
case A_ODDQ:
244-
DECIDE((x1 & 1) && (y1 & 1));
245-
246-
case A_EVENQ:
247-
DECIDE((x1 & 1) == 0 && (y1 & 1) == 0);
248-
#endif
249243
case A_NEGATE:
250244
x1 = -x1;
251245
y1 = -y1;
@@ -345,6 +339,16 @@
345339
return R_RET;
346340
}
347341
Trap_Make(REB_PAIR, val);
342+
343+
case A_ODDQ:
344+
case A_EVENQ:
345+
x = VAL_PAIR_X_INT(val) & 1;
346+
y = VAL_PAIR_Y_INT(val) & 1;
347+
if (action == A_ODDQ)
348+
DECIDE(x && y);
349+
else
350+
DECIDE(x == 0 && y == 0);
351+
348352
}
349353
}
350354
Trap_Action(REB_PAIR, action);
@@ -355,10 +359,10 @@
355359
VAL_PAIR_Y(DS_RETURN) = y1;
356360
return R_RET;
357361

358-
//is_false:
359-
// return R_FALSE;
362+
is_false:
363+
return R_FALSE;
360364

361-
//is_true:
362-
// return R_TRUE;
365+
is_true:
366+
return R_TRUE;
363367
}
364368

src/tests/units/pair-test.r3

+22
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,28 @@ Rebol [
238238

239239
===end-group===
240240

241+
===start-group=== "pair - even?/odd?"
242+
;@@ https://github.com/Oldes/Rebol-issues/issues/1884
243+
--test-- "odd?"
244+
--assert not odd? 0x0
245+
--assert not odd? 0x1
246+
--assert not odd? 1x0
247+
--assert odd? 1x1
248+
--assert not odd? 2x2
249+
--assert odd? 1.1x2.9
250+
--assert not odd? 1.1x2.2
251+
252+
--test-- "even?"
253+
--assert even? 0x0
254+
--assert not even? 0x1
255+
--assert not even? 1x0
256+
--assert not even? 1x1
257+
--assert even? 2x2
258+
--assert even? 1.9x2.1
259+
--assert not even? 1.1x2.2
260+
261+
===end-group===
262+
241263
===start-group=== "pair - issues"
242264

243265
--test-- "invalid construction"

0 commit comments

Comments
 (0)