Sujet : FP number syntax (was: ANN: DX-Forth 4.57)
De : anton (at) *nospam* mips.complang.tuwien.ac.at (Anton Ertl)
Groupes : comp.os.cpm comp.lang.forthSuivi-à : comp.lang.forthDate : 25. Dec 2024, 12:36:16
Autres entêtes
Organisation : Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID : <2024Dec25.123616@mips.complang.tuwien.ac.at>
References : 1 2 3 4 5 6
User-Agent : xrn 10.11
dxf <
dxforth@gmail.com> writes:
On 25/12/2024 3:06 pm, John wrote:
And not sure how to enter decimals, I though maybe entering a ".0" after my numbers would flag them as reals not integers, but...
3.14 2.96 <return> does not put both numbers on the stack
>
Those would be illegal numbers - neither reals nor integers.
At least in standard Forth. In traditional Forth 3.14 and 2.96 are
double-cell integers (with the value #314 and #296). And backwards
compatibility demands that they should not be recognized as FP values.
In Gforth snapshots from the last few years (not available for CP/M,
sorry) you get the following when you type in "3.14":
*terminal*:2:1: warning: '3.14' is a double-cell integer; type `help' for more info ok 2
HELP then says:
To input floating-point numbers, use an exponent, e.g. "1e".
To input double-cell integers without warnings, use a base-prefix and put
the '.' only in the last position, e.g. "#1.".
But you can also do
' rec-float ' forth-recognize defer@ >stack
and then you can do things like
3.14 2.96 f* cr f.
which produces the following output:
*terminal*:18:1: warning: float without 'e' is non-standard
*terminal*:18:6: warning: float without 'e' is non-standard
9.2944 ok
You can also disable the warnings with "warnings off".
Followups set to comp.lang.forth.
- anton
-- M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.htmlcomp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html New standard: https://forth-standard.org/ EuroForth 2024: https://euro.theforth.net