diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-08-16 06:54:33 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-08-16 06:54:33 -0700 |
commit | c77cd7d90f4a1549dacbf4b5e34827df2d6e4f03 (patch) | |
tree | 3ae642dc2162703404efceb85d4ac3e7c1fd88bd /arith.c | |
parent | 45e2d317b52cf5eec1212c175a39a97222ee9e3b (diff) | |
download | txr-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.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -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)) |