• FP number syntax (was: ANN: DX-Forth 4.57)

    From Anton Ertl@21:1/5 to dxf on Wed Dec 25 11:36:16 2024
    XPost: comp.os.cpm

    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.html
    comp.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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From albert@spenarnc.xs4all.nl@21:1/5 to Anton Ertl on Wed Dec 25 16:50:16 2024
    In article <2024Dec25.123616@mips.complang.tuwien.ac.at>,
    Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
    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.

    A more simple approach is:
    stick to case-sensitive.
    In decimal 1E is a floating point number, as long as the floating
    point number is loaded.
    In HEX 1E is not a floating point number.
    1e is not reconfignized anyhow, unless BASE is incremented a lot.

    For hex instead use _ for the exponent sign.
    1E_0 OK
    .S
    S[ ] OK
    DECIMAL
    .FS
    3.000000000000000000E1

    S[ ] OK

    The advantage is that hex allows to represent floating point
    numbers exactly.

    (You guessed it, it is the ciforth way.)


    - anton
    --
    Temu exploits Christians: (Disclaimer, only 10 apostles)
    Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style Wall
    Art For Home, Office And Garden Decor - Perfect For Windows, Bars,
    And Gifts For Friends Family And Colleagues.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)