/ two-slash /
2/ : shift or division?
The ANS Forth (a.k.a. ISO Forth) defines 2/ as an arithmetic shift right,
but there are two unevident nuances.
First of all, 2/ is not the same as 2 /
Jerry Avins <firstname.lastname@example.org**> wrote in the message <3CF7A052.75658F4B@ieee.org>:
> SwiftForth 2.2.2 09Mar2001
> 101 2 / . 50 ok
> 101 2/ . 50 ok
> -101 2 / . -50 ok
> -101 2/ . -51 ok
Look once more at the last two lines. 2/ rounds towards minus infinity,
while 2 / rounds towards zero.
At second, the ANS Forth document fails to give the right definition
of what an arithmetic shift right is:
> 6.1.0330 2/ "two-slash" CORE
> ( x1 -- x2 )
> x2 is the result of shifting x1 one bit toward the least-significant
> bit, leaving the most-significant bit unchanged.
This definition is ok for both tow's complement and one's complement
machines but is wrong for signed magnitude machines.
Andrew Haley <aph@*****************>
wrote in the message <email@example.com>:
> The only sane way to do an arithmetic right shift on a sign-magnitude
> machine is a shift that doesn't involve the sign bit. The standard
> defintion of 2/ for such a machine is Just Plain Wrong.
Two more examples of number representations some bits of which
must remain untouched are:
firstname.lastname@example.org (Michael L Gassanenko) wrote
in the message <email@example.com>:
> 1) a system that represent integers as floating point numbers.
> I heard about at least one such system (IIRC pre-ANS).
> 2) a system that uses shadow bits for run-time type information.
> I use one such system as a cross-compiling host.
The 3rd realistic example of a system that uses an unusual number
representation is a Forth system implemented on a virtual machine
that supports big numbers (each number is represented with as many
bits as is needed), e.g. Forth on top of Scheme.
generated Wed Jul 23 02:53:41 2003mlg