Discussion:
Negative number division
Add Reply
LIT
2024-06-01 18:19:32 UTC
Reply
Permalink
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.
minforth
2024-06-01 18:40:09 UTC
Reply
Permalink
There is a totally unknown esoteric language called Python:

MicroPython v1.19.1 on 2022-11-05; win32 [GCC 6.3.0] version
Use Ctrl-D to exit, Ctrl-E for paste mode
a = -3
b = 10
print( a // b )
-1

How dare they!
LIT
2024-06-01 19:58:29 UTC
Reply
Permalink
These Pythoneers are indeed impudent.
Fortumately the creators of (most of) DOS Forths
and CPU designers themselves shared my opinion.
a***@spenarnc.xs4all.nl
2024-06-01 20:17:45 UTC
Reply
Permalink
Post by LIT
These Pythoneers are indeed impudent.
Fortumately the creators of (most of) DOS Forths
and CPU designers themselves shared my opinion.
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.#.# .

Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat purring. - the Wise from Antrim -
dxf
2024-06-02 02:44:21 UTC
Reply
Permalink
Post by a***@spenarnc.xs4all.nl
Post by LIT
These Pythoneers are indeed impudent.
Fortumately the creators of (most of) DOS Forths
and CPU designers themselves shared my opinion.
Actually I agree with gForth and Python that a / that is compatible
with FM/MOD is preferable.
You would make a good priest. There is room only for one god - mine.
mhx
2024-06-02 06:37:44 UTC
Reply
Permalink
Post by a***@spenarnc.xs4all.nl
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
a***@spenarnc.xs4all.nl
2024-06-02 19:49:37 UTC
Reply
Permalink
Post by mhx
Post by a***@spenarnc.xs4all.nl
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.
Actually there is only a problem if you are not aware of different
possibities how / and MOD is defined.
If you are used to one system and you use it consistently you
hardly notice.
Post by mhx
-marcel
Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat purring. - the Wise from Antrim -
dxf
2024-06-03 01:55:29 UTC
Reply
Permalink
Post by a***@spenarnc.xs4all.nl
Post by mhx
Post by a***@spenarnc.xs4all.nl
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.
Actually there is only a problem if you are not aware of different
possibities how / and MOD is defined.
If you are used to one system and you use it consistently you
hardly notice.
ANS-Forth's mish-mash largely rules out using / and MOD for negative
arguments. When the latter is needed (which is infrequent) I'll use
FM/MOD or SM/REM as appropriate. That's preferable to the confusing
personality redefinitions ANS offered up.
dxf
2024-06-02 02:29:02 UTC
Reply
Permalink
Post by LIT
...
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.
By 'logic' you mean expectation? Floored-division happens to give
the expected (aka desired) result when it comes to problems involving
modulus. Most times I don't divide negative numbers so any forth
will do.
LIT
2024-06-02 06:52:57 UTC
Reply
Permalink
Post by dxf
By 'logic' you mean expectation?
Maybe rather "common sense". What is
the difference between common sense
and dialectic? In short: common sense
requires no "buts".
dxf
2024-06-02 08:46:21 UTC
Reply
Permalink
Post by LIT
Post by dxf
By 'logic' you mean expectation?
Maybe rather "common sense". What is
the difference between common sense
and dialectic? In short: common sense
requires no "buts".
'common sense' is experience common to all. Mathematics is taught
and so is negative numbers.
Ron AARON
2024-06-02 05:35:33 UTC
Reply
Permalink
8th: -3 10 / .
-0.30000
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.
Anton Ertl
2024-06-02 11:23:26 UTC
Reply
Permalink
Post by LIT
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

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: https://forth-standard.org/
EuroForth 2023: https://euro.theforth.net/2023
LIT
2024-06-02 12:10:13 UTC
Reply
Permalink
Post by Anton Ertl
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
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:

-3 10 / . -1 ok
-3 10 /s .
:2: Undefined word
-3 10 >>>/s<<< .
Backtrace: [..]

2. I guess (looking at these words) that there's
a "switch" implemented, that "vectorizes" usual
/ mod etc. using these two sets?
ahmed
2024-06-02 12:16:21 UTC
Reply
Permalink
Hi,

Gforth 0.7.9_20200709
Authors: Anton Ertl, Bernd Paysan, Jens Wilke et al., for more type
`authors'
Copyright © 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<https://gnu.org/licenses/gpl.html>
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `help' for basic help
ok
ok
ok
-3 10 / . -1 ok
-3 10 /s . 0 ok
-3 10 /f . -1 ok

It works.

Ahmed
Anton Ertl
2024-06-02 16:00:46 UTC
Reply
Permalink
Post by LIT
Post by Anton Ertl
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
Symmetric: /s mods /mods */mods */s
Floored: /f modf /modf */modf */f
1. Which version? 0.7.3 -- described as
Yes. It's in the development version since February 2020.
Post by LIT
2. I guess (looking at these words) that there's
a "switch" implemented, that "vectorizes" usual
/ mod etc. using these two sets?
If you mean that / is a deferred word or somesuch that can be directed
to perform /f or /s (and likewise for MOD /MOD */MOD */), no, that's
not the case, because that is a bad idea. It would change the
behaviour of existing words. E.g., if a piece of code checks whether
/ is floored and then uses it in a definition in a way that is correct
for floored division, that definition would become wrong if / is
redirected to be symmetric. E.g.:

-1 3 / -1 [if]
: /s
2dup /
... \ add 1 in some cases
;
[else]
synonym /s /
[then]

Therefore, Gforth statically defines, e.g.

' /f alias /

If you want a symmetric /, you can define

' /s alias /

However, if your program relies on symmetric behaviour, it's better to
call /S, and to define that on systems that do not have it; on systems
with symmetric /, the definition would be as simple as

synonym /s /

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: https://forth-standard.org/
EuroForth 2023: https://euro.theforth.net/2023
LIT
2024-06-02 19:37:04 UTC
Reply
Permalink
Post by Anton Ertl
If you mean that / is a deferred word or somesuch that can be directed
to perform /f or /s (and likewise for MOD /MOD */MOD */), no, that's
not the case, because that is a bad idea. It would change the
behaviour of existing words. E.g., if a piece of code checks whether
/ is floored and then uses it in a definition in a way that is correct
for floored division, that definition would become wrong if / is
redirected to be symmetric. E.g.: [..]
Actually I assumed the Gforth's code has been modified
to internally use explicitly /f (or /s) etc., therefore there
wouldn't be a need for such check. And the usual / MOD etc. could
then be left for user's decision, whether they will work one way,
or the other.
Post by Anton Ertl
However, if your program relies on symmetric behaviour, it's better to
call /S, and to define that on systems that do not have it; on systems
with symmetric /, the definition would be as simple as
synonym /s /
Thanks, downloaded that development version, I'll try that.
LIT
2024-06-04 22:37:42 UTC
Reply
Permalink
Post by Anton Ertl
Yes. It's in the development version since February 2020.
Not possible to install; it requires some "esoteric" library,
which I don't need for anything but especially for Gforth (pipewire).
That library requires -- of course -- another library:
./meson.build:1:0: ERROR: Meson version is 0.59.4 but project requires
Post by Anton Ertl
= 0.61.1
From what I see, the devs' assumption is: "everyone surely are using
Fedora 'bleeding edge' with all newest available libraries installed".
No, guys -- some use just Slackware 15.0, not taking too much care
about some "exotic" libraries neither their newest versions.
d***@comcast.net
2024-08-25 21:10:43 UTC
Reply
Permalink
Sorry for delay, I misplaced this and just re-found it.

On Sat, 1 Jun 2024 18:19:32 +0000, ***@gmail.com (LIT) wrote:
...
Post by LIT
ANSI-C: printf("%d\n", -3 / 10) gives output 0
"ANSI C" is ambiguous. When the first C standard was created in 1989
by ASC X3 J11 people called it ANSI. That standard was then adopted
with only editorial changes by "ISO" (technically, ISO/IEC JTC1 SC22).
Since then several revised standards have been _jointly_ developed by
the ANSI subcommittee (now mutated into INCITS) and the ISO one, and
published by ANSI, ISO, and other national members.

Some people reserve the name "ANSI C" only for C89/90, while some
apply it to the newer versions in which ANSI participates but no
longer controls. This matters here because C89/90 made rounding of
division with a negative operand implementation-dependent (and
required % for remainder to be consistent with division always so with
a negative operand it was also implementation-dependent). C99 and
later -- which per above might or might not be called "ANSI C" --
standardized division rounding as toward-zero (and % consistent).

Current C implementations follow the newer standards, unless you
resurrect an ancient one, like Borland Turbo C on an emulated (i.e.
fake) PC/AT with MSDOS 2 or something like that.

Loading...