A few days ago, I released an experiment on how Forth might adapt to
a balanced ternary architecture, with an instruction set emulator and
a native FPGA implementation included. In balanced ternary, all
numbers are signed with low-level arithmetic being quite elegant, and
there are new logic operators to explore. If you like to dive in: >https://codeberg.org/Mecrisp/mecrisp-ternary
Matthias Koch <m.cook@gmx.net> writes:
...
|In balanced ternary, a right shift is exactly the same as symmetric |division by powers of three, unlike binary in which right-shifting
|negative two-complement numbers to divide by powers of two gives
|rounding artifacts.
Floored division is not any more a rounding artifact than symmetric
division is. Whether to use floored or symmetric division depends on
the application. That's why we have FM/MOD and SM/REM in the
standard. The Forth-83 committee was so strongly in favour of floored
that they broke compatibility with Forth-79 because of that.
Gforth since 0.7 implements / and other division words where Forth-94
allows the system to choose as floored division words. This means
that in Gforth, "2 /" is equivalent to 2/ (which is defined as a shift
right by 1 bit):
-3 2 / . \ prints -2
-3 2/ . \ prints -2
dxf <dxforth@gmail.com> writes:
On 26/05/2026 4:10 am, Anton Ertl wrote:
Gforth since 0.7 implements / and other division words where Forth-94
allows the system to choose as floored division words. This means
that in Gforth, "2 /" is equivalent to 2/ (which is defined as a shift
right by 1 bit):
-3 2 / . \ prints -2
-3 2/ . \ prints -2
Which is all very nice until beginners ask how that makes any sense ;-)
They don't (I know because I have been teaching Forth beginners for
three decades). That's because negative dividends are rare, and
negative divisors are even rarer. But in those cases where negative dividends occur, floored division usually makes sense, and users
encountering it don't ask.
ANS at least tells you 2* 2/ are bit-shifters with historic, albeit misleading,
names.
The name of 2* is not misleading on architectures with 2s-complement arithmetic. I.e., every architecture designed in the last
half-century (the IBM S/360 is actually 62 years old), and everything
that any existing standard system (for any Forth standard) runs on.
...
ANS at least tells you 2* 2/ are bit-shifters with historic, albeitmisleading,
names.You know I'm a pragmatic guy. Back in the 32 bit era, I tested every
On 26-05-2026 07:53, dxf wrote:
ANS at least tells you 2* 2/ are bit-shifters with historic, albeit misleading,You know I'm a pragmatic guy. Back in the 32 bit era, I tested every single value with both 2* and "2 *" - no difference. So, 2* essentially became "2 *".
names.
Very different story with 2/. So, there is a unique opcode 2/ in 4tH - but not a true 2*. ;-)
On 2/06/2026 7:23 am, Hans Bezemer wrote:
On 26-05-2026 07:53, dxf wrote:
ANS at least tells you 2* 2/ are bit-shifters with historic, albeit misleading,You know I'm a pragmatic guy. Back in the 32 bit era, I tested every single value with both 2* and "2 *" - no difference. So, 2* essentially became "2 *".
names.
Very different story with 2/. So, there is a unique opcode 2/ in 4tH - but not a true 2*. ;-)
In eForth one finds:
: 2* 2 * ;
: 2/ 2 / ;
which rather defeats the purpose of the functions which is speed.
As to what is returned by a bit-shifting 2/ depends on the hardware.
For 2's complement it's floored. For 1's complement it's symmetric.
For signed-magnitude it's ...
On 2/06/2026 7:23 am, Hans Bezemer wrote:
In eForth one finds:
: 2* 2 * ;
: 2/ 2 / ;
which rather defeats the purpose of the functions which is speed.
As to what is returned by a bit-shifting 2/ depends on the hardware.
For 2's complement it's floored. For 1's complement it's symmetric.
For signed-magnitude it's ...
dxf <dxforth@gmail.com> writes:
On 2/06/2026 7:23 am, Hans Bezemer wrote:
In eForth one finds:
: 2* 2 * ;
: 2/ 2 / ;
which rather defeats the purpose of the functions which is speed.
But eForth's purpose is not speed.
As to what is returned by a bit-shifting 2/ depends on the hardware.
For 2's complement it's floored. For 1's complement it's symmetric.
For signed-magnitude it's ...
For sign-magnitude an arithmetic interpretation is that, for positive numbers, it's division by 2, while for negative numbers, it's the
average between the number and -2^(n-1) (where n is the number of bits
in a cell). It's not very useful for sign-magnitude, but given that sign-magnitude and ones-complement have died out long ago and never
had Forth systems, who cares.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 70 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 01:17:09 |
| Calls: | 949 |
| Calls today: | 1 |
| Files: | 1,325 |
| Messages: | 280,983 |