-1a = -3
b = 10
print( a // b )
These Pythoneers are indeed impudent.
Fortumately the creators of (most of) DOS Forths
and CPU designers themselves shared my opinion.
Only a few examples from within Linux console:
Gforth: -3 10 / . -1 ok
PForth: -3 10 / . 0 ok
ciforth: S[ ] OK -3 10 / .
0 ESP32Forth: --> -3 10 / . -1 ok
TCL: % expr -3 / 10
-1
ANSI-C: printf("%d\n", -3 / 10) gives output 0
Guys, whatever you can write about floored/non-floored
division -- it's nothing more than kind of "dialectic".
When one divides -3 by 10 the result CANNOT be higher/lower
than 0, because there's larger difference between -10 and -3
than between 0 and -3. Simple.
The -1 result is contrary to logic. It's nonsense.
From what I see even TCL is sick for this "floorness",
not just quite a few Forths.
Actually I agree with gForth and Python that a / that is compatible
with FM/MOD is preferable. Changing it in ciforth is a major change,
so that it has to go with a change of the primary version number
(now 5.5.1) It has to wait for version 6.#.# .
Guys, whatever you can write about floored/non-floored
division -- it's nothing more than kind of "dialectic".
When one divides -3 by 10 the result CANNOT be higher/lower
than 0, because there's larger difference between -10 and -3
than between 0 and -3. Simple.
The -1 result is contrary to logic. It's nonsense.
If you prefer symmetric division, standard Forth provides SM/REM. In
addition, the development version of Gforth provides a complete set of
symmetric (and floored) words complementing the standard
(implementation-defined ones):
Symmetric: /s mods /mods */mods */s
Floored: /f modf /modf */modf */f
1. Which version? 0.7.3 -- described as
"Latest release" doesn't know that:
2. I guess (looking at these words) that there's
a "switch" implemented, that "vectorizes" usual
/ mod etc. using these two sets?
albert@spenarnc.xs4all.nl wrote:
Actually I agree with gForth and Python that a / that is compatible
with FM/MOD is preferable. Changing it in ciforth is a major change,
so that it has to go with a change of the primary version number
(now 5.5.1) It has to wait for version 6.#.# .
In over 40 years of using Forth, I remember only a single instance
where I had a problem in a non-benchmark situation.
-marcel
ANSI-C: printf("%d\n", -3 / 10) gives output 0
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 475 |
Nodes: | 16 (2 / 14) |
Uptime: | 22:51:36 |
Calls: | 9,488 |
Calls today: | 7 |
Files: | 13,617 |
Messages: | 6,121,103 |