summaryrefslogtreecommitdiffstats
path: root/arith.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-08-16 06:54:33 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-08-16 06:54:33 -0700
commitc77cd7d90f4a1549dacbf4b5e34827df2d6e4f03 (patch)
tree3ae642dc2162703404efceb85d4ac3e7c1fd88bd /arith.c
parent45e2d317b52cf5eec1212c175a39a97222ee9e3b (diff)
downloadtxr-c77cd7d90f4a1549dacbf4b5e34827df2d6e4f03.tar.gz
txr-c77cd7d90f4a1549dacbf4b5e34827df2d6e4f03.tar.bz2
txr-c77cd7d90f4a1549dacbf4b5e34827df2d6e4f03.zip
Allow character inputs in some bit operations.
* arith.c (logand, logior, logxor): Allow one operand to be a character, if the opposite opernad is a fixnum integer. The result is a character. (bit): Allow the value being tested to be a character. * txr.1: Updated.
Diffstat (limited to 'arith.c')
-rw-r--r--arith.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/arith.c b/arith.c
index 7700ea07..abf9f1be 100644
--- a/arith.c
+++ b/arith.c
@@ -2241,6 +2241,15 @@ val logand(val a, val b)
return zero;
switch (TYPE_PAIR(type(a), type(b))) {
+ case TYPE_PAIR(NUM, CHR):
+ case TYPE_PAIR(CHR, NUM):
+ if (a == b) {
+ return a;
+ } else {
+ cnum ac = c_num(a);
+ cnum bc = c_num(b);
+ return chr(ac & bc);
+ }
case TYPE_PAIR(NUM, NUM):
if (a == b) {
return a;
@@ -2282,6 +2291,15 @@ val logior(val a, val b)
return zero;
switch (TYPE_PAIR(type(a), type(b))) {
+ case TYPE_PAIR(NUM, CHR):
+ case TYPE_PAIR(CHR, NUM):
+ if (a == b) {
+ return a;
+ } else {
+ cnum ac = c_num(a);
+ cnum bc = c_num(b);
+ return chr(ac | bc);
+ }
case TYPE_PAIR(NUM, NUM):
if (a == b) {
return a;
@@ -2323,6 +2341,15 @@ val logxor(val a, val b)
return zero;
switch (TYPE_PAIR(type(a), type(b))) {
+ case TYPE_PAIR(NUM, CHR):
+ case TYPE_PAIR(CHR, NUM):
+ if (a == b) {
+ return a;
+ } else {
+ cnum ac = c_num(a);
+ cnum bc = c_num(b);
+ return chr(ac ^ bc);
+ }
case TYPE_PAIR(NUM, NUM):
if (a == b) {
return a;
@@ -2593,6 +2620,7 @@ val bit(val a, val bit)
switch (type(a)) {
case NUM:
+ case CHR:
{
cnum an = c_num(a);
if (bn < (SIZEOF_PTR * CHAR_BIT))