• F.N floating point format word

    From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Fri Oct 2 10:30:42 2026
    From Newsgroup: comp.lang.forth

    This message is for <peter@noreply.tin.it>

    For some reason I can't see your message from yesterday in the other
    thread, to which this reply would have been appropriate.

    I revised kForth-64 (@commit f6e9ddb) and kForth-32 (@commit 2393bb4) to
    fix my bug in REPRESENT. REPRESENT now throws an error (-24, Invalid
    Numeric Argument) when the argument u (number of significant digits) is
    not in the range 0 < u < 769.

    Additionally, SET-PRECISION also throws the same error (-24) when the
    argument is not in the range 0 < u < 769.

    I've also revised your F.N code to work with both separate fp stack and unified data/fp stack systems (since kForth-32 and kForth-Win32 still
    use a unified stack). F.N passes all of my tests on both kForth-64/32.
    It will be included within a future version of my strings package (strings.4th), unless you have any objections.

    A separate string output word is needed, which would be the primary
    factor of F.N. I can modify your code to do this, but if you decide to
    this then there is no need for duplication of effort.

    --
    Krishna

    P.S. please obtain the source code for the new commits from

    https://github.com/mynenik

    at the moment. I haven't yet had the chance to make new development
    archive files for ccreweb.org.





    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Fri Oct 2 17:49:21 2026
    From Newsgroup: comp.lang.forth

    On Fri, 2 Oct 2026 10:30:42 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    This message is for <peter@noreply.tin.it>

    For some reason I can't see your message from yesterday in the other
    thread, to which this reply would have been appropriate.

    I revised kForth-64 (@commit f6e9ddb) and kForth-32 (@commit 2393bb4) to
    fix my bug in REPRESENT. REPRESENT now throws an error (-24, Invalid
    Numeric Argument) when the argument u (number of significant digits) is
    not in the range 0 < u < 769.

    Additionally, SET-PRECISION also throws the same error (-24) when the argument is not in the range 0 < u < 769.

    I've also revised your F.N code to work with both separate fp stack and unified data/fp stack systems (since kForth-32 and kForth-Win32 still
    use a unified stack). F.N passes all of my tests on both kForth-64/32.
    It will be included within a future version of my strings package (strings.4th), unless you have any objections.

    A separate string output word is needed, which would be the primary
    factor of F.N. I can modify your code to do this, but if you decide to
    this then there is no need for duplication of effort.

    Good to hear that it works now! Of course you are welcome to use and modify
    the code.

    I have actually now also done a string printing version. It uses a string printing wordset I use in the LXF64 code generator to produce assembler
    text. It basically just adds a S in front of the ordinary words. The
    words are: SEMIT, STYPE, S., SFILL. You can see that it is quite easy to make
    a string version from a working screen printing version.

    I will write up an ANS implementation of them and post that and (F.N)
    on this thread.

    I have also done some micro optimizations on F.N

    BR
    Peter


    --
    Krishna

    P.S. please obtain the source code for the new commits from

    https://github.com/mynenik

    at the moment. I haven't yet had the chance to make new development
    archive files for ccreweb.org.







    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Fri Oct 2 16:33:22 2026
    From Newsgroup: comp.lang.forth

    On 10/2/26 10:49 AM, peter wrote:
    On Fri, 2 Oct 2026 10:30:42 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    This message is for <peter@noreply.tin.it>

    For some reason I can't see your message from yesterday in the other
    thread, to which this reply would have been appropriate.

    I revised kForth-64 (@commit f6e9ddb) and kForth-32 (@commit 2393bb4) to
    fix my bug in REPRESENT. REPRESENT now throws an error (-24, Invalid
    Numeric Argument) when the argument u (number of significant digits) is
    not in the range 0 < u < 769.

    Additionally, SET-PRECISION also throws the same error (-24) when the
    argument is not in the range 0 < u < 769.

    I've also revised your F.N code to work with both separate fp stack and
    unified data/fp stack systems (since kForth-32 and kForth-Win32 still
    use a unified stack). F.N passes all of my tests on both kForth-64/32.
    It will be included within a future version of my strings package
    (strings.4th), unless you have any objections.

    A separate string output word is needed, which would be the primary
    factor of F.N. I can modify your code to do this, but if you decide to
    this then there is no need for duplication of effort.

    Good to hear that it works now! Of course you are welcome to use and modify the code.

    I have actually now also done a string printing version. It uses a string printing wordset I use in the LXF64 code generator to produce assembler
    text. It basically just adds a S in front of the ordinary words. The
    words are: SEMIT, STYPE, S., SFILL. You can see that it is quite easy to make a string version from a working screen printing version.

    I will write up an ANS implementation of them and post that and (F.N)
    on this thread.

    I have also done some micro optimizations on F.N

    One more thing to check more closely is the case of n = 0 decimal
    places. I believe the rule for whether or not the decimal point is
    appended depends on whether or not the rounded result is the same as the truncated result. My tests may not be correct for this case.

    I am comparing the string output with sprintf() in C, leading me to
    believe I need to go back and re-examine my tests for the case of n=0.

    --
    Krishna

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Sat Oct 3 00:07:31 2026
    From Newsgroup: comp.lang.forth

    On Fri, 2 Oct 2026 16:33:22 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    On 10/2/26 10:49 AM, peter wrote:
    On Fri, 2 Oct 2026 10:30:42 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    This message is for <peter@noreply.tin.it>

    For some reason I can't see your message from yesterday in the other
    thread, to which this reply would have been appropriate.

    I revised kForth-64 (@commit f6e9ddb) and kForth-32 (@commit 2393bb4) to >> fix my bug in REPRESENT. REPRESENT now throws an error (-24, Invalid
    Numeric Argument) when the argument u (number of significant digits) is
    not in the range 0 < u < 769.

    Additionally, SET-PRECISION also throws the same error (-24) when the
    argument is not in the range 0 < u < 769.

    I've also revised your F.N code to work with both separate fp stack and
    unified data/fp stack systems (since kForth-32 and kForth-Win32 still
    use a unified stack). F.N passes all of my tests on both kForth-64/32.
    It will be included within a future version of my strings package
    (strings.4th), unless you have any objections.

    A separate string output word is needed, which would be the primary
    factor of F.N. I can modify your code to do this, but if you decide to
    this then there is no need for duplication of effort.

    Good to hear that it works now! Of course you are welcome to use and modify the code.

    I have actually now also done a string printing version. It uses a string printing wordset I use in the LXF64 code generator to produce assembler text. It basically just adds a S in front of the ordinary words. The
    words are: SEMIT, STYPE, S., SFILL. You can see that it is quite easy to make
    a string version from a working screen printing version.

    I will write up an ANS implementation of them and post that and (F.N)
    on this thread.

    I have also done some micro optimizations on F.N

    One more thing to check more closely is the case of n = 0 decimal
    places. I believe the rule for whether or not the decimal point is
    appended depends on whether or not the rounded result is the same as the truncated result. My tests may not be correct for this case.

    I am comparing the string output with sprintf() in C, leading me to
    believe I need to go back and re-examine my tests for the case of n=0.

    --
    Krishna


    I have actually changed to always print out the . in all cases.
    I did this for consistency. but it is changeable.

    I have anyway tested my string writing version on kForth64.
    It works well on kForth-fast but not kForth. There it stops at the first
    test and complains about a value not being of addr type!

    This uses my string writing words. These us a cell counted string as
    storage. A 255 max traditional char based counted string will not work.
    In my system I use a word (16bits) counted strings. But the cell based
    is more portable. You can of course change this to what suits your
    system best.

    I use a circular string buffer with 16 1024 strings instead of allocating
    each string. It is simple so you will understand it.

    I have also changed the sign printing to also print a space in front
    of a positive number, it looks better when numbers are in a column.
    It has been optimized to : .sign 13 and 32 + semit ;

    Here is the code that runs on kForth64-fast

    \ Cell counted string words
    -1 [if]
    : xcount ( addr -- addr+cell count )
    dup @ swap cell+ swap ;

    : xappend ( addr n addr2 -- ) \ append string to string at addr2
    2dup 2>r
    xcount + swap cmove
    r> xcount r> + swap 1 cells - ! ;

    : xplace ( addr n addr2 -- ) \ place string to string at addr2
    dup 0 swap !
    xappend ;

    : cxappend ( c addr2 -- ) \ append c to end of string at addr2
    dup >r xcount + c!
    1 r> +! ;

    : cxfill ( n c addr2 -- ) \ append n cs to the end of string at addr2
    >r over r@ swap >r
    xcount + -rot fill
    r> r> +! ;

    \ redirect output to memory

    VARIABLE (string-buf)

    : sbuf (string-buf) @ ;

    : sbuf> sbuf xcount ;

    : init-string-buf ( addr -- addr-old) \ retrieve addr-old from
    (string-buf) @ swap \ string-buf, place addr there
    dup 0 swap ! (string-buf) ! ;

    : >sbuf> ( addr-old -- addr len ) \ retrieve addr len and set
    >r sbuf xcount \ string-buf to old value
    r> (string-buf) ! ;

    : semit ( c -- ) \ type to buffer
    sbuf cxappend ;

    : stype ( addr len -- )
    sbuf xappend ;

    : sfill ( n c -- ) \ fill buffer with n cs
    sbuf cxfill ;

    : nl 10 semit ;

    : s. s>d swap over dabs <# #s rot sign #> stype ;

    \ : strbuf 1024 allocate throw ;

    variable (strindx)
    create (strbuf) 16384 allot

    : strbuf ( -- addr ) \ circular buffer with 16 1024 buffers
    (strindx) dup >r @ 1024 + 16384 mod dup r> ! (strbuf) + ;

    [then]
    \ print float to n decimals

    create fpad 1024 allot

    : .sign ( f -- )
    13 and 32 + semit ; \ prints bl for positive
    \ if 32 semit then ; \ use this to only print -

    : .zeros ( n -- )
    48 sfill ;

    : s"0." s" 0." stype ;

    : one-or-zero ( F:fp -- ) \ exp<=0 n=0 round to +-1 or 0
    fround>s 48 + semit ; \ kForth version
    \ fround f>s 48 + semit ; \ ANS version

    : f.n-case-00 ( F:fp -- ) \ exp<=0 n=0 round to +-1 or 0
    one-or-zero 46 semit ;

    : f.n-case-e+n<0 ( F:fp n -- )
    fdrop
    s"0." .zeros ;

    : f.n-case-e+n=0 ( F:fp n e -- )
    fdup abs s>f falog f* fswap \ prepare fp for rounding
    1- f.n-case-e+n<0 \ print 1 less zero
    one-or-zero ;

    : f.n-case-e>0 ( F:fp n e -- )
    over + \ n e+n
    fpad 1024 48 fill
    fpad swap represent 2drop \ n e'
    dup >r \ n e' r: e'
    fpad swap stype 46 semit \ n
    fpad r> + \ n fpad+e'
    swap 0 max stype ;

    : f.n-case-e<=0 ( F:fp n e -- )
    over + 1 max \ n e+n
    fpad 1024 48 fill
    fpad swap represent 2drop \ n e'
    dup >r \ n e' r: e'
    s"0." abs .zeros
    fpad swap r> + \ fpad n+e'
    stype ;

    : (f.n) ( F:fp n -- )
    strbuf init-string-buf >r \ save old string on rs
    fdup fpad 32 represent \ find exp and sign
    swap .sign fabs \ print the sign
    0= if 2drop fdrop
    fpad 3 stype else \ print nan or inf
    over 0< if
    swap over 1- negate max swap else \ limit negative n
    swap over 1024 swap - min swap then \ limit positive n
    2dup 0 <= swap 0= and \ n e f
    if 2drop f.n-case-00 else
    2dup + 0<
    if drop f.n-case-e+n<0 else
    2dup + 0=
    if f.n-case-e+n=0 else
    dup 0>
    if f.n-case-e>0 else
    f.n-case-e<=0
    then then then then then r> >sbuf> ;

    : f.n (f.n) type space ;


    \ 0 [IF]
    \ Test cases
    : testing cr begin refill while source 2dup type space evaluate cr repeat ; testing
    0.9e 0 f.n
    0.3e 0 f.n
    -0.9e 0 f.n
    -0.3e 0 f.n

    0.123e 0 f.n
    0.123e-1 1 f.n
    0.123e-2 2 f.n
    0.123e-3 3 f.n

    0.823e 0 f.n
    0.823e-1 1 f.n
    0.823e-2 2 f.n
    0.823e-3 3 f.n

    0.1368e 3 f.n
    -0.1368e-1 3 f.n
    0.1368e-2 3 f.n
    -0.1368e-3 3 f.n
    0.1368e-4 3 f.n

    -0.8368e 3 f.n
    -0.8368e-1 3 f.n
    -0.8368e-2 3 f.n
    -0.8368e-3 3 f.n
    -0.8368e-4 3 f.n

    126.8567e 3 f.n
    126.8567e 2 f.n
    126.8567e 1 f.n
    126.8567e 0 f.n
    126.8567e -1 f.n
    126.8567e -2 f.n
    126.8567e -3 f.n

    99.995e 3 f.n
    99.995e 2 f.n
    99.995e 1 f.n

    5.2345678e-1 10 f.n
    5.2345678e-2 10 f.n
    5.2345678e-3 10 f.n
    5.2345678e-4 10 f.n
    5.2345678e-5 10 f.n
    5.2345678e-6 10 f.n
    5.2345678e-7 10 f.n
    5.2345678e-8 10 f.n
    5.2345678e-9 10 f.n
    5.2345678e-10 10 f.n
    5.2345678e-11 10 f.n
    5.2345678e-12 10 f.n

    -1e 0e f/ 5 f.n
    0e 0e f/ 5 f.n

    \ Krishna Myneni tests

    0.0051e 0 f.n
    0.0051e 1 f.n
    0.0051e 2 f.n
    0.0051e 3 f.n
    0.0051e 4 f.n
    0.0051e 5 f.n
    0.0051e 17 f.n
    2.0e-15 17 f.n

    0.0e 0 f.n
    0.1e 0 f.n
    0.2e 0 f.n
    0.4e 0 f.n
    0.5e 0 f.n
    0.51e 0 f.n

    0.500000000000000001e 0 f.n
    0.50000000000000001e 0 f.n
    0.5000000000000001e 0 f.n

    0.6e 0 f.n
    0.9e 0 f.n
    1.0e 0 f.n
    1.4e 0 f.n
    1.4999999e 0 f.n
    1.5e 0 f.n
    2.5e 0 f.n
    3.5e 0 f.n

    -1100.2e 0 f.n
    -1100.5e 0 f.n
    -1101.5e 0 f.n
    -1102.5e 0 f.n

    2.01682663070034556e16 0 f.n
    2.01682663070034556e16 20 f.n

    0.5e 25 f.n
    0.625e 25 f.n
    0.625e 25 f.n

    -0.6e 4 f.n
    -0.6e 16 f.n
    -0.6e 17 f.n
    -0.6e 23 f.n
    -0.6e 25 f.n

    9.1e 3 f.n
    9.51e 1 f.n
    9.55e 1 f.n
    -9.66e 1 f.n

    99.995e 2 f.n
    99.625e 2 f.n
    96.62500000000001e 2 f.n

    1.247777e3 0 f.n
    1.247777e3 1 f.n
    1.247777e3 2 f.n
    1.247777e3 3 f.n

    -5.0999913335e0 4 f.n
    -5.0999913335e0 5 f.n
    -5.0999913335e0 6 f.n
    -5.0999913335e0 7 f.n
    -5.0999913335e0 8 f.n
    -5.0999913335e0 9 f.n

    9.599999999e8 0 f.n

    \ test large arguments
    123e300 10 f.n
    123e-300 305 f.n
    \ [THEN]

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Fri Oct 2 17:36:06 2026
    From Newsgroup: comp.lang.forth

    On 10/2/26 5:07 PM, peter wrote:
    On Fri, 2 Oct 2026 16:33:22 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    ...

    One more thing to check more closely is the case of n = 0 decimal
    places. I believe the rule for whether or not the decimal point is
    appended depends on whether or not the rounded result is the same as the
    truncated result. My tests may not be correct for this case.

    I am comparing the string output with sprintf() in C, leading me to
    believe I need to go back and re-examine my tests for the case of n=0.

    ...

    I have actually changed to always print out the . in all cases.
    I did this for consistency. but it is changeable.


    Will check how C and Fortran behave and whether or not that adheres to convention in the sciences first, before coming to any conclusion.
    I have anyway tested my string writing version on kForth64.
    It works well on kForth-fast but not kForth. There it stops at the first
    test and complains about a value not being of addr type!

    Will check it out. It probably needs a @ replaced by a@ where an address
    is being fetched from a variable for the non-fast version of kForth due
    to run-time type checking. The type checking is disabled in the fast
    version.

    This uses my string writing words. These us a cell counted string as
    storage. A 255 max traditional char based counted string will not work.
    In my system I use a word (16bits) counted strings. But the cell based
    is more portable. You can of course change this to what suits your
    system best.


    That will not be an issue.
    I use a circular string buffer with 16 1024 strings instead of allocating each string. It is simple so you will understand it.

    Thanks ... I think :-)

    I have also changed the sign printing to also print a space in front
    of a positive number, it looks better when numbers are in a column.
    It has been optimized to : .sign 13 and 32 + semit ;

    Here is the code that runs on kForth64-fast

    ...
    Thank you.

    --
    Krishna

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Sat Oct 3 05:37:49 2026
    From Newsgroup: comp.lang.forth

    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    I believe the rule for whether or not the decimal point is
    appended depends on whether or not the rounded result is the same as the >truncated result.

    I have never heard about such a rule.

    Gforth's E.P only displays the decimal point if it is necessary to
    display a digit after the decimal point. E.g.:

    127.9e 2 e.p \ prints 128e

    This example demonstrates another principle: Because displaying the
    number in exponential format as "1.3e2" would be longer, it chooses to
    use the non-exponential format, and given that that shows three
    mantissa digits, E.P also shows to three digits precision rather than
    the two that were asked for. It does this in a rule-of-thumb way,
    which may be off in some cases.

    Given that E. and E.EXACT are based on E., they work the same way.
    E.g., the smallest positive FP number is shown by E. as 5e-324.

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Sat Oct 3 06:06:00 2026
    From Newsgroup: comp.lang.forth

    On 10/3/26 6:02 AM, Krishna Myneni wrote:
    On 10/3/26 12:37 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    I believe the rule for whether or not the decimal point is
    appended depends on whether or not the rounded result is the same as the >>> truncated result.

    I have never heard about such a rule.


    I remember a rule for expressing the significance of the last digit for fixed point formatting with zero decimal places. Since we are using
    round to nearest explicitly, we know the fractional part is always
    within the bounds +/- 0.5 and that the last digit for the n = 0 case is significant.

    The presence of the trailing decimal point for n = 0 can be used as an explicit indicator that rounding was used instead of truncation for n = 0.

    Having said that, it appears that C's sprintf() always omits the decimal point for the format "%.0lf" based on my tests with gcc, even when
    rounding to nearest, so there appears to be no such convention for fixed point formatting floating point numbers. I prefer using the trailing
    decimal point for F.N when n is specified to be zero.
    Gforth's E.P only displays the decimal point if it is necessary to
    display a digit after the decimal point.-a E.g.:

    127.9e 2 e.p \ prints 128e
    What is the 2? It does not appear to be either the precision (number of
    significant digits) or the number of decimal places?


    Sorry, thunderbird appears to be screwing up the quoted and unquoted
    parts of the message. I need to find a better news reader client.

    --
    KM

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Sat Oct 3 07:23:31 2026
    From Newsgroup: comp.lang.forth

    On 10/3/26 6:02 AM, Krishna Myneni wrote:
    On 10/3/26 12:37 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    I believe the rule for whether or not the decimal point is
    appended depends on whether or not the rounded result is the same as the >>> truncated result.

    I have never heard about such a rule.


    I remember a rule for expressing the significance of the last digit for fixed point formatting with zero decimal places. Since we are using
    round to nearest explicitly, we know the fractional part is always
    within the bounds +/- 0.5 and that the last digit for the n = 0 case is significant.

    The presence of the trailing decimal point for n = 0 can be used as an explicit indicator that rounding was used instead of truncation for n = 0.

    Having said that, it appears that C's sprintf() always omits the decimal point for the format "%.0lf" based on my tests with gcc, even when
    rounding to nearest, so there appears to be no such convention for fixed point formatting floating point numbers. I prefer using the trailing
    decimal point for F.N when n is specified to be zero.


    Another advantage of having the trailing decimal point for the output of
    F.N with n = 0 is that an implementation of a fixed point output word
    which uses truncation rather than round to nearest can be distinguished
    by not providing a trailing decimal point when n = 0.

    --
    KM

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Sat Oct 3 15:47:19 2026
    From Newsgroup: comp.lang.forth

    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    127.9e 2 e.p \ prints 128e
    What is the 2? It does not appear to be either the precision (number of >significant digits) or the number of decimal places?

    It is the precision the user asks for, but if three digits of mantissa
    are printed anyway (because it's shorter than "1.3e2"), the number is
    shown with precision 3.

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Sat Oct 3 06:02:05 2026
    From Newsgroup: comp.lang.forth

    On 10/3/26 12:37 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    I believe the rule for whether or not the decimal point is
    appended depends on whether or not the rounded result is the same as the
    truncated result.

    I have never heard about such a rule.


    I remember a rule for expressing the significance of the last digit for
    fixed point formatting with zero decimal places. Since we are using
    round to nearest explicitly, we know the fractional part is always
    within the bounds +/- 0.5 and that the last digit for the n = 0 case is significant.

    The presence of the trailing decimal point for n = 0 can be used as an explicit indicator that rounding was used instead of truncation for n = 0.

    Having said that, it appears that C's sprintf() always omits the decimal
    point for the format "%.0lf" based on my tests with gcc, even when
    rounding to nearest, so there appears to be no such convention for fixed
    point formatting floating point numbers. I prefer using the trailing
    decimal point for F.N when n is specified to be zero.
    > Gforth's E.P only displays the decimal point if it is necessary to
    display a digit after the decimal point. E.g.:

    127.9e 2 e.p \ prints 128e
    What is the 2? It does not appear to be either the precision (number of
    significant digits) or the number of decimal places?

    --
    Krishna
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Sat Oct 3 21:16:29 2026
    From Newsgroup: comp.lang.forth

    On 10/3/26 10:47 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    127.9e 2 e.p \ prints 128e
    What is the 2? It does not appear to be either the precision (number of
    significant digits) or the number of decimal places?

    It is the precision the user asks for, but if three digits of mantissa
    are printed anyway (because it's shorter than "1.3e2"), the number is
    shown with precision 3.


    Ah, thanks.


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Sun Oct 4 03:03:52 2026
    From Newsgroup: comp.lang.forth

    On 10/3/26 6:02 AM, Krishna Myneni wrote:
    On 10/3/26 12:37 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    I believe the rule for whether or not the decimal point is
    appended depends on whether or not the rounded result is the same as the >>> truncated result.

    I have never heard about such a rule.


    I remember a rule for expressing the significance of the last digit for fixed point formatting with zero decimal places. Since we are using
    round to nearest explicitly, we know the fractional part is always
    within the bounds +/- 0.5 and that the last digit for the n = 0 case is significant.
    ...

    Here is a reference for the use of the trailing decimal point to
    indicate the significance of the last digit of the integer:

    https://www.purplemath.com/modules/rounding2.htm

    === begin quote ===
    560 has two significant digits: the last zero is just a placeholder.

    560. : notice that "point" after the zero! This has three significant
    digits, because the decimal point tells us that the measurement was made
    to the nearest unit, so the zero is not just a placeholder.
    === end quote ==

    The implied uncertainty for the case of no trailing decimal point "560"
    is +/- 5, while the implied uncertainty with the trailing decimal point
    "560." is +/-0.5.

    --
    KM

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Sun Oct 4 03:37:41 2026
    From Newsgroup: comp.lang.forth

    On 10/4/26 3:03 AM, Krishna Myneni wrote:
    On 10/3/26 6:02 AM, Krishna Myneni wrote:
    On 10/3/26 12:37 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    I believe the rule for whether or not the decimal point is
    appended depends on whether or not the rounded result is the same as
    the
    truncated result.

    I have never heard about such a rule.


    I remember a rule for expressing the significance of the last digit
    for fixed point formatting with zero decimal places. Since we are
    using round to nearest explicitly, we know the fractional part is
    always within the bounds +/- 0.5 and that the last digit for the n = 0
    case is significant.
    ...

    Here is a reference for the use of the trailing decimal point to
    indicate the significance of the last digit of the integer:

    https://www.purplemath.com/modules/rounding2.htm

    === begin quote ===
    560 has two significant digits: the last zero is just a placeholder.

    560. : notice that "point" after the zero! This has three significant digits, because the decimal point tells us that the measurement was made
    to the nearest unit, so the zero is not just a placeholder.
    === end quote ==

    The implied uncertainty for the case of no trailing decimal point "560"
    is +/- 5, while the implied uncertainty with the trailing decimal point "560." is +/-0.5.

    --
    KM


    The trailing decimal point is specifically needed to indicate the
    significance of trailing zeros of the integer.

    From the Wikipedia article on Significant Figures: https://en.wikipedia.org/wiki/Significant_figures

    === begin quote ===
    A decimal point may be placed after the number; for example "1300."
    indicates specifically that trailing zeros are meant to be significant.[7]
    === end quote ===


    This is true for fixed point formatting with rounding to nearest and
    with specified number of decimal places, n = 0.

    If the last digit of the integer is not zero, the use of the trailing
    decimal point is not needed (the implied uncertainty is still +/- 0.5)
    -- the presence or absence of the trailing decimal point does not create
    an ambiguity when the last digit is nonzero.

    gcc's sprintf() with format string "%.0lf" does not following the
    trailing zeros rule for integers e.g. with the number "-1100.2" and zero decimal places, it generates the string "-1100" instead of "-1100."
    which may lead to an ambiguity about whether or not the two trailing
    zeros are significant.



    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Sun Oct 4 09:19:37 2026
    From Newsgroup: comp.lang.forth

    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    On 10/4/26 3:03 AM, Krishna Myneni wrote:
    https://www.purplemath.com/modules/rounding2.htm

    === begin quote ===
    560 has two significant digits: the last zero is just a placeholder.

    560. : notice that "point" after the zero! This has three significant
    digits, because the decimal point tells us that the measurement was made
    to the nearest unit, so the zero is not just a placeholder.
    === end quote ==

    The implied uncertainty for the case of no trailing decimal point "560"
    is +/- 5, while the implied uncertainty with the trailing decimal point
    "560." is +/-0.5.

    --
    KM


    The trailing decimal point is specifically needed to indicate the >significance of trailing zeros of the integer.

    From the Wikipedia article on Significant Figures:
    https://en.wikipedia.org/wiki/Significant_figures

    === begin quote ===
    A decimal point may be placed after the number; for example "1300." >indicates specifically that trailing zeros are meant to be significant.[7] >=== end quote ===


    This is true for fixed point formatting with rounding to nearest and
    with specified number of decimal places, n = 0.

    If the last digit of the integer is not zero, the use of the trailing >decimal point is not needed (the implied uncertainty is still +/- 0.5)
    -- the presence or absence of the trailing decimal point does not create
    an ambiguity when the last digit is nonzero.

    gcc's sprintf() with format string "%.0lf" does not following the
    trailing zeros rule for integers e.g. with the number "-1100.2" and zero >decimal places, it generates the string "-1100" instead of "-1100."
    which may lead to an ambiguity about whether or not the two trailing
    zeros are significant.

    I have seen numbers shown with one digit underlined (probably the last significant one), which would also help for the case when 1300 has
    three significant digits.

    I think that for many uses of FP output words the significant digits
    are not known to the programmer, and any indication of significant
    digits would be misleading.

    After all, FP exists so that most qusers don't have to worry about the
    range of numbers they process, and it has won over fixed point (the
    alternative von Neumann and Chuck Moore advocated) because of that
    convenience. There are people who worry about things like precision
    etc. of FP computations, and who can compute significant digits if
    they know how many digits are significant in the inputs, but they are
    a minority of FP users.

    In any case, none of my FP output words indicate significant digits in
    any way.

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Sun Oct 4 05:25:10 2026
    From Newsgroup: comp.lang.forth

    On 10/4/26 4:19 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    On 10/4/26 3:03 AM, Krishna Myneni wrote:
    https://www.purplemath.com/modules/rounding2.htm

    === begin quote ===
    560 has two significant digits: the last zero is just a placeholder.

    560. : notice that "point" after the zero! This has three significant
    digits, because the decimal point tells us that the measurement was made >>> to the nearest unit, so the zero is not just a placeholder.
    === end quote ==

    The implied uncertainty for the case of no trailing decimal point "560"
    is +/- 5, while the implied uncertainty with the trailing decimal point
    "560." is +/-0.5.

    --
    KM


    The trailing decimal point is specifically needed to indicate the
    significance of trailing zeros of the integer.

    From the Wikipedia article on Significant Figures:
    https://en.wikipedia.org/wiki/Significant_figures

    === begin quote ===
    A decimal point may be placed after the number; for example "1300."
    indicates specifically that trailing zeros are meant to be significant.[7] >> === end quote ===


    This is true for fixed point formatting with rounding to nearest and
    with specified number of decimal places, n = 0.

    If the last digit of the integer is not zero, the use of the trailing
    decimal point is not needed (the implied uncertainty is still +/- 0.5)
    -- the presence or absence of the trailing decimal point does not create
    an ambiguity when the last digit is nonzero.

    gcc's sprintf() with format string "%.0lf" does not following the
    trailing zeros rule for integers e.g. with the number "-1100.2" and zero
    decimal places, it generates the string "-1100" instead of "-1100."
    which may lead to an ambiguity about whether or not the two trailing
    zeros are significant.

    I have seen numbers shown with one digit underlined (probably the last significant one), which would also help for the case when 1300 has
    three significant digits.

    I think that for many uses of FP output words the significant digits
    are not known to the programmer, and any indication of significant
    digits would be misleading.


    The whole point of using standard F. FS. and FE. with the number of significant digits set by PRECISION is for the programmer to restrict
    the total number of digits, with rounding specified by the standard.
    This is to meet the expectations of the user for how many digits are
    needed to be displayed in a given context. That number is application dependent.

    Similarly, for fixed point output with a specified number of decimal
    places (n) the programmer restricts the output to show the user a fixed
    number of decimal places that are appropriate to the context. If the
    result represents an integer, then F.N formatting with n = 0 is
    presuming that all digits in the integer are significant. When that is
    not the case, F.N is not the right choice for floating point output. The correct choice then would be F. per the standard (for some reason, this
    is not stated in the specification of F. but in the specification for SET-PRECISION).

    In the standard F. depends on PRECISION to specify the number of
    significant digits. Thus, if you want to output the floating point
    number 9.61241e4 to 2 significant digits, the standard prescribes the
    solution as

    2 SET-PRECISION
    9.61241e4 F.

    In Gforth, it outputs the following:

    2 set-precision ok
    9.61241e4 F. 96000. ok

    The trailing decimal point is problematic -- it indicates that the
    trailing zeros in the output are significant. When the number of
    significant digits requested by PRECISION are fewer than the number of
    digits in the integer portion of the floating point number, there should
    be no trailing decimal point, per convention.

    By the way, where is it stated in the standard that F. must print a
    trailing decimal point if the output represents an integer?

    --
    KM


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Sun Oct 4 06:03:00 2026
    From Newsgroup: comp.lang.forth

    On 10/4/26 4:19 AM, Anton Ertl wrote:

    ...
    I think that for many uses of FP output words the significant digits
    are not known to the programmer, and any indication of significant
    digits would be misleading.
    ...
    It is generally true that the actual number of significant digits for a calculation are not known by the programmer, unless they have done
    numerical error analysis. But it is also generally true that the number
    of significant digits which are used are typically less than the
    significant digits provided by double precision floating point
    calculations, often far less. For that reason, it is usually not true
    that *any* indication of significant digits are misleading.

    People tend to be conservative about the number of significant digits in
    a calculation when using them. For scientific and engineering
    calculations, there is more scrutiny, but sometimes not enough. This is
    why ACM and other computational science journals exist. There are
    numerous times when I obtained unexpected results from a computation and
    have had to ask, "is this a numerical computational problem?" This is
    kind of how it is in practice. The hard work of numerical analysis isn't
    done unless the results are unexpected.


    --
    KM


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Sun Oct 4 11:25:37 2026
    From Newsgroup: comp.lang.forth

    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    The whole point of using standard F. FS. and FE. with the number of >significant digits set by PRECISION is for the programmer to restrict
    the total number of digits, with rounding specified by the standard.
    This is to meet the expectations of the user for how many digits are
    needed to be displayed in a given context. That number is application >dependent.

    I never use SET-PRECISION except for testing it. F. output is too
    dependent on the actual number to make sense in most application
    usage. FS. and FE. always use exponential notation, and therefore
    their usefulness is limited.

    In the standard F. depends on PRECISION to specify the number of
    significant digits. Thus, if you want to output the floating point
    number 9.61241e4 to 2 significant digits, the standard prescribes the >solution as

    2 SET-PRECISION
    9.61241e4 F.

    In Gforth, it outputs the following:

    2 set-precision ok
    9.61241e4 F. 96000. ok

    The trailing decimal point is problematic -- it indicates that the
    trailing zeros in the output are significant.

    No. It indicates that the F. implementation is standard-conforming,
    nothing else.

    When the number of
    significant digits requested by PRECISION are fewer than the number of >digits in the integer portion of the floating point number, there should
    be no trailing decimal point, per convention.

    The Forth standard specifies that F. output must contain a ".". If
    you want it printed without ".", don't use F..

    By the way, where is it stated in the standard that F. must print a
    trailing decimal point if the output represents an integer?

    |Display, with a trailing space, the top number on the floating-point
    |stack using fixed-point notation:
    |
    |[-] <digits>.<digits0>

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Sun Oct 4 08:50:50 2026
    From Newsgroup: comp.lang.forth

    On 10/4/26 6:25 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    The whole point of using standard F. FS. and FE. with the number of
    significant digits set by PRECISION is for the programmer to restrict
    the total number of digits, with rounding specified by the standard.
    This is to meet the expectations of the user for how many digits are
    needed to be displayed in a given context. That number is application
    dependent.

    I never use SET-PRECISION except for testing it. F. output is too
    dependent on the actual number to make sense in most application
    usage. FS. and FE. always use exponential notation, and therefore
    their usefulness is limited.

    In the standard F. depends on PRECISION to specify the number of
    significant digits. Thus, if you want to output the floating point
    number 9.61241e4 to 2 significant digits, the standard prescribes the
    solution as

    2 SET-PRECISION
    9.61241e4 F.

    In Gforth, it outputs the following:

    2 set-precision ok
    9.61241e4 F. 96000. ok

    The trailing decimal point is problematic -- it indicates that the
    trailing zeros in the output are significant.

    No. It indicates that the F. implementation is standard-conforming,
    nothing else.


    It indicates a lack of self-consistency in the standard:

    F. cannot output PRECISION significant digits *and* indicate that all
    digits output in the example are significant at the same time for
    certain cases, described in my previous message.

    When the number of
    significant digits requested by PRECISION are fewer than the number of
    digits in the integer portion of the floating point number, there should
    be no trailing decimal point, per convention.

    The Forth standard specifies that F. output must contain a ".". If
    you want it printed without ".", don't use F..


    The alternative is to change the standard for F. so that the decimal
    point is used only when PRECISION dictates that it should be.

    By the way, where is it stated in the standard that F. must print a
    trailing decimal point if the output represents an integer?

    |Display, with a trailing space, the top number on the floating-point
    |stack using fixed-point notation:
    |
    |[-] <digits>.<digits0>

    Ok. The decimal point is not in brackets. It should be.

    --
    Krishna





    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Sun Oct 4 09:07:41 2026
    From Newsgroup: comp.lang.forth

    On 10/4/26 6:25 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    The whole point of using standard F. FS. and FE. with the number of
    significant digits set by PRECISION is for the programmer to restrict
    the total number of digits, with rounding specified by the standard.
    This is to meet the expectations of the user for how many digits are
    needed to be displayed in a given context. That number is application
    dependent.


    FS. and FE. always use exponential notation, and therefore
    their usefulness is limited.
    ...

    FS. is by far the most useful floating point formatting word for the
    science community, and likely for much of the engineering community as well.

    Formatting words which are perceived as most convenient for users are
    not foundational. Fixed point and scientific notation floating point
    decimal formatting words with precise specifications about
    representation of either significant digits *or* decimal places are foundational. As the IEEE 754 standard states, for binary format one
    cannot specify both significant digits and decimal places -- they are
    mutually incompatible.

    Other output formats which change form automatically between fixed point
    and scientific notation based on perceived user convenience are fine as
    long as it's clear whether they are specified with significant digits or decimal places, but they are not foundational for computing with
    floating point numbers, and can sometimes be misleading such as taking
    an argument specifying the number of significant digits but outputting a format with a different number of significant digits. That can be dangerous.

    --
    Krishna





    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Sun Oct 4 14:39:55 2026
    From Newsgroup: comp.lang.forth

    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    It is generally true that the actual number of significant digits for a >calculation are not known by the programmer, unless they have done
    numerical error analysis. But it is also generally true that the number
    of significant digits which are used are typically less than the
    significant digits provided by double precision floating point
    calculations, often far less.

    You are using "significant digits" with two differing meanings here.

    The second one seems to be about the best precision that can be
    represented by FP numbers, something similar to what Gforth's
    E. outputs, except that E. never shows trailing 0s behind the decimal
    point, and you would probably like to see them, right? But then, one
    might just say that 16-17 digits are significant in this sense, no
    need to show all these trailing zeros of the value 1e.

    The other one is the meaning that comes out of the precision of the
    input data and how the computation affects it. This one cannot be
    determined easily, so in the usual case whatever the programmer passes
    as precision (whether with set-precision, or the p parameters of e.p
    or f.rdp, or whatever other means there are) has a good chance of not
    being the correct significant-digit count. And creating such an
    indication for default output words is likely to be misleading and
    therefore do more harm than good.

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Sun Oct 4 14:53:42 2026
    From Newsgroup: comp.lang.forth

    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    On 10/4/26 6:25 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    The whole point of using standard F. FS. and FE. with the number of
    significant digits set by PRECISION is for the programmer to restrict
    the total number of digits, with rounding specified by the standard.
    This is to meet the expectations of the user for how many digits are
    needed to be displayed in a given context. That number is application
    dependent.

    I never use SET-PRECISION except for testing it. F. output is too
    dependent on the actual number to make sense in most application
    usage. FS. and FE. always use exponential notation, and therefore
    their usefulness is limited.

    In the standard F. depends on PRECISION to specify the number of
    significant digits. Thus, if you want to output the floating point
    number 9.61241e4 to 2 significant digits, the standard prescribes the
    solution as

    2 SET-PRECISION
    9.61241e4 F.

    In Gforth, it outputs the following:

    2 set-precision ok
    9.61241e4 F. 96000. ok

    The trailing decimal point is problematic -- it indicates that the
    trailing zeros in the output are significant.

    No. It indicates that the F. implementation is standard-conforming,
    nothing else.


    It indicates a lack of self-consistency in the standard:

    F. cannot output PRECISION significant digits *and* indicate that all
    digits output in the example are significant at the same time for
    certain cases, described in my previous message.

    Given that the standard does not say that the presence of "." is such
    an indication, I see no lack of self-consistency here. You may
    deplore the lack of consistency with the convention you mentioned, but
    I never heard about such a convention before the present discussion,
    so it does not seem to be particularly widespread.

    If somebody wants to know the value of PRECISION, they can do

    f. precision .

    But given that PRECISION in a typical program is not the number of
    significant digits that a numerical analyst would produce, typical
    programs will not do that.

    The Forth standard specifies that F. output must contain a ".". If
    you want it printed without ".", don't use F..


    The alternative is to change the standard for F. so that the decimal
    point is used only when PRECISION dictates that it should be.

    I think it's bad enough that F. prints without "E", i.e., the result
    is not something that the standard Forth text interpreter will
    recognize as a float. Making it appear as if it was a single-cell
    integer would be even worse.

    If you want an indication of precision, you can do that in your system
    in a standard-conforming way by underlining the last significant
    digit. E.g., if in 1.3e three digits are significant, the output can
    look like what comes out of Gforth with the following sequence on an
    ANSI terminal:

    s\" 13\e[4m0\e[0m0." type

    Unlike the convention of leaving away the "." in some cases, this is
    also clearly indicates the number of significant digits in cases like
    1300e.

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Sun Oct 4 11:33:20 2026
    From Newsgroup: comp.lang.forth

    On 10/4/26 9:39 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    It is generally true that the actual number of significant digits for a
    calculation are not known by the programmer, unless they have done
    numerical error analysis. But it is also generally true that the number
    of significant digits which are used are typically less than the
    significant digits provided by double precision floating point
    calculations, often far less.

    You are using "significant digits" with two differing meanings here.

    The second one seems to be about the best precision that can be
    represented by FP numbers, something similar to what Gforth's
    E. outputs, except that E. never shows trailing 0s behind the decimal
    point, and you would probably like to see them, right? But then, one
    might just say that 16-17 digits are significant in this sense, no
    need to show all these trailing zeros of the value 1e.

    The other one is the meaning that comes out of the precision of the
    input data and how the computation affects it. This one cannot be
    determined easily, so in the usual case whatever the programmer passes
    as precision (whether with set-precision, or the p parameters of e.p
    or f.rdp, or whatever other means there are) has a good chance of not
    being the correct significant-digit count. And creating such an
    indication for default output words is likely to be misleading and
    therefore do more harm than good.


    Please take a look at the Wikipedia page on Significant Figures, in the Section, "Rounding to significant figures". Note that "significant
    figures" and "significant digits" have the same meaning. There are two
    tables in that section, both of which demonstrate the formatted output
    for the value of Precision in significant digits. With regard to
    floating point formatting words, I am using significant digits in the
    sense described in the two tables, which are both intended to
    demonstrate fixed point output for a given number of significant digits.

    --
    Krishna



    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Sun Oct 4 13:56:46 2026
    From Newsgroup: comp.lang.forth

    On 10/4/26 9:53 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    ...
    In Gforth, it outputs the following:

    2 set-precision ok
    9.61241e4 F. 96000. ok

    The trailing decimal point is problematic -- it indicates that the
    trailing zeros in the output are significant.

    No. It indicates that the F. implementation is standard-conforming,
    nothing else.


    It indicates a lack of self-consistency in the standard:

    F. cannot output PRECISION significant digits *and* indicate that all
    digits output in the example are significant at the same time for
    certain cases, described in my previous message.

    Given that the standard does not say that the presence of "." is such
    an indication, I see no lack of self-consistency here. You may
    deplore the lack of consistency with the convention you mentioned, but
    I never heard about such a convention before the present discussion,
    so it does not seem to be particularly widespread.


    https://www.khanacademy.org/math/arithmetic-home/arith-review-decimals/arithmetic-significant-figures-tutorial/v/significant-figures


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Mon Oct 5 16:18:13 2026
    From Newsgroup: comp.lang.forth

    On 5/10/2026 1:53 am, Anton Ertl wrote:
    ...
    I think it's bad enough that F. prints without "E", i.e., the result
    is not something that the standard Forth text interpreter will
    recognize as a float. Making it appear as if it was a single-cell
    integer would be even worse.

    Neither does D. output with anything that would signify its type.
    I'd rather have numeric output that followed general convention
    than something peculiar to forth. Nothing stops implementers from
    supplying mechanisms whereby users can change what F. prints.

    Maybe there's a mechanism in Gforth that stops annoying nags when
    printing numbers?

    Gforth 0.7.9_20200709

    1. d.
    *terminal*:1:1: warning: '1.' is a double-cell integer; type `help' for more info1 ok

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Mon Oct 5 05:51:14 2026
    From Newsgroup: comp.lang.forth

    dxf <dxforth@gmail.com> writes:
    Maybe there's a mechanism in Gforth that stops annoying nags when
    printing numbers?

    Gforth 0.7.9_20200709

    1. d.
    *terminal*:1:1: warning: '1.' is a double-cell integer; type `help' for more info1 ok

    You are not warned when printing numbers, but when inputting
    double-cell integers without base prefix. And guess what, as the
    warning says, HELP tells you what to do to avoid the warning:

    |To input double-cell integers without warnings, use a base-prefix and put
    |the '.' only in the last position, e.g. "#1.".

    So if you input

    #1. d.

    you get the output without warning.

    You can continue reading the HELP text, which says:

    |Disable warnings with "warnings off" and reduce warnings with "-1 warnings !" |~/.config/gforthrc0 is loaded before processing the OS command line. |~/.config/gforthrc is loaded before entering the Forth command line.

    But note that when you disable warnings, you also disable other
    warnings. So using a base prefix is the method I recommend.

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Mon Oct 5 06:29:30 2026
    From Newsgroup: comp.lang.forth

    Returning to the discussion on F.N the comparable Fortran format
    specifier is 'F0.<n>' -- the width field set to zero allows output
    character length to vary for the integer part of the decimal number, and
    n is again the number of decimal places to which the fixed point output
    is rounded.

    I created a F90 program to print the same test cases I use with F.N and
    the results are shown below. My recommendation is that the Fortran F
    format how is F.N should behave.

    Column 1 -- running index
    Column 2 -- entered double precision number
    Column 3 -- number of decimal places
    Column 4 -- output from Fortran F format with n decimal places

    Outputs for the same inputs with Peter's F.N implementation are given
    further below.
    --
    Krishna Myneni

    === begin output ===
    $ ./fortran-fixpt-dec
    Fortran fixed point output with n decimal places.
    1 0.0051d0 0 0.
    2 0.0051d0 1 .0
    3 0.0051d0 2 .01
    4 0.0051d0 3 .005
    5 0.0051d0 4 .0051
    6 0.0051d0 5 .00510
    7 0.0051d0 17 .00510000000000000
    8 2.0d-15 17 .00000000000000200
    9 0.1d0 0 0.
    10 0.2d0 0 0.
    11 0.5d0 0 0.
    12 0.51d0 0 1.
    13 0.500000000000000001d0 0 0.
    14 0.50000000000000001d0 0 0.
    15 0.5000000000000001d0 0 1.
    16 0.6d0 0 1.
    17 0.9d0 0 1.
    18 1.0d0 0 1.
    19 1.4d0 0 1.
    20 1.4999999d0 0 1.
    21 1.5d0 0 2.
    22 2.5d0 0 2.
    23 3.5d0 0 4.
    24 -1100.2d0 0 -1100.
    25 -1100.5d0 0 -1100.
    26 -1101.5d0 0 -1102.
    27 -1102.5d0 0 -1102.
    28 2.01682663070034556d16 0 20168266307003456.
    29 2.01682663070034556d16 20 20168266307003456.00000000000000000000
    30 0.5d0 25 .5000000000000000000000000
    31 0.625d0 25 .6250000000000000000000000
    32 -0.6d0 4 -.6000
    33 -0.6d0 16 -.6000000000000000
    34 -0.6d0 17 -.59999999999999998
    35 -0.6d0 23 -.59999999999999997779554
    36 -0.6d0 25 -.5999999999999999777955395
    37 9.1d0 3 9.100
    38 9.51d0 1 9.5
    39 9.55d0 1 9.6
    40 -9.66d0 1 -9.7
    41 99.995d0 2 100.00
    42 99.625d0 2 99.62
    43 96.625000000 2 96.63
    44 1.247777d3 0 1248.
    45 1.247777d3 1 1247.8
    46 1.247777d3 2 1247.78
    47 1.247777d3 3 1247.777
    48 -5.0999913335d0 4 -5.1000
    49 -5.0999913335d0 5 -5.09999
    50 -5.0999913335d0 6 -5.099991
    51 -5.0999913335d0 7 -5.0999913
    52 -5.0999913335d0 8 -5.09999133
    53 -5.0999913335d0 9 -5.099991334
    54 9.599999999d8 0 960000000.
    === end output ===

    === begin output for F.N ===
    \ Test of Peter's implementation of F.N <peter.noreply@tin.it>
    \ 1 Oct 2026
    \ Columns 2 and 3 are the arguments for F.N
    \ Column 4 is the formatted output from F.N

    1 0.0051e 0 0
    2 0.0051e 1 0.0
    3 0.0051e 2 0.01
    4 0.0051e 3 0.005
    5 0.0051e 4 0.0051
    6 0.0051e 5 0.00510
    7 0.0051e 17 0.00510000000000000
    8 2.0e-15 17 0.00000000000000200
    9 0.1e 0 0
    10 0.2e 0 0
    11 0.5e 0 0
    12 0.51e 0 1
    13 0.500000000000000001e 0 0
    14 0.50000000000000001e 0 0
    15 0.5000000000000001e 0 1
    16 0.6e 0 1
    17 0.9e 0 1
    18 1.0e 0 1.
    19 1.4e 0 1.
    20 1.4999999e 0 1.
    21 1.5e 0 2.
    22 2.5e 0 2.
    23 3.5e 0 4.
    24 -1100.2e 0 -1100.
    25 -1100.5e 0 -1100.
    26 -1101.5e 0 -1102.
    27 -1102.5e 0 -1102.
    28 2.01682663070034556e16 0 20168266307003456.
    29 2.01682663070034556e16 20 20168266307003456.00000000000000000000
    30 0.5e 25 0.5000000000000000000000000
    31 0.625e 25 0.6250000000000000000000000
    32 -0.6e 4 -0.6000
    33 -0.6e 16 -0.6000000000000000
    34 -0.6e 17 -0.59999999999999998
    35 -0.6e 23 -0.59999999999999997779554
    36 -0.6e 25 -0.5999999999999999777955395
    37 9.1e 3 9.100
    38 9.51e 1 9.5
    39 9.55e 1 9.6
    40 -9.66e 1 -9.7
    41 99.995e 2 100.00
    42 99.625e 2 99.62
    43 96.62500000000001e 2 96.63
    44 1.247777e3 0 1248.
    45 1.247777e3 1 1247.8
    46 1.247777e3 2 1247.78
    47 1.247777e3 3 1247.777
    48 -5.0999913335e0 4 -5.1000
    49 -5.0999913335e0 5 -5.09999
    50 -5.0999913335e0 6 -5.099991
    51 -5.0999913335e0 7 -5.0999913
    52 -5.0999913335e0 8 -5.09999133
    53 -5.0999913335e0 9 -5.099991334
    54 9.599999999e8 0 960000000.
    === end output for F.N ===

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Mon Oct 5 23:06:01 2026
    From Newsgroup: comp.lang.forth

    On 5/10/2026 4:51 pm, Anton Ertl wrote:
    dxf <dxforth@gmail.com> writes:
    Maybe there's a mechanism in Gforth that stops annoying nags when
    printing numbers?

    Gforth 0.7.9_20200709

    1. d.
    *terminal*:1:1: warning: '1.' is a double-cell integer; type `help' for more info1 ok

    You are not warned when printing numbers, but when inputting
    double-cell integers without base prefix. And guess what, as the
    warning says, HELP tells you what to do to avoid the warning:

    |To input double-cell integers without warnings, use a base-prefix and put |the '.' only in the last position, e.g. "#1.".

    So if you input

    #1. d.

    you get the output without warning.

    You can continue reading the HELP text, which says:

    |Disable warnings with "warnings off" and reduce warnings with "-1 warnings !"
    |~/.config/gforthrc0 is loaded before processing the OS command line. |~/.config/gforthrc is loaded before entering the Forth command line.

    But note that when you disable warnings, you also disable other
    warnings. So using a base prefix is the method I recommend.

    -1 warnings ! works when entered manually. Tried inserting in gforthrc0|gforthrc
    definitions but no luck.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Mon Oct 5 15:02:22 2026
    From Newsgroup: comp.lang.forth

    On Mon, 5 Oct 2026 06:29:30 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    Returning to the discussion on F.N the comparable Fortran format
    specifier is 'F0.<n>' -- the width field set to zero allows output
    character length to vary for the integer part of the decimal number, and
    n is again the number of decimal places to which the fixed point output
    is rounded.

    I created a F90 program to print the same test cases I use with F.N and
    the results are shown below. My recommendation is that the Fortran F
    format how is F.N should behave.

    Column 1 -- running index
    Column 2 -- entered double precision number
    Column 3 -- number of decimal places
    Column 4 -- output from Fortran F format with n decimal places

    Outputs for the same inputs with Peter's F.N implementation are given further below.
    --
    Krishna Myneni

    Inserting the tables side by side in an excel sheet
    I can see that the only differences are trailing point
    where n=0 and value <0 and the leading 0 before the decimal
    point.

    I have already done the change and the trailing point is
    now output in all cases except where n is negative.

    I like the leading 0 so that will remain!

    BR
    Peter


    === begin output ===
    $ ./fortran-fixpt-dec
    Fortran fixed point output with n decimal places.
    1 0.0051d0 0 0.
    2 0.0051d0 1 .0
    3 0.0051d0 2 .01
    4 0.0051d0 3 .005
    5 0.0051d0 4 .0051
    6 0.0051d0 5 .00510
    7 0.0051d0 17 .00510000000000000
    8 2.0d-15 17 .00000000000000200
    9 0.1d0 0 0.
    10 0.2d0 0 0.
    11 0.5d0 0 0.
    12 0.51d0 0 1.
    13 0.500000000000000001d0 0 0.
    14 0.50000000000000001d0 0 0.
    15 0.5000000000000001d0 0 1.
    16 0.6d0 0 1.
    17 0.9d0 0 1.
    18 1.0d0 0 1.
    19 1.4d0 0 1.
    20 1.4999999d0 0 1.
    21 1.5d0 0 2.
    22 2.5d0 0 2.
    23 3.5d0 0 4.
    24 -1100.2d0 0 -1100.
    25 -1100.5d0 0 -1100.
    26 -1101.5d0 0 -1102.
    27 -1102.5d0 0 -1102.
    28 2.01682663070034556d16 0 20168266307003456.
    29 2.01682663070034556d16 20 20168266307003456.00000000000000000000
    30 0.5d0 25 .5000000000000000000000000
    31 0.625d0 25 .6250000000000000000000000
    32 -0.6d0 4 -.6000
    33 -0.6d0 16 -.6000000000000000
    34 -0.6d0 17 -.59999999999999998
    35 -0.6d0 23 -.59999999999999997779554
    36 -0.6d0 25 -.5999999999999999777955395
    37 9.1d0 3 9.100
    38 9.51d0 1 9.5
    39 9.55d0 1 9.6
    40 -9.66d0 1 -9.7
    41 99.995d0 2 100.00
    42 99.625d0 2 99.62
    43 96.625000000 2 96.63
    44 1.247777d3 0 1248.
    45 1.247777d3 1 1247.8
    46 1.247777d3 2 1247.78
    47 1.247777d3 3 1247.777
    48 -5.0999913335d0 4 -5.1000
    49 -5.0999913335d0 5 -5.09999
    50 -5.0999913335d0 6 -5.099991
    51 -5.0999913335d0 7 -5.0999913
    52 -5.0999913335d0 8 -5.09999133
    53 -5.0999913335d0 9 -5.099991334
    54 9.599999999d8 0 960000000.
    === end output ===

    === begin output for F.N ===
    \ Test of Peter's implementation of F.N <peter.noreply@tin.it>
    \ 1 Oct 2026
    \ Columns 2 and 3 are the arguments for F.N
    \ Column 4 is the formatted output from F.N

    1 0.0051e 0 0
    2 0.0051e 1 0.0
    3 0.0051e 2 0.01
    4 0.0051e 3 0.005
    5 0.0051e 4 0.0051
    6 0.0051e 5 0.00510
    7 0.0051e 17 0.00510000000000000
    8 2.0e-15 17 0.00000000000000200
    9 0.1e 0 0
    10 0.2e 0 0
    11 0.5e 0 0
    12 0.51e 0 1
    13 0.500000000000000001e 0 0
    14 0.50000000000000001e 0 0
    15 0.5000000000000001e 0 1
    16 0.6e 0 1
    17 0.9e 0 1
    18 1.0e 0 1.
    19 1.4e 0 1.
    20 1.4999999e 0 1.
    21 1.5e 0 2.
    22 2.5e 0 2.
    23 3.5e 0 4.
    24 -1100.2e 0 -1100.
    25 -1100.5e 0 -1100.
    26 -1101.5e 0 -1102.
    27 -1102.5e 0 -1102.
    28 2.01682663070034556e16 0 20168266307003456.
    29 2.01682663070034556e16 20 20168266307003456.00000000000000000000
    30 0.5e 25 0.5000000000000000000000000
    31 0.625e 25 0.6250000000000000000000000
    32 -0.6e 4 -0.6000
    33 -0.6e 16 -0.6000000000000000
    34 -0.6e 17 -0.59999999999999998
    35 -0.6e 23 -0.59999999999999997779554
    36 -0.6e 25 -0.5999999999999999777955395
    37 9.1e 3 9.100
    38 9.51e 1 9.5
    39 9.55e 1 9.6
    40 -9.66e 1 -9.7
    41 99.995e 2 100.00
    42 99.625e 2 99.62
    43 96.62500000000001e 2 96.63
    44 1.247777e3 0 1248.
    45 1.247777e3 1 1247.8
    46 1.247777e3 2 1247.78
    47 1.247777e3 3 1247.777
    48 -5.0999913335e0 4 -5.1000
    49 -5.0999913335e0 5 -5.09999
    50 -5.0999913335e0 6 -5.099991
    51 -5.0999913335e0 7 -5.0999913
    52 -5.0999913335e0 8 -5.09999133
    53 -5.0999913335e0 9 -5.099991334
    54 9.599999999e8 0 960000000.
    === end output for F.N ===



    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Mon Oct 5 08:36:33 2026
    From Newsgroup: comp.lang.forth

    On 10/5/26 8:02 AM, peter wrote:
    On Mon, 5 Oct 2026 06:29:30 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    Returning to the discussion on F.N the comparable Fortran format
    specifier is 'F0.<n>' -- the width field set to zero allows output
    character length to vary for the integer part of the decimal number, and
    n is again the number of decimal places to which the fixed point output
    is rounded.

    I created a F90 program to print the same test cases I use with F.N and
    the results are shown below. My recommendation is that the Fortran F
    format how is F.N should behave.

    Column 1 -- running index
    Column 2 -- entered double precision number
    Column 3 -- number of decimal places
    Column 4 -- output from Fortran F format with n decimal places

    Outputs for the same inputs with Peter's F.N implementation are given
    further below.
    --
    Krishna Myneni

    Inserting the tables side by side in an excel sheet
    I can see that the only differences are trailing point
    where n=0 and value <0 and the leading 0 before the decimal
    point.

    I have already done the change and the trailing point is
    now output in all cases except where n is negative.

    I like the leading 0 so that will remain!


    Great. The leading 0 creates no ambiguity in the interpretation of the
    output.

    --
    Krishna

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Mon Oct 5 08:50:00 2026
    From Newsgroup: comp.lang.forth

    On 10/5/26 6:29 AM, Krishna Myneni wrote:
    Returning to the discussion on F.N the comparable Fortran format
    specifier is 'F0.<n>' -- the width field set to zero allows output
    character length to vary for the integer part of the decimal number, and
    n is again the number of decimal places to which the fixed point output
    is rounded.

    I created a F90 program to print the same test cases I use with F.N and
    the results are shown below. My recommendation is that the Fortran F
    format how is F.N should behave.

    Column 1 -- running index
    Column 2 -- entered double precision number
    Column 3 -- number of decimal places
    Column 4 -- output from Fortran F format with n decimal places

    For anyone curious about the Fortran 90 program for checking the F
    format output, I've attached it below. It was compiled under gfortran
    (GNU Fortran).

    --
    KM

    === begin code ===
    program fixptdec
    ! fixed point output rounding to n decimal places
    implicit none
    integer tn, n
    real(kind=8) r

    print *, 'Fortran fixed point output with n decimal places.'
    ! 1
    r = 0.0051d0; n = 0
    tn = 1
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '0.0051d0', n, r
    ! 2
    n = 1
    tn = 2
    print '(I3,1X,A12,2X,I2,4X,F0.1)', tn, '0.0051d0', n, r
    ! 3
    n = 2
    tn = 3
    print '(I3,1X,A12,2X,I2,4X,F0.2)', tn, '0.0051d0', n, r
    ! 4
    n = 3
    tn = 4
    print '(I3,1X,A12,2X,I2,4X,F0.3)', tn, '0.0051d0', n, r
    ! 5
    n = 4
    tn = 5
    print '(I3,1X,A12,2X,I2,4X,F0.4)', tn, '0.0051d0', n, r
    ! 6
    n = 5
    tn = 6
    print '(I3,1X,A12,2X,I2,4X,F0.5)', tn, '0.0051d0', n, r
    ! 7
    n = 17
    tn = 7
    print '(I3,1X,A12,2X,I2,4X,F0.17)', tn, '0.0051d0', n, r
    ! 8
    r = 2.0d-15; n = 17
    tn = 8
    print '(I3,1X,A12,2X,I2,4X,F0.17)', tn, '2.0d-15', n, r
    ! 9
    r = 0.1d0; n = 0
    tn = 9
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '0.1d0', n, r
    ! 10
    r = 0.2d0; n = 0
    tn = 10
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn,'0.2d0', n, r
    ! 11
    r = 0.5d0; n = 0
    tn = 11
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '0.5d0', n, r
    ! 12
    r = 0.51d0; n = 0
    tn = 12
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '0.51d0', n, r
    ! 13
    r = 0.500000000000000001d0; n = 0
    tn = 13
    print '(I3,1X,A24,2X,I2,4X,F0.0)', tn, '0.500000000000000001d0', n, r
    ! 14
    r = 0.50000000000000001d0; n = 0
    tn = 14
    print '(I3,1X,A24,2X,I2,4X,F0.0)', tn, '0.50000000000000001d0', n, r
    ! 15
    r = 0.5000000000000001d0; n = 0
    tn = 15
    print '(I3,1X,A24,2X,I2,4X,F0.0)', tn, '0.5000000000000001d0', n, r
    ! 16
    r = 0.6d0; n = 0
    tn = 16
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '0.6d0', n, r
    ! 17
    r = 0.9d0; n = 0
    tn = 17
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '0.9d0', n, r
    ! 18
    r = 1.0d0; n = 0
    tn = 18
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '1.0d0', n, r
    ! 19
    r = 1.4d0; n = 0
    tn = 19
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '1.4d0', n, r
    ! 20
    r = 1.4999999d0; n = 0
    tn = 20
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '1.4999999d0', n, r
    ! 21
    r = 1.5d0; n = 0
    tn = 21
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '1.5d0', n, r
    ! 22
    r = 2.5d0; n = 0
    tn = 22
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '2.5d0', n, r
    ! 23
    r = 3.5d0; n = 0
    tn = 23
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '3.5d0', n, r
    ! 24
    r = -1100.2d0; n = 0
    tn = 24
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '-1100.2d0', n, r
    ! 25
    r = -1100.5d0; n = 0
    tn = 25
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '-1100.5d0', n, r
    ! 26
    r = -1101.5d0; n = 0
    tn = 26
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '-1101.5d0', n, r
    ! 27
    r = -1102.5d0; n = 0
    tn = 27
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '-1102.5d0', n, r
    ! 28
    r = 2.01682663070034556d16; n = 0
    tn = 28
    print '(I3,1X,A24,2X,I2,4X,F0.0)', tn, '2.01682663070034556d16', n, r
    ! 29
    n = 20
    tn = 29
    print '(I3,1X,A24,2X,I2,4X,F0.20)', tn, '2.01682663070034556d16', n, r
    ! 30
    r = 0.5d0; n = 25
    tn = 30
    print '(I3,1X,A12,2X,I2,4X,F0.25)', tn, '0.5d0', n, r
    ! 31
    r = 0.625d0; n = 25
    tn = 31
    print '(I3,1X,A12,2X,I2,4X,F0.25)', tn, '0.625d0', n, r
    ! 32
    r = -0.6d0; n = 4
    tn = 32
    print '(I3,1X,A12,2X,I2,4X,F0.4)', tn, '-0.6d0', n, r
    ! 33
    n = 16
    tn = 33
    print '(I3,1X,A12,2X,I2,4X,F0.16)', tn, '-0.6d0', n, r
    ! 34
    n = 17
    tn = 34
    print '(I3,1X,A12,2X,I2,4X,F0.17)', tn, '-0.6d0', n, r
    ! 35
    n = 23
    tn = 35
    print '(I3,1X,A12,2X,I2,4X,F0.23)', tn, '-0.6d0', n, r
    ! 36
    n = 25
    tn = 36
    print '(I3,1X,A12,2X,I2,4X,F0.25)', tn, '-0.6d0', n, r
    ! 37
    r = 9.1d0; n = 3
    tn = 37
    print '(I3,1X,A12,2X,I2,4X,F0.3)', tn, '9.1d0', n, r
    ! 38
    r = 9.51d0; n = 1
    tn = 38
    print '(I3,1X,A12,2X,I2,4X,F0.1)', tn, '9.51d0', n, r
    ! 39
    r = 9.55d0; n = 1
    tn = 39
    print '(I3,1X,A12,2X,I2,4X,F0.1)', tn, '9.55d0', n, r
    ! 40
    r = -9.66d0; n = 1
    tn = 40
    print '(I3,1X,A12,2X,I2,4X,F0.1)', tn, '-9.66d0', n, r
    ! 41
    r = 99.995d0; n = 2
    tn = 41
    print '(I3,1X,A12,2X,I2,4X,F0.2)', tn, '99.995d0', n, r
    ! 42
    r = 99.625d0; n = 2
    tn = 42
    print '(I3,1X,A12,2X,I2,4X,F0.2)', tn, '99.625d0', n, r
    ! 43
    r = 96.62500000000001d0; n = 2
    tn = 43
    print '(I3,1X,A12,2X,I2,4X,F0.2)', tn, '96.62500000000001d0', n, r
    ! 44
    r = 1.247777d3; n = 0
    tn = 44
    print '(I3,1X,A12,2X,I2,4X,F0.0)', tn, '1.247777d3', n, r
    ! 45
    n = 1
    tn = 45
    print '(I3,1X,A12,2X,I2,4X,F0.1)', tn, '1.247777d3', n, r
    ! 46
    n = 2
    tn = 46
    print '(I3,1X,A12,2X,I2,4X,F0.2)', tn, '1.247777d3', n, r
    ! 47
    n = 3
    tn = 47
    print '(I3,1X,A12,2X,I2,4X,F0.3)', tn, '1.247777d3', n, r
    ! 48
    r = -5.0999913335d0; n = 4
    tn = 48
    print '(I3,1X,A24,2X,I2,4X,F0.4)', tn, '-5.0999913335d0', n, r
    ! 49
    n = 5
    tn = 49
    print '(I3,1X,A24,2X,I2,4X,F0.5)', tn, '-5.0999913335d0', n, r
    ! 50
    n = 6
    tn = 50
    print '(I3,1X,A24,2X,I2,4X,F0.6)', tn, '-5.0999913335d0', n, r
    ! 51
    n = 7
    tn = 51
    print '(I3,1X,A24,2X,I2,4X,F0.7)', tn, '-5.0999913335d0', n, r
    ! 52
    n = 8
    tn = 52
    print '(I3,1X,A24,2X,I2,4X,F0.8)', tn, '-5.0999913335d0', n, r
    ! 53
    n = 9
    tn = 53
    print '(I3,1X,A24,2X,I2,4X,F0.9)', tn, '-5.0999913335d0', n, r
    ! 54
    r = 9.599999999d8; n = 0
    tn = 54
    print '(I3,1X,A24,2X,I2,4X,F0.0)', tn, '9.599999999d8', n, r

    end program
    === end code ===

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Mon Oct 5 17:20:50 2026
    From Newsgroup: comp.lang.forth

    dxf <dxforth@gmail.com> writes:
    -1 warnings ! works when entered manually. Tried inserting in gforthrc0|gforthrc
    definitions but no luck.

    Works for me:

    [~/gforth:172258] echo "-1 warnings !" >~/.config/gforthrc
    [~/gforth:172259] gforth
    Gforth 0.7.9_20260923
    Authors: Anton Ertl, Bernd Paysan, Jens Wilke et al., for more type `authors' Copyright -- 2025 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
    warnings ? -1 ok
    -1. d. -1 ok

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Paul Rubin@no.email@nospam.invalid to comp.lang.forth on Mon Oct 5 12:50:13 2026
    From Newsgroup: comp.lang.forth

    dxf <dxforth@gmail.com> writes:
    -1 warnings ! works when entered manually. Tried inserting in gforthrc0|gforthrc
    definitions but no luck.

    gforthrc is a new thing, does it work at all in your gforth
    installation?

    I notice that "warnings on" also works, opposite of "warnings off".
    Clever. These are gforth specific.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Mon Oct 5 21:15:41 2026
    From Newsgroup: comp.lang.forth

    Paul Rubin <no.email@nospam.invalid> writes:
    I notice that "warnings on" also works, opposite of "warnings off".

    Not quite. Default is -2. -1 (warnings on) reduces the warnings
    relative to the default.

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Mon Oct 5 17:01:14 2026
    From Newsgroup: comp.lang.forth

    On 10/5/26 8:02 AM, peter wrote:
    On Mon, 5 Oct 2026 06:29:30 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    ...
    I created a F90 program to print the same test cases I use with F.N and
    the results are shown below. My recommendation is that the Fortran F
    format how is F.N should behave.

    Column 1 -- running index
    Column 2 -- entered double precision number
    Column 3 -- number of decimal places
    Column 4 -- output from Fortran F format with n decimal places

    Outputs for the same inputs with Peter's F.N implementation are given
    further below.
    ...

    Inserting the tables side by side in an excel sheet
    I can see that the only differences are trailing point
    where n=0 and value <0 and the leading 0 before the decimal
    point.

    I have already done the change and the trailing point is
    now output in all cases except where n is negative.

    I like the leading 0 so that will remain!

    BR
    Peter


    === begin output ===
    $ ./fortran-fixpt-dec
    Fortran fixed point output with n decimal places.
    ...
    43 96.625000000 2 96.63
    ...
    === end output ===

    === begin output for F.N ===
    \ Test of Peter's implementation of F.N <peter.noreply@tin.it>
    \ 1 Oct 2026
    \ Columns 2 and 3 are the arguments for F.N
    \ Column 4 is the formatted output from F.N
    ...
    43 96.62500000000001e 2 96.63
    ...
    === end output for F.N ===


    There is an error in the Fortran test 43, because I forgot to include
    the exponent field "d0". It's output is incorrect. Compare with the F.N
    output for test 43, which is correct. I guess the gfortran compiler interpreted the number as a single precision float.

    Peter, I notice you did not incorporate the logic used for printing +/-
    inf and nan using F. from your first version in your 2nd version on
    October 2. I have completed the automated tests for (F.N) with your 2nd version of the code for the tests we have so far. Is there a reason you
    left out the logic for handling infinities and nans in your 2nd version?

    --
    Krishna

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Tue Oct 6 11:54:45 2026
    From Newsgroup: comp.lang.forth

    On 6/10/2026 6:50 am, Paul Rubin wrote:
    dxf <dxforth@gmail.com> writes:
    -1 warnings ! works when entered manually. Tried inserting in
    gforthrc0|gforthrc
    definitions but no luck.

    gforthrc is a new thing, does it work at all in your gforth
    installation?

    In Gforth 0.7.9_20200709 for Win there's a file gforthrc.fs in the root directory with definitions for the above. Beyond that I've no idea.

    It's not the first time I've encountered forths that claim to be able
    to do things, only to find documentation lacking, problems with the
    process, and an unsatisfactory response from the supplier. Best one
    can do is make sure one's own system doesn't suffer these traits.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Tue Oct 6 07:36:08 2026
    From Newsgroup: comp.lang.forth

    On Mon, 5 Oct 2026 17:01:14 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    On 10/5/26 8:02 AM, peter wrote:
    On Mon, 5 Oct 2026 06:29:30 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    ...
    I created a F90 program to print the same test cases I use with F.N and
    the results are shown below. My recommendation is that the Fortran F
    format how is F.N should behave.

    Column 1 -- running index
    Column 2 -- entered double precision number
    Column 3 -- number of decimal places
    Column 4 -- output from Fortran F format with n decimal places

    Outputs for the same inputs with Peter's F.N implementation are given
    further below.
    ...

    Inserting the tables side by side in an excel sheet
    I can see that the only differences are trailing point
    where n=0 and value <0 and the leading 0 before the decimal
    point.

    I have already done the change and the trailing point is
    now output in all cases except where n is negative.

    I like the leading 0 so that will remain!

    BR
    Peter


    === begin output ===
    $ ./fortran-fixpt-dec
    Fortran fixed point output with n decimal places.
    ...
    43 96.625000000 2 96.63
    ...
    === end output ===

    === begin output for F.N ===
    \ Test of Peter's implementation of F.N <peter.noreply@tin.it>
    \ 1 Oct 2026
    \ Columns 2 and 3 are the arguments for F.N
    \ Column 4 is the formatted output from F.N
    ...
    43 96.62500000000001e 2 96.63
    ...
    === end output for F.N ===


    There is an error in the Fortran test 43, because I forgot to include
    the exponent field "d0". It's output is incorrect. Compare with the F.N output for test 43, which is correct. I guess the gfortran compiler interpreted the number as a single precision float.

    Peter, I notice you did not incorporate the logic used for printing +/-
    inf and nan using F. from your first version in your 2nd version on
    October 2. I have completed the automated tests for (F.N) with your 2nd version of the code for the tests we have so far. Is there a reason you
    left out the logic for handling infinities and nans in your 2nd version?

    --
    Krishna

    Yes there is! Using F. was like a quick fix for concentrating on the
    real logic. It worked but had a dependency on precision. DXF pointed out
    this. If you set precision to 1 only the first letter would print out.

    As the first operation in (f.n) is to call represent with a buffer lenght
    of 32 we have already the information stored in the buffer without
    truncation. So instead of calling F. I type out the 3 first letters
    from the buffer when flag2 is zero. Note that I change the order and
    the sign is printed first so that will be correct.

    I see now what the problem with case 43 is. I compared the results
    and they happened to be correct anyway!

    BR
    Peter

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Tue Oct 6 08:03:47 2026
    From Newsgroup: comp.lang.forth

    On Mon, 5 Oct 2026 17:01:14 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    On 10/5/26 8:02 AM, peter wrote:
    On Mon, 5 Oct 2026 06:29:30 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    ...
    I created a F90 program to print the same test cases I use with F.N and
    the results are shown below. My recommendation is that the Fortran F
    format how is F.N should behave.

    Column 1 -- running index
    Column 2 -- entered double precision number
    Column 3 -- number of decimal places
    Column 4 -- output from Fortran F format with n decimal places

    Outputs for the same inputs with Peter's F.N implementation are given
    further below.
    ...

    Inserting the tables side by side in an excel sheet
    I can see that the only differences are trailing point
    where n=0 and value <0 and the leading 0 before the decimal
    point.

    I have already done the change and the trailing point is
    now output in all cases except where n is negative.

    I like the leading 0 so that will remain!

    BR
    Peter


    === begin output ===
    $ ./fortran-fixpt-dec
    Fortran fixed point output with n decimal places.
    ...
    43 96.625000000 2 96.63
    ...
    === end output ===

    === begin output for F.N ===
    \ Test of Peter's implementation of F.N <peter.noreply@tin.it>
    \ 1 Oct 2026
    \ Columns 2 and 3 are the arguments for F.N
    \ Column 4 is the formatted output from F.N
    ...
    43 96.62500000000001e 2 96.63
    ...
    === end output for F.N ===


    There is an error in the Fortran test 43, because I forgot to include
    the exponent field "d0". It's output is incorrect. Compare with the F.N output for test 43, which is correct. I guess the gfortran compiler interpreted the number as a single precision float.

    Peter, I notice you did not incorporate the logic used for printing +/-
    inf and nan using F. from your first version in your 2nd version on
    October 2. I have completed the automated tests for (F.N) with your 2nd version of the code for the tests we have so far. Is there a reason you
    left out the logic for handling infinities and nans in your 2nd version?

    --
    Krishna


    If you are working on (f.n) that I posted there are 2 changes I have made later.

    f.n-case-e>0 should be

    : f.n-case-e>0 ( F:fp n e -- )
    over + \ n e+n
    fpad 1024 '0' fill
    fpad swap represent 2drop \ n e'
    dup >r \ n e' r: e'
    fpad swap stype
    dup 0 >= if 46 semit then \ n
    fpad r> + \ n fpad+e'
    swap 0 max stype ;

    This will prevent the dot to be printed at the end when using negative n.

    The other is in a comment

    : .sign ( f -- )
    13 and 32 + semit ; \ prints bl for positive
    \ if 45 semit then ; \ use this to only print -

    The code I posted have 32 in the commented out part!
    It would print a blank instead of a -

    Peter

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Tue Oct 6 06:25:36 2026
    From Newsgroup: comp.lang.forth

    dxf <dxforth@gmail.com> writes:
    On 6/10/2026 6:50 am, Paul Rubin wrote:
    dxf <dxforth@gmail.com> writes:
    -1 warnings ! works when entered manually. Tried inserting in
    gforthrc0|gforthrc
    definitions but no luck.

    gforthrc is a new thing, does it work at all in your gforth
    installation?

    In Gforth 0.7.9_20200709 for Win there's a file gforthrc.fs in the root >directory with definitions for the above. Beyond that I've no idea.

    It's not the first time I've encountered forths that claim to be able
    to do things, only to find documentation lacking, problems with the
    process, and an unsatisfactory response from the supplier.

    It's not the first time that some user has given insufficient
    information in a bug report, and found the response unsatisfactory.

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Tue Oct 6 17:40:49 2026
    From Newsgroup: comp.lang.forth

    On 6/10/2026 4:36 pm, peter wrote:
    ...
    As the first operation in (f.n) is to call represent with a buffer lenght
    of 32 we have already the information stored in the buffer without truncation. So instead of calling F. I type out the 3 first letters
    from the buffer when flag2 is zero. Note that I change the order and
    the sign is printed first so that will be correct.
    ...

    That was a neat trick using fpad 32 REPRESENT to retrieve the power while ensuring the buffer got filled should flag2 turn out false. OTOH it does
    mean REPRESENT is called twice for regular numbers.

    As regards the sign:

    "When flag2 is false, n and flag1 are implementation defined [...]"

    While flag1 *could* be a sign, it can't be counted on and it's messy to
    handle in any case. For this reason I have REPRESENT include the sign
    (if any) within the graphic itself. In apps when flag2 is false, I need
    only output the graphic and it's 'job done'.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Tue Oct 6 18:22:10 2026
    From Newsgroup: comp.lang.forth

    On 6/10/2026 5:25 pm, Anton Ertl wrote:
    dxf <dxforth@gmail.com> writes:
    On 6/10/2026 6:50 am, Paul Rubin wrote:
    dxf <dxforth@gmail.com> writes:
    -1 warnings ! works when entered manually. Tried inserting in
    gforthrc0|gforthrc
    definitions but no luck.

    gforthrc is a new thing, does it work at all in your gforth
    installation?

    In Gforth 0.7.9_20200709 for Win there's a file gforthrc.fs in the root
    directory with definitions for the above. Beyond that I've no idea.

    It's not the first time I've encountered forths that claim to be able
    to do things, only to find documentation lacking, problems with the
    process, and an unsatisfactory response from the supplier.

    It's not the first time that some user has given insufficient
    information in a bug report, and found the response unsatisfactory.

    From your previous reply it appears you got the information you needed.
    It's the answer that was lacking. All I see are what appears to be
    manual entries at an OS prompt.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Tue Oct 6 05:30:07 2026
    From Newsgroup: comp.lang.forth

    On 10/6/26 1:03 AM, peter wrote:
    On Mon, 5 Oct 2026 17:01:14 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    On 10/5/26 8:02 AM, peter wrote:
    On Mon, 5 Oct 2026 06:29:30 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    ...
    I created a F90 program to print the same test cases I use with F.N and >>>> the results are shown below. My recommendation is that the Fortran F
    format how is F.N should behave.

    Column 1 -- running index
    Column 2 -- entered double precision number
    Column 3 -- number of decimal places
    Column 4 -- output from Fortran F format with n decimal places

    Outputs for the same inputs with Peter's F.N implementation are given
    further below.
    ...

    Inserting the tables side by side in an excel sheet
    I can see that the only differences are trailing point
    where n=0 and value <0 and the leading 0 before the decimal
    point.

    I have already done the change and the trailing point is
    now output in all cases except where n is negative.

    I like the leading 0 so that will remain!

    BR
    Peter


    === begin output ===
    $ ./fortran-fixpt-dec
    Fortran fixed point output with n decimal places.
    ...
    43 96.625000000 2 96.63
    ...
    === end output ===

    === begin output for F.N ===
    \ Test of Peter's implementation of F.N <peter.noreply@tin.it>
    \ 1 Oct 2026
    \ Columns 2 and 3 are the arguments for F.N
    \ Column 4 is the formatted output from F.N
    ...
    43 96.62500000000001e 2 96.63
    ...
    === end output for F.N ===




    If you are working on (f.n) that I posted there are 2 changes I have made later.

    f.n-case-e>0 should be

    : f.n-case-e>0 ( F:fp n e -- )
    over + \ n e+n
    fpad 1024 '0' fill
    fpad swap represent 2drop \ n e'
    dup >r \ n e' r: e'
    fpad swap stype
    dup 0 >= if 46 semit then \ n
    fpad r> + \ n fpad+e'
    swap 0 max stype ;

    This will prevent the dot to be printed at the end when using negative n.

    The other is in a comment

    : .sign ( f -- )
    13 and 32 + semit ; \ prints bl for positive
    \ if 45 semit then ; \ use this to only print -

    The code I posted have 32 in the commented out part!
    It would print a blank instead of a -

    Yes, I'm currently revising your "version 2" code, posted on October 2,
    for F.N, which includes the string output word (F.N), to work also with
    the unified fp/data stack.

    I noticed the two options for .SIGN and used the second option which
    does not output a space for positive values -- this will make writing
    the word for right-justified output simpler. The automated tests for
    (F.N) currently work on both kforth64 and kforth64-fast. Two additional
    tests check that the sign of floating point zero is handled correctly
    (it is) -- F0< cannot be used to check for the sign of fp zero.

    --
    Krishna









    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Tue Oct 6 05:48:23 2026
    From Newsgroup: comp.lang.forth

    On 10/6/26 5:30 AM, Krishna Myneni wrote:

    ... The automated tests for
    (F.N) currently work on both kforth64 and kforth64-fast. Two additional tests check that the sign of floating point zero is handled correctly
    (it is) -- F0< cannot be used to check for the sign of fp zero.


    The current set of automated tests for (F.N) :

    === begin code ===
    TESTING (F.N)
    : comp ( caddr1 u caddr2 u -- n )
    2swap -trailing bl skip compare ;

    t{ ( 1 ) 0.0051e0 0 (f.n) s" 0." comp -> 0 }t
    t{ ( 2 ) 0.0051e0 1 (f.n) s" 0.0" comp -> 0 }t
    t{ ( 3 ) 0.0051e0 2 (f.n) s" 0.01" comp -> 0 }t
    t{ ( 4 ) 0.0051e0 3 (f.n) s" 0.005" comp -> 0 }t
    t{ ( 5 ) 0.0051e0 4 (f.n) s" 0.0051" comp -> 0 }t
    t{ ( 6 ) 0.0051e0 5 (f.n) s" 0.00510" comp -> 0 }t
    t{ ( 7 ) 0.0051e0 17 (f.n) s" 0.00510000000000000" comp -> 0 }t
    t{ ( 8 ) 2.0e-15 17 (f.n) s" 0.00000000000000200" comp -> 0 }t
    t{ ( 9 ) 0.1e0 0 (f.n) s" 0." comp -> 0 }t
    t{ ( 10 ) 0.2e0 0 (f.n) s" 0." comp -> 0 }t
    t{ ( 11 ) 0.5e0 0 (f.n) s" 0." comp -> 0 }t
    t{ ( 12 ) 0.51e0 0 (f.n) s" 1." comp -> 0 }t
    t{ ( 13 ) 0.500000000000000001e0 0 (f.n) s" 0." comp -> 0 }t
    t{ ( 14 ) 0.50000000000000001e0 0 (f.n) s" 0." comp -> 0 }t
    t{ ( 15 ) 0.5000000000000001e0 0 (f.n) s" 1." comp -> 0 }t
    t{ ( 16 ) 0.6e0 0 (f.n) s" 1." comp -> 0 }t
    t{ ( 17 ) 0.9e0 0 (f.n) s" 1." comp -> 0 }t
    t{ ( 18 ) 1.0e0 0 (f.n) s" 1." comp -> 0 }t
    t{ ( 19 ) 1.4e0 0 (f.n) s" 1." comp -> 0 }t
    t{ ( 20 ) 1.4999999e0 0 (f.n) s" 1." comp -> 0 }t
    t{ ( 21 ) 1.5e0 0 (f.n) s" 2." comp -> 0 }t
    t{ ( 22 ) 2.5e0 0 (f.n) s" 2." comp -> 0 }t
    t{ ( 23 ) 3.5e0 0 (f.n) s" 4." comp -> 0 }t
    t{ ( 24 ) -1100.2e0 0 (f.n) s" -1100." comp -> 0 }t
    t{ ( 25 ) -1100.5e0 0 (f.n) s" -1100." comp -> 0 }t
    t{ ( 26 ) -1101.5e0 0 (f.n) s" -1102." comp -> 0 }t
    t{ ( 27 ) -1102.5e0 0 (f.n) s" -1102." comp -> 0 }t
    t{ ( 28 ) 2.01682663070034556e16 0 (f.n) s" 20168266307003456."
    comp -> 0 }t
    t{ ( 29 ) 2.01682663070034556e16 20 (f.n)
    s" 20168266307003456.00000000000000000000" comp -> 0 }t
    t{ ( 30 ) 0.5e0 25 (f.n) s" 0.5000000000000000000000000"
    comp -> 0 }t
    t{ ( 31 ) 0.625e0 25 (f.n) s" 0.6250000000000000000000000"
    comp -> 0 }t
    t{ ( 32 ) -0.6e0 4 (f.n) s" -0.6000" comp -> 0 }t
    t{ ( 33 ) -0.6e0 16 (f.n) s" -0.6000000000000000" comp -> 0 }t
    t{ ( 34 ) -0.6e0 17 (f.n) s" -0.59999999999999998"
    comp -> 0 }t
    t{ ( 35 ) -0.6e0 23 (f.n) s" -0.59999999999999997779554"
    comp -> 0 }t
    t{ ( 36 ) -0.6e0 25 (f.n) s" -0.5999999999999999777955395"
    comp -> 0 }t
    t{ ( 37 ) 9.1e0 3 (f.n) s" 9.100" comp -> 0 }t
    t{ ( 38 ) 9.51e0 1 (f.n) s" 9.5" comp -> 0 }t
    t{ ( 39 ) 9.55e0 1 (f.n) s" 9.6" comp -> 0 }t
    t{ ( 40 ) -9.66e0 1 (f.n) s" -9.7" comp -> 0 }t
    t{ ( 41 ) 99.995e0 2 (f.n) s" 100.00" comp -> 0 }t
    t{ ( 42 ) 99.625e0 2 (f.n) s" 99.62" comp -> 0 }t
    t{ ( 43 ) 96.62500000000001e 2 (f.n) s" 96.63" comp -> 0 }t
    t{ ( 44 ) 1.247777e3 0 (f.n) s" 1248." comp -> 0 }t
    t{ ( 45 ) 1.247777e3 1 (f.n) s" 1247.8" comp -> 0 }t
    t{ ( 46 ) 1.247777e3 2 (f.n) s" 1247.78" comp -> 0 }t
    t{ ( 47 ) 1.247777e3 3 (f.n) s" 1247.777" comp -> 0 }t
    t{ ( 48 ) -5.0999913335e0 4 (f.n) s" -5.1000" comp -> 0 }t
    t{ ( 49 ) -5.0999913335e0 5 (f.n) s" -5.09999" comp -> 0 }t
    t{ ( 50 ) -5.0999913335e0 6 (f.n) s" -5.099991" comp -> 0 }t
    t{ ( 51 ) -5.0999913335e0 7 (f.n) s" -5.0999913" comp -> 0 }t
    t{ ( 52 ) -5.0999913335e0 8 (f.n) s" -5.09999133" comp -> 0 }t
    t{ ( 53 ) -5.0999913335e0 9 (f.n) s" -5.099991334" comp -> 0 }t
    t{ ( 54 ) 9.599999999e8 0 (f.n) s" 960000000." comp -> 0 }t
    t{ ( 55 ) 0.0e 0 (f.n) s" 0." comp -> 0 }t
    t{ ( 56 ) -0.0e 0 (f.n) s" -0." comp -> 0 }t
    === end code ===

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Tue Oct 6 11:57:59 2026
    From Newsgroup: comp.lang.forth

    dxf <dxforth@gmail.com> writes:
    On 6/10/2026 5:25 pm, Anton Ertl wrote:
    dxf <dxforth@gmail.com> writes:
    On 6/10/2026 6:50 am, Paul Rubin wrote:
    dxf <dxforth@gmail.com> writes:
    -1 warnings ! works when entered manually. Tried inserting in
    gforthrc0|gforthrc
    definitions but no luck.

    gforthrc is a new thing, does it work at all in your gforth
    installation?

    In Gforth 0.7.9_20200709 for Win there's a file gforthrc.fs in the root
    directory with definitions for the above. Beyond that I've no idea.

    It's not the first time I've encountered forths that claim to be able
    to do things, only to find documentation lacking, problems with the
    process, and an unsatisfactory response from the supplier.

    It's not the first time that some user has given insufficient
    information in a bug report, and found the response unsatisfactory.

    From your previous reply it appears you got the information you needed.

    Given that you did not write exactly what you did, I certainly did not
    get the information. The most likely cause of the failure to affect
    WARNINGS is that you modified the wrong file, so in <2026Oct5.192050@mips.complang.tuwien.ac.at> (which you may or may not
    mean with "your previous reply") I showed you how modifying
    ~/.config/gforthrc actually leads to the result you were interested
    in. Apart from the mention you gave here you did not react to that.

    One might conclude that my last response was satisfactory, except that
    you then wrote something about an "unsatisfactory response", without
    mentioning any specifics.

    It's the answer that was lacking. All I see are what appears to be
    manual entries at an OS prompt.

    [~/gforth:172258] echo "-1 warnings !" >~/.config/gforthrc
    [~/gforth:172259] gforth

    The stuff in brackets is my shell prompt, and the stuff behind are my
    shell commands.

    Gforth 0.7.9_20260923
    Authors: Anton Ertl, Bernd Paysan, Jens Wilke et al., for more type `authors'
    Copyright (C) 2025 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

    This is the startup message of Gforth.

    warnings ? -1 ok

    Here "warnings ?" is the input at the Forth command line, and the
    stuff behind it is the output of the Forth system. This demonstrates
    that WARNINGS indeed has the value -1 after Gforth has started.

    -1. d. -1 ok

    Here "-1. d." is the input at the Forth command line, and the stuff
    behind it is the output of the Forth system. This demonstrates that
    the warning is no longer given.

    It surprises me that you did not recognize without the comments.

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Tue Oct 6 20:40:50 2026
    From Newsgroup: comp.lang.forth

    On Tue, 6 Oct 2026 05:48:23 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    On 10/6/26 5:30 AM, Krishna Myneni wrote:

    ... The automated tests for
    (F.N) currently work on both kforth64 and kforth64-fast. Two additional tests check that the sign of floating point zero is handled correctly
    (it is) -- F0< cannot be used to check for the sign of fp zero.


    The current set of automated tests for (F.N) :

    When I run this I get 3 error. All for 0.6e with 17 23 and 25 decimals.
    The reason is that I use dtoa.c in mode=4. Return shortest string that
    converts back to original fp number. If I change to mode 2 I get all
    correct. I have mode as a variable that I can set!

    BR
    Peter


    === begin code ===
    TESTING (F.N)
    : comp ( caddr1 u caddr2 u -- n )
    2swap -trailing bl skip compare ;

    t{ ( 1 ) 0.0051e0 0 (f.n) s" 0." comp -> 0 }t
    t{ ( 2 ) 0.0051e0 1 (f.n) s" 0.0" comp -> 0 }t
    t{ ( 3 ) 0.0051e0 2 (f.n) s" 0.01" comp -> 0 }t
    t{ ( 4 ) 0.0051e0 3 (f.n) s" 0.005" comp -> 0 }t
    t{ ( 5 ) 0.0051e0 4 (f.n) s" 0.0051" comp -> 0 }t
    t{ ( 6 ) 0.0051e0 5 (f.n) s" 0.00510" comp -> 0 }t
    t{ ( 7 ) 0.0051e0 17 (f.n) s" 0.00510000000000000" comp -> 0 }t
    t{ ( 8 ) 2.0e-15 17 (f.n) s" 0.00000000000000200" comp -> 0 }t
    t{ ( 9 ) 0.1e0 0 (f.n) s" 0." comp -> 0 }t
    t{ ( 10 ) 0.2e0 0 (f.n) s" 0." comp -> 0 }t
    t{ ( 11 ) 0.5e0 0 (f.n) s" 0." comp -> 0 }t
    t{ ( 12 ) 0.51e0 0 (f.n) s" 1." comp -> 0 }t
    t{ ( 13 ) 0.500000000000000001e0 0 (f.n) s" 0." comp -> 0 }t
    t{ ( 14 ) 0.50000000000000001e0 0 (f.n) s" 0." comp -> 0 }t
    t{ ( 15 ) 0.5000000000000001e0 0 (f.n) s" 1." comp -> 0 }t
    t{ ( 16 ) 0.6e0 0 (f.n) s" 1." comp -> 0 }t
    t{ ( 17 ) 0.9e0 0 (f.n) s" 1." comp -> 0 }t
    t{ ( 18 ) 1.0e0 0 (f.n) s" 1." comp -> 0 }t
    t{ ( 19 ) 1.4e0 0 (f.n) s" 1." comp -> 0 }t
    t{ ( 20 ) 1.4999999e0 0 (f.n) s" 1." comp -> 0 }t
    t{ ( 21 ) 1.5e0 0 (f.n) s" 2." comp -> 0 }t
    t{ ( 22 ) 2.5e0 0 (f.n) s" 2." comp -> 0 }t
    t{ ( 23 ) 3.5e0 0 (f.n) s" 4." comp -> 0 }t
    t{ ( 24 ) -1100.2e0 0 (f.n) s" -1100." comp -> 0 }t
    t{ ( 25 ) -1100.5e0 0 (f.n) s" -1100." comp -> 0 }t
    t{ ( 26 ) -1101.5e0 0 (f.n) s" -1102." comp -> 0 }t
    t{ ( 27 ) -1102.5e0 0 (f.n) s" -1102." comp -> 0 }t
    t{ ( 28 ) 2.01682663070034556e16 0 (f.n) s" 20168266307003456."
    comp -> 0 }t
    t{ ( 29 ) 2.01682663070034556e16 20 (f.n)
    s" 20168266307003456.00000000000000000000" comp -> 0 }t
    t{ ( 30 ) 0.5e0 25 (f.n) s" 0.5000000000000000000000000"
    comp -> 0 }t
    t{ ( 31 ) 0.625e0 25 (f.n) s" 0.6250000000000000000000000"
    comp -> 0 }t
    t{ ( 32 ) -0.6e0 4 (f.n) s" -0.6000" comp -> 0 }t
    t{ ( 33 ) -0.6e0 16 (f.n) s" -0.6000000000000000" comp -> 0 }t
    t{ ( 34 ) -0.6e0 17 (f.n) s" -0.59999999999999998"
    comp -> 0 }t
    t{ ( 35 ) -0.6e0 23 (f.n) s" -0.59999999999999997779554"
    comp -> 0 }t
    t{ ( 36 ) -0.6e0 25 (f.n) s" -0.5999999999999999777955395"
    comp -> 0 }t
    t{ ( 37 ) 9.1e0 3 (f.n) s" 9.100" comp -> 0 }t
    t{ ( 38 ) 9.51e0 1 (f.n) s" 9.5" comp -> 0 }t
    t{ ( 39 ) 9.55e0 1 (f.n) s" 9.6" comp -> 0 }t
    t{ ( 40 ) -9.66e0 1 (f.n) s" -9.7" comp -> 0 }t
    t{ ( 41 ) 99.995e0 2 (f.n) s" 100.00" comp -> 0 }t
    t{ ( 42 ) 99.625e0 2 (f.n) s" 99.62" comp -> 0 }t
    t{ ( 43 ) 96.62500000000001e 2 (f.n) s" 96.63" comp -> 0 }t
    t{ ( 44 ) 1.247777e3 0 (f.n) s" 1248." comp -> 0 }t
    t{ ( 45 ) 1.247777e3 1 (f.n) s" 1247.8" comp -> 0 }t
    t{ ( 46 ) 1.247777e3 2 (f.n) s" 1247.78" comp -> 0 }t
    t{ ( 47 ) 1.247777e3 3 (f.n) s" 1247.777" comp -> 0 }t
    t{ ( 48 ) -5.0999913335e0 4 (f.n) s" -5.1000" comp -> 0 }t
    t{ ( 49 ) -5.0999913335e0 5 (f.n) s" -5.09999" comp -> 0 }t
    t{ ( 50 ) -5.0999913335e0 6 (f.n) s" -5.099991" comp -> 0 }t
    t{ ( 51 ) -5.0999913335e0 7 (f.n) s" -5.0999913" comp -> 0 }t
    t{ ( 52 ) -5.0999913335e0 8 (f.n) s" -5.09999133" comp -> 0 }t
    t{ ( 53 ) -5.0999913335e0 9 (f.n) s" -5.099991334" comp -> 0 }t
    t{ ( 54 ) 9.599999999e8 0 (f.n) s" 960000000." comp -> 0 }t
    t{ ( 55 ) 0.0e 0 (f.n) s" 0." comp -> 0 }t
    t{ ( 56 ) -0.0e 0 (f.n) s" -0." comp -> 0 }t
    === end code ===



    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Tue Oct 6 14:24:32 2026
    From Newsgroup: comp.lang.forth

    On 10/6/26 1:40 PM, peter wrote:
    On Tue, 6 Oct 2026 05:48:23 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    On 10/6/26 5:30 AM, Krishna Myneni wrote:

    ... The automated tests for
    (F.N) currently work on both kforth64 and kforth64-fast. Two additional
    tests check that the sign of floating point zero is handled correctly
    (it is) -- F0< cannot be used to check for the sign of fp zero.


    The current set of automated tests for (F.N) :

    When I run this I get 3 error. All for 0.6e with 17 23 and 25 decimals.
    The reason is that I use dtoa.c in mode=4. Return shortest string that converts back to original fp number. If I change to mode 2 I get all
    correct. I have mode as a variable that I can set!


    Ah, thanks for that info. I haven't tried using dtoa() in any mode other
    than 2.

    I have updated all three git repos for kForth, kForth-64/32/Win32 to
    include the files fdotn.4th and fdotn-test.4th. They pass the tests in fdotn-test.4th for the most recent versions (downloadable in zip or
    tar.gz form from github):

    kForth-64 v0.8.6
    kForth-32 v2.8.6
    kForth-Win32 v2.7.1

    The test program, fdotn-test.4th, was updated to print the error count
    and also be insensitive to case (this is for INF and NAN). I still have
    to update my implementation of REPRESENT to return these special
    strings, per the Forth standard A.12.6.1.2143.

    --
    Krishna


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Tue Oct 6 16:44:39 2026
    From Newsgroup: comp.lang.forth

    On 10/2/26 10:30 AM, Krishna Myneni wrote:
    ...
    I've also revised your F.N code to work with both separate fp stack and unified data/fp stack systems (since kForth-32 and kForth-Win32 still
    use a unified stack). F.N passes all of my tests on both kForth-64/32.
    ...
    F.N is already a significant improvement over my F.RD word which uses
    the conventional method for fixed point output using f>fpstr:

    \ Convert r to a formatted fixed point string with
    \ n decimal places, 0 <= n <= 17.
    : f>fpstr ( n -- a u ) ( F: r -- ) \ ( r n -- a u )
    0 max 17 min >r 10e r@ s>f f**
    f* fround f>d dup -rot dabs
    <# r> 0 ?DO # LOOP [char] . hold #s rot sign #> ;

    The *measurement* of the absolute frequency of the Strontium-87 optical
    clock (see ref. [1]) is:

    429 228 004 229 873.65 +/- 0.37 Hz

    429228004229873.65e 18 2 f.rd \ field width = 18, decimal places = 2 429228004229873.60 ok


    429228004229873.65e 2 f.n
    429228004229873.62 ok

    The F.N output is a more accurate representation of the average
    measurement. Here, we are already pushing the limits of double precision floating point to store measured numbers.

    --
    Krishna Myneni

    [1] https://arxiv.org/pdf/0804.4509

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Tue Oct 6 18:00:19 2026
    From Newsgroup: comp.lang.forth

    On 10/6/26 4:44 PM, Krishna Myneni wrote:
    ...

    429 228 004 229 873.65 +/- 0.37 Hz

    429228004229873.65e 18 2 f.rd-a \ field width = 18, decimal places = 2 429228004229873.60 ok


    429228004229873.65e 2 f.n
    429228004229873.62-a ok

    The F.N output is a more accurate representation of the average
    measurement. ...
    The output from F.RD is not only farther from the input value, it
    actually does not correspond to any properly rounded binary64 number.
    Exact values for binary64 in this neighborhood are:

    429228004229873.5625
    429228004229873.625
    429228004229873.6875

    Thus the last digit output by F.RD in the example above is garbage.

    --
    KM

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Wed Oct 7 12:19:38 2026
    From Newsgroup: comp.lang.forth

    On 6/10/2026 10:57 pm, Anton Ertl wrote:
    dxf <dxforth@gmail.com> writes:
    On 6/10/2026 5:25 pm, Anton Ertl wrote:
    dxf <dxforth@gmail.com> writes:
    On 6/10/2026 6:50 am, Paul Rubin wrote:
    dxf <dxforth@gmail.com> writes:
    -1 warnings ! works when entered manually. Tried inserting in
    gforthrc0|gforthrc
    definitions but no luck.

    gforthrc is a new thing, does it work at all in your gforth
    installation?

    In Gforth 0.7.9_20200709 for Win there's a file gforthrc.fs in the root >>>> directory with definitions for the above. Beyond that I've no idea.

    It's not the first time I've encountered forths that claim to be able
    to do things, only to find documentation lacking, problems with the
    process, and an unsatisfactory response from the supplier.

    It's not the first time that some user has given insufficient
    information in a bug report, and found the response unsatisfactory.

    From your previous reply it appears you got the information you needed.

    Given that you did not write exactly what you did, I certainly did not
    get the information. The most likely cause of the failure to affect
    WARNINGS is that you modified the wrong file, so in <2026Oct5.192050@mips.complang.tuwien.ac.at> (which you may or may not
    mean with "your previous reply") I showed you how modifying ~/.config/gforthrc actually leads to the result you were interested
    in. Apart from the mention you gave here you did not react to that.

    One might conclude that my last response was satisfactory, except that
    you then wrote something about an "unsatisfactory response", without mentioning any specifics.

    It's the answer that was lacking. All I see are what appears to be
    manual entries at an OS prompt.

    [~/gforth:172258] echo "-1 warnings !" >~/.config/gforthrc
    [~/gforth:172259] gforth

    The stuff in brackets is my shell prompt, and the stuff behind are my
    shell commands.
    ...

    What is the solution for Windows? It's the gforth system I quoted.
    Perhaps there's no simple answer. It would explain your evasions.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Wed Oct 7 06:13:10 2026
    From Newsgroup: comp.lang.forth

    dxf <dxforth@gmail.com> writes:
    On 6/10/2026 10:57 pm, Anton Ertl wrote:
    [~/gforth:172258] echo "-1 warnings !" >~/.config/gforthrc
    [~/gforth:172259] gforth

    The stuff in brackets is my shell prompt, and the stuff behind are my
    shell commands.
    ...

    What is the solution for Windows?

    Our recommendation is WSL2, and in that you can use, e.g., bash, and
    the commands above will work (at least for a Gforth installation that
    also runs on WSL2).

    Given that your request is about something that happens before Gforth
    is started, the answer necessarily provides shell commands. You can
    also create ~/.config/gforthrc from within Gforth, using the words
    =mkdir, create-file, write-file, and close-file. I am sure you can
    figure it out.

    Because I don't use Gforth on Windows, that's where my free support
    ends (and I don't offer paid support).

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Wed Oct 7 02:49:57 2026
    From Newsgroup: comp.lang.forth

    On 10/6/26 1:03 AM, peter wrote:
    On Mon, 5 Oct 2026 17:01:14 -0500
    ...
    If you are working on (f.n) that I posted there are 2 changes I have made later.

    f.n-case-e>0 should be

    : f.n-case-e>0 ( F:fp n e -- )
    over + \ n e+n
    fpad 1024 '0' fill
    fpad swap represent 2drop \ n e'
    dup >r \ n e' r: e'
    fpad swap stype
    dup 0 >= if 46 semit then \ n
    fpad r> + \ n fpad+e'
    swap 0 max stype ;

    This will prevent the dot to be printed at the end when using negative n.

    The other is in a comment

    : .sign ( f -- )
    13 and 32 + semit ; \ prints bl for positive
    \ if 45 semit then ; \ use this to only print -

    The code I posted have 32 in the commented out part!
    It would print a blank instead of a -
    ...

    In the definition of (F.N) you use an argument of u = 32 significant
    digits to REPRESENT. I did not understand why you chose this particular
    number to obtain the decimal exponent (exp). I changed this to 17 and
    all of the tests in fdotn-test.4th still pass.

    : (f.n) ...
    fdup fabs fswap fpad ( 32) 17 represent \ find exp and sign

    Since binary -> decimal conversion with 17 significant digits is
    guaranteed to cycle in a round trip for binary64, I think 17 will
    suffice here for obtaining the correct decimal exponent.

    --
    Krishna


    --
    Krishna

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Wed Oct 7 08:10:11 2026
    From Newsgroup: comp.lang.forth

    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    Since binary -> decimal conversion with 17 significant digits is
    guaranteed to cycle in a round trip for binary64

    It will give you a binary->decimal->binary round trip, but the decimal
    number is not always the shortest one that gives this FP number. E.g.:

    0.9e 17 e.p \ .90000000000000002e

    while obviously "0.9e" already gives you this FP number. E. tries
    15-17 digits, and outputs the first one where the round trip works.

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Wed Oct 7 08:21:13 2026
    From Newsgroup: comp.lang.forth

    On 10/7/26 3:10 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    Since binary -> decimal conversion with 17 significant digits is
    guaranteed to cycle in a round trip for binary64

    It will give you a binary->decimal->binary round trip, but the decimal
    number is not always the shortest one that gives this FP number. E.g.:

    0.9e 17 e.p \ .90000000000000002e

    while obviously "0.9e" already gives you this FP number. E. tries
    15-17 digits, and outputs the first one where the round trip works.


    Ok, but that's not what's needed for implementing F.N where the number
    of decimal places, to which the output is rounded, is specified. IOW it
    will not be equivalent to the Fortran F format.

    --
    KM



    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Thu Oct 8 02:01:10 2026
    From Newsgroup: comp.lang.forth

    On 7/10/2026 5:13 pm, Anton Ertl wrote:
    dxf <dxforth@gmail.com> writes:
    On 6/10/2026 10:57 pm, Anton Ertl wrote:
    [~/gforth:172258] echo "-1 warnings !" >~/.config/gforthrc
    [~/gforth:172259] gforth

    The stuff in brackets is my shell prompt, and the stuff behind are my
    shell commands.
    ...

    What is the solution for Windows?

    Our recommendation is WSL2, and in that you can use, e.g., bash, and
    the commands above will work (at least for a Gforth installation that
    also runs on WSL2).

    Given that your request is about something that happens before Gforth
    is started, the answer necessarily provides shell commands. You can
    also create ~/.config/gforthrc from within Gforth, using the words
    =mkdir, create-file, write-file, and close-file. I am sure you can
    figure it out.

    Because I don't use Gforth on Windows, that's where my free support
    ends (and I don't offer paid support).

    The solution was staring me in the face and I couldn't see it. Uninstall.
    I'd long wondered to whom the moron-level warnings in Gforth were directed.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Wed Oct 7 14:58:44 2026
    From Newsgroup: comp.lang.forth

    On 10/6/26 4:44 PM, Krishna Myneni wrote:
    On 10/2/26 10:30 AM, Krishna Myneni wrote:
    ...
    I've also revised your F.N code to work with both separate fp stack
    and unified data/fp stack systems (since kForth-32 and kForth-Win32
    still use a unified stack). F.N passes all of my tests on both
    kForth-64/32.
    ...
    F.N is already a significant improvement over my F.RD word which uses
    the conventional method for fixed point output using f>fpstr:

    \ Convert r to a formatted fixed point string with
    \ n decimal places, 0 <= n <= 17.
    : f>fpstr ( n -- a u ) ( F: r -- ) \ ( r n -- a u )
    -a-a-a 0 max 17 min >r 10e r@ s>f f**
    -a-a-a f* fround f>d dup -rot dabs
    -a-a-a <# r> 0 ?DO # LOOP [char] . hold #s rot sign #> ;
    ...

    It dawned on me that F>FPSTR is just an implementation of (F.N) -- the
    string output version of F.N . Beyond the example I gave above, what's
    wrong with this implementation? I can rename the word to (F.N) and use
    my automated tests in fdotn-test.4th to test F>FPSTR.

    : (f.n) f>fpstr ;

    With the definition above, I obtain 7 errors for the following tests:
    29, 30, 31, 34, 35, 36, and 56.

    The implementation of F>FPSTR was designed to handle no more than 17
    decimal places, which explains why it fails for tests requesting more
    than 17 decimal places: 29, 30, 31, 35, and 36.

    Eliminating these tests leaves two remaining tests of F>FPSTR which
    failed for some reason other than asking for too many decimal places:

    34: -0.6e0 17 (f.n) type -0.60000000000000000 ok
    56: -0.0e 0 (f.n) type 0. ok

    The failure of test 56 occurred because we lost the sign of -0.0e when performing F>D so this is understood.

    The failure of converting the binary64 representation of -0.6e0 to 17
    decimal places, even though it looks like it is correct, is not, because
    the only double precision numbers which can be represented near the
    decimal input, -0.6e0 are

    before: -0.600000000000000088817841970012523233890533447265625
    x: -0.59999999999999997779553950749686919152736663818359375
    after: -0.5999999999999998667732370449812151491641998291015625

    The closest number is the middle number, which, rounded to 17 decimal
    places, is

    -0.59999999999999998

    Why does F>FPSTR shows the output as "-0.60000000000000000"? This is due
    to a fortuitous coincidence for the numbers which are represented in
    double precision at -0.6e17, which is the intermediate computation of
    FPSTR before converting to a double length integer. The actual numbers
    which can be represented around -0.6e-17 are spaced like this:

    before: -60000000000000008
    x: -60000000000000000
    after: -59999999999999992

    The middle number happens to be a match for the expected output,

    -0.60000000000000000

    The algorithm for F>FPSTR is falling on the double precision numbers in
    the region of the scaled number, which can turn out badly if we did not
    have the coincidence of landing on an exact representation after the
    scaling e.g. 0.61100000000009990e

    The double precision numbers in the unscaled region are
    before: 0.61100000000009979661541592577123083174228668212890625
    x: 0.6110000000000999076377183882868848741054534912109375
    after: 0.61100000000010001866002085080253891646862030029296875

    The center value x, rounded to 17 decimal places is

    0.61100000000009991e

    which is what is printed by our more accurate REPRESENT-based (f.n)
    defined in fdotn.4th:

    0.61100000000009990e 17 (f.n) type
    0.61100000000009991 ok

    In contrast the scaled region used by F>FPSTR has the possible double precision numbers

    before: 61100000000009984
    x: 61100000000009992
    after: 61100000000010000

    with the closest being 61100000000009992 to the scaled input number. Hence,

    0.61100000000009990e 17 f>fpstr type
    0.61100000000009992 ok


    --
    KM










    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Wed Oct 7 22:35:26 2026
    From Newsgroup: comp.lang.forth

    On Wed, 7 Oct 2026 02:49:57 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    On 10/6/26 1:03 AM, peter wrote:
    On Mon, 5 Oct 2026 17:01:14 -0500
    ...
    If you are working on (f.n) that I posted there are 2 changes I have made later.

    f.n-case-e>0 should be

    : f.n-case-e>0 ( F:fp n e -- )
    over + \ n e+n
    fpad 1024 '0' fill
    fpad swap represent 2drop \ n e'
    dup >r \ n e' r: e'
    fpad swap stype
    dup 0 >= if 46 semit then \ n
    fpad r> + \ n fpad+e'
    swap 0 max stype ;

    This will prevent the dot to be printed at the end when using negative n.

    The other is in a comment

    : .sign ( f -- )
    13 and 32 + semit ; \ prints bl for positive
    \ if 45 semit then ; \ use this to only print -

    The code I posted have 32 in the commented out part!
    It would print a blank instead of a -
    ...

    In the definition of (F.N) you use an argument of u = 32 significant
    digits to REPRESENT. I did not understand why you chose this particular number to obtain the decimal exponent (exp). I changed this to 17 and
    all of the tests in fdotn-test.4th still pass.

    : (f.n) ...
    fdup fabs fswap fpad ( 32) 17 represent \ find exp and sign

    Since binary -> decimal conversion with 17 significant digits is
    guaranteed to cycle in a round trip for binary64, I think 17 will
    suffice here for obtaining the correct decimal exponent.

    There were no real reason. The result at fpad is used only for
    INF and NAN. I also wanted a number larger then 17, 32 looked like
    a good round number. The importance of the first call to represent
    is to get a correct exp to use in the following calculations.
    The second time represent is called it will be with u=exp+n to get
    the correct rounding.

    Peter

    --
    Krishna


    --
    Krishna



    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Wed Oct 7 16:59:31 2026
    From Newsgroup: comp.lang.forth

    On 10/7/26 3:35 PM, peter wrote:
    On Wed, 7 Oct 2026 02:49:57 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    ...

    In the definition of (F.N) you use an argument of u = 32 significant
    digits to REPRESENT. I did not understand why you chose this particular
    number to obtain the decimal exponent (exp). I changed this to 17 and
    all of the tests in fdotn-test.4th still pass.

    : (f.n) ...
    fdup fabs fswap fpad ( 32) 17 represent \ find exp and sign

    Since binary -> decimal conversion with 17 significant digits is
    guaranteed to cycle in a round trip for binary64, I think 17 will
    suffice here for obtaining the correct decimal exponent.

    There were no real reason. The result at fpad is used only for
    INF and NAN. I also wanted a number larger then 17, 32 looked like
    a good round number. The importance of the first call to represent
    is to get a correct exp to use in the following calculations.
    The second time represent is called it will be with u=exp+n to get
    the correct rounding.


    There may be an efficiency gain to going with the minimum number of significant digits to get the exponent. I haven't benchmarked it, but
    big number arithmetic comes into play when dealing with such a large
    number of significant digits.

    --
    KM

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Wed Oct 7 21:17:45 2026
    From Newsgroup: comp.lang.forth

    On 10/7/26 4:59 PM, Krishna Myneni wrote:
    On 10/7/26 3:35 PM, peter wrote:
    On Wed, 7 Oct 2026 02:49:57 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    ...

    In the definition of (F.N) you use an argument of u = 32 significant
    digits to REPRESENT. I did not understand why you chose this particular
    number to obtain the decimal exponent (exp). I changed this to 17 and
    all of the tests in fdotn-test.4th still pass.

    : (f.n) ...
    -a-a fdup fabs fswap fpad ( 32) 17 represent-a \ find exp and sign

    Since binary -> decimal conversion with 17 significant digits is
    guaranteed to cycle in a round trip for binary64, I think 17 will
    suffice here for obtaining the correct decimal exponent.

    There were no real reason. The result at fpad is used only for
    INF and NAN. I also wanted a number larger then 17, 32 looked like
    a good round number. The importance of the first call to represent
    is to get a correct exp to use in the following calculations.
    The second time represent is called it will be with u=exp+n to get
    the correct rounding.


    There may be an efficiency gain to going with the minimum number of significant digits to get the exponent. I haven't benchmarked it, but
    big number arithmetic comes into play when dealing with such a large
    number of significant digits.


    Initial tests show there is no appreciable difference in execution time between using 32 significant digits and 17 significant digits in the
    initial call to REPRESENT for benchmarking (F.N).

    Also, the F>FPSTR method of obtaining the string to n decimal places is approximately twice as fast as the REPRESENT-based (F.N) method, but the latter is more versatile (works over a larger range of n). Incidentally,
    I replaced raising 10.0e0 to the n^th power via F** with FALOG in the
    defn of F>FPSTR.

    --
    KM


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Thu Oct 8 13:34:33 2026
    From Newsgroup: comp.lang.forth

    On 8/10/2026 7:35 am, peter wrote:
    ...
    There were no real reason. The result at fpad is used only for
    INF and NAN. I also wanted a number larger then 17, 32 looked like
    a good round number. The importance of the first call to represent
    is to get a correct exp to use in the following calculations.
    The second time represent is called it will be with u=exp+n to get
    the correct rounding.

    Are you sure it's necessary? Your tests appear to work with it set at 5.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Wed Oct 7 21:51:32 2026
    From Newsgroup: comp.lang.forth

    On 10/7/26 9:17 PM, Krishna Myneni wrote:
    On 10/7/26 4:59 PM, Krishna Myneni wrote:
    ...
    Also, the F>FPSTR method of obtaining the string to n decimal places is approximately twice as fast as the REPRESENT-based (F.N) method, but the latter is more versatile (works over a larger range of n). ...
    Also, the ability to use -n to round the integer part of a number to n significant digits is awesome!

    Example:

    1906.0e 0 f.n 1906. ok \ round to 1's place, 4 sig digits
    1906.0e -1 f.n 1910 ok \ round to 10's place, 3 sig digits
    1906.0e -2 f.n 1900 ok \ round to 100's place, 2 sig digits
    1906.0e -3 f.n 2000 ok \ round to 1000's place, 1 sig digit

    Note there is a trailing decimal point for rounding to the 1's place
    (n=0): all four digits are significant.

    There is no trailing decimal point for n = -1 through -3 which is
    appropriate -- the trailing zeros are not significant. For integers,
    trailing zeros would only be significant if a decimal point appears at
    the end.

    --
    KM

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Thu Oct 8 12:13:02 2026
    From Newsgroup: comp.lang.forth

    On Thu, 8 Oct 2026 13:34:33 +1100
    dxf <dxforth@gmail.com> wrote:

    On 8/10/2026 7:35 am, peter wrote:
    ...
    There were no real reason. The result at fpad is used only for
    INF and NAN. I also wanted a number larger then 17, 32 looked like
    a good round number. The importance of the first call to represent
    is to get a correct exp to use in the following calculations.
    The second time represent is called it will be with u=exp+n to get
    the correct rounding.

    Are you sure it's necessary? Your tests appear to work with it set at 5.


    You might be right!
    My first concern was for number like
    9.9999999995e that will round up all the way and get a exp+1
    But it looks like the code handles that also.

    The problem was 99.995e 2 f.n that became 100.0
    But that was solved also by pre-filling the buffer with 0 and always
    printing the correct number of decimals

    BR
    Peter

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Thu Oct 8 15:26:45 2026
    From Newsgroup: comp.lang.forth

    On Thu, 8 Oct 2026 12:13:02 +0200
    peter <peter.noreply@tin.it> wrote:

    On Thu, 8 Oct 2026 13:34:33 +1100
    dxf <dxforth@gmail.com> wrote:

    On 8/10/2026 7:35 am, peter wrote:
    ...
    There were no real reason. The result at fpad is used only for
    INF and NAN. I also wanted a number larger then 17, 32 looked like
    a good round number. The importance of the first call to represent
    is to get a correct exp to use in the following calculations.
    The second time represent is called it will be with u=exp+n to get
    the correct rounding.

    Are you sure it's necessary? Your tests appear to work with it set at 5.


    You might be right!
    My first concern was for number like
    9.9999999995e that will round up all the way and get a exp+1
    But it looks like the code handles that also.

    The problem was 99.995e 2 f.n that became 100.0
    But that was solved also by pre-filling the buffer with 0 and always
    printing the correct number of decimals

    BR
    Peter


    Thanks to dxf's question I continued testing and found an error.

    0.999955555e 2 f.n 0.0100

    What happened was that in this case exp from the first represent is 0
    in the test to choose action f.n-case-e<=0 get chosen. In this part
    exp is recalculated and became 1!
    The correction is to move the second represent earlier before choosing.

    the relevant code will become

    : f.n-case-e>0 ( F:fp n e -- )
    \ 3 lines deleted
    dup >r \ n e' r: e'
    fpad swap type
    dup 0 >= if '.' emit then \ n
    fpad r> + \ n fpad+e'
    swap 0 max type ;

    : f.n-case-e<=0 ( F:fp n e -- )
    \ 3 lines deleted
    dup >r \ n e' r: e'
    ." 0." abs 0 ?do '0' emit loop
    fpad swap r> + \ fpad n+e'
    type ;

    : f.n ( F:fp n -- )
    fdup fpad 32 represent \ find exp and sign
    swap .sign fabs \ if '-' emit fabs then \ print the sign
    0= if 2drop fdrop
    fpad 3 type exit then \ print nan or inf
    over 0< if
    swap over 1- negate max swap else \ limit negative n
    swap over 1024 swap - min swap then \ limit positive n
    2dup 0 <= swap 0= and \ n e f
    if 2drop f.n-case-00 exit then
    2dup + 0<
    if drop f.n-case-e+n<0 exit then
    2dup + 0=
    if f.n-case-e+n=0 exit then
    \ the 3 lines added here
    over + 1 max \ n e+n
    fpad 1024 '0' fill
    fpad swap represent 2drop \ n e'

    dup 0>
    if f.n-case-e>0 exit then
    f.n-case-e<=0 ;

    The same changes need to be done on the (f.n) words

    Now also this case will round correctly

    0.999955555e 2 f.n 1.00

    BR
    Peter


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Thu Oct 8 09:18:57 2026
    From Newsgroup: comp.lang.forth

    On 10/8/26 8:26 AM, peter wrote:
    On Thu, 8 Oct 2026 12:13:02 +0200
    peter <peter.noreply@tin.it> wrote:

    On Thu, 8 Oct 2026 13:34:33 +1100
    dxf <dxforth@gmail.com> wrote:

    On 8/10/2026 7:35 am, peter wrote:
    ...
    There were no real reason. The result at fpad is used only for
    INF and NAN. I also wanted a number larger then 17, 32 looked like
    a good round number. The importance of the first call to represent
    is to get a correct exp to use in the following calculations.
    The second time represent is called it will be with u=exp+n to get
    the correct rounding.

    Are you sure it's necessary? Your tests appear to work with it set at 5. >>>

    You might be right!
    My first concern was for number like
    9.9999999995e that will round up all the way and get a exp+1
    But it looks like the code handles that also.

    The problem was 99.995e 2 f.n that became 100.0
    But that was solved also by pre-filling the buffer with 0 and always
    printing the correct number of decimals

    BR
    Peter


    Thanks to dxf's question I continued testing and found an error.

    0.999955555e 2 f.n 0.0100

    What happened was that in this case exp from the first represent is 0
    in the test to choose action f.n-case-e<=0 get chosen. In this part
    exp is recalculated and became 1!
    The correction is to move the second represent earlier before choosing.

    the relevant code will become

    : f.n-case-e>0 ( F:fp n e -- )
    \ 3 lines deleted
    dup >r \ n e' r: e'
    fpad swap type
    dup 0 >= if '.' emit then \ n
    fpad r> + \ n fpad+e'
    swap 0 max type ;

    : f.n-case-e<=0 ( F:fp n e -- )
    \ 3 lines deleted
    dup >r \ n e' r: e'
    ." 0." abs 0 ?do '0' emit loop
    fpad swap r> + \ fpad n+e'
    type ;

    : f.n ( F:fp n -- )
    fdup fpad 32 represent \ find exp and sign
    swap .sign fabs \ if '-' emit fabs then \ print the sign
    0= if 2drop fdrop
    fpad 3 type exit then \ print nan or inf
    over 0< if
    swap over 1- negate max swap else \ limit negative n
    swap over 1024 swap - min swap then \ limit positive n
    2dup 0 <= swap 0= and \ n e f
    if 2drop f.n-case-00 exit then
    2dup + 0<
    if drop f.n-case-e+n<0 exit then
    2dup + 0=
    if f.n-case-e+n=0 exit then
    \ the 3 lines added here
    over + 1 max \ n e+n
    fpad 1024 '0' fill
    fpad swap represent 2drop \ n e'

    dup 0>
    if f.n-case-e>0 exit then
    f.n-case-e<=0 ;

    The same changes need to be done on the (f.n) words

    Now also this case will round correctly

    0.999955555e 2 f.n 1.00

    BR
    Peter



    Would you please attach the complete code when you get a chance since
    several revisions have been made?

    Also, I found the following issue with n < 0. It's possible I introduced
    a bug in my revisions of your code, or that I missed some change.

    0.1e -1 (f.n) type 0.1 ok \ should be "0."
    0.01e -1 (f.n) type 0.01 ok \ should be "0."
    0.1e -2 (f.n) type 0.1 ok \ should be "0."

    and similar.

    --
    Krishna


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Thu Oct 8 22:07:46 2026
    From Newsgroup: comp.lang.forth

    On Thu, 8 Oct 2026 09:18:57 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    On 10/8/26 8:26 AM, peter wrote:
    On Thu, 8 Oct 2026 12:13:02 +0200
    peter <peter.noreply@tin.it> wrote:

    On Thu, 8 Oct 2026 13:34:33 +1100
    dxf <dxforth@gmail.com> wrote:

    On 8/10/2026 7:35 am, peter wrote:
    ...
    There were no real reason. The result at fpad is used only for
    INF and NAN. I also wanted a number larger then 17, 32 looked like
    a good round number. The importance of the first call to represent
    is to get a correct exp to use in the following calculations.
    The second time represent is called it will be with u=exp+n to get
    the correct rounding.

    Are you sure it's necessary? Your tests appear to work with it set at 5. >>>

    You might be right!
    My first concern was for number like
    9.9999999995e that will round up all the way and get a exp+1
    But it looks like the code handles that also.

    The problem was 99.995e 2 f.n that became 100.0
    But that was solved also by pre-filling the buffer with 0 and always
    printing the correct number of decimals

    BR
    Peter


    Thanks to dxf's question I continued testing and found an error.

    0.999955555e 2 f.n 0.0100

    What happened was that in this case exp from the first represent is 0
    in the test to choose action f.n-case-e<=0 get chosen. In this part
    exp is recalculated and became 1!
    The correction is to move the second represent earlier before choosing.



    Would you please attach the complete code when you get a chance since several revisions have been made?

    Also, I found the following issue with n < 0. It's possible I introduced
    a bug in my revisions of your code, or that I missed some change.

    0.1e -1 (f.n) type 0.1 ok \ should be "0."
    0.01e -1 (f.n) type 0.01 ok \ should be "0."
    0.1e -2 (f.n) type 0.1 ok \ should be "0."

    and similar.

    --
    Krishna

    No they were actually designed to behave like that! I made it so that
    when an impossible combination of exp and n were found n was set to a
    value that showed the number with one significant digit. That is exactly
    what happens in the above tests. But I agree with you when both exp and n
    are negative n will be set as 0 and the number rounded to 1. or 0.
    I have implemented that test now. I also restructured the code better
    and combined 2 cases into one case normal.

    Below follows code for both F.N and (F.N) tested on kForth64

    BR
    Peter

    F.N
    \ F.N print float to n decimals

    create fpad 1024 allot

    : .sign ( f -- )
    13 and 32 + emit ; \ prints bl for positive

    : one-or-zero ( F:fp -- ) \ exp<=0 n=0 round to +-1 or 0
    fround>s 48 + emit ;

    : f.n-case-00 ( F:fp -- ) \ exp<=0 n=0 round to +-1 or 0
    one-or-zero 46 emit ;

    : f.n-case-e+n<0 ( F:fp n -- )
    fdrop
    ." 0."
    0 ?do 48 emit loop ;

    : f.n-case-e+n=0 ( F:fp n e -- )
    fdup abs s>f falog f* fswap \ prepare fp for rounding
    1- f.n-case-e+n<0 \ print 1 less zero
    one-or-zero ;

    : f.n-case-normal ( F:fp n e -- )
    over + 1 max \ n e+n
    fpad 1024 48 fill
    fpad swap represent 2drop \ n e'
    dup >r dup 0> \ n e' f r: e'
    if \ exp >0
    fpad swap type
    dup 0 >= if 46 emit then \ n
    fpad r> + \ n fpad+e'
    swap 0 max type
    else \ exp <=0
    ." 0." abs 0 ?do 48 emit loop
    fpad swap r> + \ fpad n+e'
    type
    then ;


    : f.n ( F:fp n -- )
    fdup fpad 32 represent \ find exp and sign
    swap .sign fabs \ print the sign
    0= if 2drop fdrop
    fpad 3 type exit then \ print nan or inf
    over 0< if
    dup 0 <= if nip 0 swap else \ negative e and n
    swap over 1- negate max swap \ limit negative n
    else swap over 1024 swap - min swap then then \ limit positive n
    2dup 0 <= swap 0= and \ n e f
    if 2drop f.n-case-00 exit then
    2dup + 0<
    if drop f.n-case-e+n<0 exit then
    2dup + 0=
    if f.n-case-e+n=0 exit then
    f.n-case-normal ;

    \ 0 [IF]
    \ Test cases
    : testing cr begin refill while source 2dup type space evaluate cr repeat ; testing
    0.9e 0 f.n
    0.3e 0 f.n
    -0.9e 0 f.n
    -0.3e 0 f.n

    0.123e 0 f.n
    0.123e-1 1 f.n
    0.123e-2 2 f.n
    0.123e-3 3 f.n

    0.823e 0 f.n
    0.823e-1 1 f.n
    0.823e-2 2 f.n
    0.823e-3 3 f.n

    0.1368e 3 f.n
    -0.1368e-1 3 f.n
    0.1368e-2 3 f.n
    -0.1368e-3 3 f.n
    0.1368e-4 3 f.n

    -0.8368e 3 f.n
    -0.8368e-1 3 f.n
    -0.8368e-2 3 f.n
    -0.8368e-3 3 f.n
    -0.8368e-4 3 f.n

    126.8567e 3 f.n
    126.8567e 2 f.n
    126.8567e 1 f.n
    126.8567e 0 f.n
    126.8567e -1 f.n
    126.8567e -2 f.n
    126.8567e -3 f.n

    99.995e 3 f.n
    99.995e 2 f.n
    99.995e 1 f.n

    0.999955555e 0 f.n
    0.999955555e 1 f.n
    0.999955555e 2 f.n
    0.999955555e 3 f.n
    0.999955555e 4 f.n
    0.999955555e 5 f.n

    5.2345678e-1 10 f.n
    5.2345678e-2 10 f.n
    5.2345678e-3 10 f.n
    5.2345678e-4 10 f.n
    5.2345678e-5 10 f.n
    5.2345678e-6 10 f.n
    5.2345678e-7 10 f.n
    5.2345678e-8 10 f.n
    5.2345678e-9 10 f.n
    5.2345678e-10 10 f.n
    5.2345678e-11 10 f.n
    5.2345678e-12 10 f.n

    -1e 0e f/ 5 f.n
    0e 0e f/ 5 f.n

    \ Krishna Myneni tests

    0.0051e 0 f.n
    0.0051e 1 f.n
    0.0051e 2 f.n
    0.0051e 3 f.n
    0.0051e 4 f.n
    0.0051e 5 f.n
    0.0051e 17 f.n
    2.0e-15 17 f.n

    0.0e 0 f.n
    0.1e 0 f.n
    0.2e 0 f.n
    0.4e 0 f.n
    0.5e 0 f.n
    0.51e 0 f.n

    0.500000000000000001e 0 f.n
    0.50000000000000001e 0 f.n
    0.5000000000000001e 0 f.n

    0.6e 0 f.n
    0.9e 0 f.n
    1.0e 0 f.n
    1.4e 0 f.n
    1.4999999e 0 f.n
    1.5e 0 f.n
    2.5e 0 f.n
    3.5e 0 f.n

    -1100.2e 0 f.n
    -1100.5e 0 f.n
    -1101.5e 0 f.n
    -1102.5e 0 f.n

    2.01682663070034556e16 0 f.n
    2.01682663070034556e16 20 f.n

    0.5e 25 f.n
    0.625e 25 f.n
    0.625e 25 f.n

    -0.6e 4 f.n
    -0.6e 16 f.n
    -0.6e 17 f.n
    -0.6e 23 f.n
    -0.6e 25 f.n

    9.1e 3 f.n
    9.51e 1 f.n
    9.55e 1 f.n
    -9.66e 1 f.n

    99.995e 2 f.n
    99.625e 2 f.n
    96.62500000000001e 2 f.n

    1.247777e3 0 f.n
    1.247777e3 1 f.n
    1.247777e3 2 f.n
    1.247777e3 3 f.n

    -5.0999913335e0 4 f.n
    -5.0999913335e0 5 f.n
    -5.0999913335e0 6 f.n
    -5.0999913335e0 7 f.n
    -5.0999913335e0 8 f.n
    -5.0999913335e0 9 f.n

    9.599999999e8 0 f.n

    0.1e -1 f.n
    0.1e -2 f.n
    0.01e -1 f.n

    0.75e -1 f.n
    0.75e -2 f.n
    0.075e -1 f.n

    \ test large arguments
    123e300 10 f.n
    123e-300 305 f.n
    123e-30 40 f.n
    \ end of tests
    \ [THEN]

    Here is the code for (F.N)

    \ (F.N) print float with n decimals to string

    \ Cell counted string words
    -1 [if]
    : xcount ( addr -- addr+cell count )
    dup @ swap cell+ swap ;

    : xappend ( addr n addr2 -- ) \ append string to string at addr2
    2dup 2>r
    xcount + swap cmove
    r> xcount r> + swap 1 cells - ! ;

    : xplace ( addr n addr2 -- ) \ place string to string at addr2
    dup 0 swap !
    xappend ;

    : cxappend ( c addr2 -- ) \ append c to end of string at addr2
    dup >r xcount + c!
    1 r> +! ;

    : cxfill ( n c addr2 -- ) \ append n cs to the end of string at addr2
    >r over r@ swap >r
    xcount + -rot fill
    r> r> +! ;

    \ redirect output to memory

    VARIABLE (string-buf)

    : sbuf (string-buf) @ ;

    : sbuf> sbuf xcount ;

    : init-string-buf ( addr -- addr-old) \ retrieve addr-old from string-buf, place addr there
    (string-buf) @ swap
    dup 0 swap ! (string-buf) ! ;

    : >sbuf> ( addr-old -- addr len ) \ retrieve addr len and set string-buf to old value
    >r sbuf xcount
    r> (string-buf) ! ;

    : semit ( c -- ) \ type to buffer
    sbuf cxappend ;

    : stype ( addr len -- )
    sbuf xappend ;

    : sfill ( n c -- ) \ fill buffer with n cs
    \ over 0= if 2drop exit then
    sbuf cxfill ;

    : nl 10 semit ;

    : s. s>d swap over dabs <# #s rot sign #> stype ;

    : strbuf 1024 allocate throw ;

    [then]
    \ (F.N) print float to n decimals

    create fpad 1024 allot

    : .sign ( f -- )
    13 and 32 + semit ; \ prints bl for positive
    \ if 45 semit then ; \ use this to only print -

    : .zeros ( n -- )
    48 sfill ;

    : s"0." s" 0." stype ;

    : one-or-zero ( F:fp -- ) \ exp<=0 n=0 round to +-1 or 0
    fround>s 48 + semit ;

    : f.n-case-00 ( F:fp -- ) \ exp<=0 n=0 round to +-1 or 0
    one-or-zero 46 semit ;

    : f.n-case-e+n<0 ( F:fp n -- )
    fdrop
    s"0." .zeros ;

    : f.n-case-e+n=0 ( F:fp n e -- )
    fdup abs s>f falog f* fswap \ prepare fp for rounding
    1- f.n-case-e+n<0 \ print 1 less zero
    one-or-zero ;

    : f.n-case-normal ( F:fp n e -- )
    over + 1 max \ n e+n
    fpad 1024 48 fill
    fpad swap represent 2drop \ n e'
    dup >r dup 0> \ n e' f r: e'
    if \ exp >0
    fpad swap stype
    dup 0 >= if 46 semit then \ n
    fpad r> + \ n fpad+e'
    swap 0 max stype
    else \ exp <=0
    s"0." abs .zeros
    fpad swap r> + \ fpad n+e'
    stype
    then ;

    : (f.n) ( F:fp n -- )
    strbuf init-string-buf >r
    fdup fpad 32 represent \ find exp and sign
    swap .sign fabs \ print the sign
    0= if 2drop fdrop
    fpad 3 stype else \ print nan or inf
    over 0< if
    dup 0 <= if nip 0 swap else \ negative e and n
    swap over 1- negate max swap \ limit negative n
    else swap over 1024 swap - min swap then then \ limit positive n
    2dup 0 <= swap 0= and \ n e f
    if 2drop f.n-case-00 else
    2dup + 0<
    if drop f.n-case-e+n<0 else
    2dup + 0=
    if f.n-case-e+n=0 else
    f.n-case-normal
    then then then then r> >sbuf> ;

    : f.n (f.n) type space ;



    \ 0 [IF]
    \ Test cases
    : testing cr begin refill while source 2dup type space evaluate cr repeat ; testing
    0.9e 0 f.n
    0.3e 0 f.n
    -0.9e 0 f.n
    -0.3e 0 f.n

    0.123e 0 f.n
    0.123e-1 1 f.n
    0.123e-2 2 f.n
    0.123e-3 3 f.n

    0.823e 0 f.n
    0.823e-1 1 f.n
    0.823e-2 2 f.n
    0.823e-3 3 f.n

    0.1368e 3 f.n
    -0.1368e-1 3 f.n
    0.1368e-2 3 f.n
    -0.1368e-3 3 f.n
    0.1368e-4 3 f.n

    -0.8368e 3 f.n
    -0.8368e-1 3 f.n
    -0.8368e-2 3 f.n
    -0.8368e-3 3 f.n
    -0.8368e-4 3 f.n

    126.8567e 3 f.n
    126.8567e 2 f.n
    126.8567e 1 f.n
    126.8567e 0 f.n
    126.8567e -1 f.n
    126.8567e -2 f.n
    126.8567e -3 f.n

    99.995e 3 f.n
    99.995e 2 f.n
    99.995e 1 f.n

    0.999955555e 0 f.n
    0.999955555e 1 f.n
    0.999955555e 2 f.n
    0.999955555e 3 f.n
    0.999955555e 4 f.n
    0.999955555e 5 f.n

    5.2345678e-1 10 f.n
    5.2345678e-2 10 f.n
    5.2345678e-3 10 f.n
    5.2345678e-4 10 f.n
    5.2345678e-5 10 f.n
    5.2345678e-6 10 f.n
    5.2345678e-7 10 f.n
    5.2345678e-8 10 f.n
    5.2345678e-9 10 f.n
    5.2345678e-10 10 f.n
    5.2345678e-11 10 f.n
    5.2345678e-12 10 f.n

    -1e 0e f/ 5 f.n
    0e 0e f/ 5 f.n

    \ Krishna Myneni tests

    0.0051e 0 f.n
    0.0051e 1 f.n
    0.0051e 2 f.n
    0.0051e 3 f.n
    0.0051e 4 f.n
    0.0051e 5 f.n
    0.0051e 17 f.n
    2.0e-15 17 f.n

    0.0e 0 f.n
    0.1e 0 f.n
    0.2e 0 f.n
    0.4e 0 f.n
    0.5e 0 f.n
    0.51e 0 f.n

    0.500000000000000001e 0 f.n
    0.50000000000000001e 0 f.n
    0.5000000000000001e 0 f.n

    0.6e 0 f.n
    0.9e 0 f.n
    1.0e 0 f.n
    1.4e 0 f.n
    1.4999999e 0 f.n
    1.5e 0 f.n
    2.5e 0 f.n
    3.5e 0 f.n

    -1100.2e 0 f.n
    -1100.5e 0 f.n
    -1101.5e 0 f.n
    -1102.5e 0 f.n

    2.01682663070034556e16 0 f.n
    2.01682663070034556e16 20 f.n

    0.5e 25 f.n
    0.625e 25 f.n
    0.625e 25 f.n

    -0.6e 4 f.n
    -0.6e 16 f.n
    -0.6e 17 f.n
    -0.6e 23 f.n
    -0.6e 25 f.n

    9.1e 3 f.n
    9.51e 1 f.n
    9.55e 1 f.n
    -9.66e 1 f.n

    99.995e 2 f.n
    99.625e 2 f.n
    96.62500000000001e 2 f.n

    1.247777e3 0 f.n
    1.247777e3 1 f.n
    1.247777e3 2 f.n
    1.247777e3 3 f.n

    -5.0999913335e0 4 f.n
    -5.0999913335e0 5 f.n
    -5.0999913335e0 6 f.n
    -5.0999913335e0 7 f.n
    -5.0999913335e0 8 f.n
    -5.0999913335e0 9 f.n

    9.599999999e8 0 f.n

    0.1e -1 f.n
    0.1e -2 f.n
    0.01e -1 f.n

    0.75e -1 f.n
    0.75e -2 f.n
    0.075e -1 f.n

    \ test large arguments
    123e300 10 f.n
    123e-300 305 f.n
    \ [THEN]





    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Fri Oct 9 14:29:00 2026
    From Newsgroup: comp.lang.forth

    On 8/10/2026 9:13 pm, peter wrote:
    On Thu, 8 Oct 2026 13:34:33 +1100
    dxf <dxforth@gmail.com> wrote:

    On 8/10/2026 7:35 am, peter wrote:
    ...
    There were no real reason. The result at fpad is used only for
    INF and NAN. I also wanted a number larger then 17, 32 looked like
    a good round number. The importance of the first call to represent
    is to get a correct exp to use in the following calculations.
    The second time represent is called it will be with u=exp+n to get
    the correct rounding.

    Are you sure it's necessary? Your tests appear to work with it set at 5.


    You might be right!
    My first concern was for number like
    9.9999999995e that will round up all the way and get a exp+1
    But it looks like the code handles that also.

    There a risk when extracting the exponent on its own. As Anton pointed out
    in another thread REPRESENT at least keeps mantissa and exponent in sync.

    The problem was 99.995e 2 f.n that became 100.0
    ...

    Every REPRESENT I know gives that:

    99.995e pad 4 REPRESENT drop 2drop pad 4 dump
    195FE0 | 31 30 30 30 |1000| ok

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Fri Oct 9 15:36:42 2026
    From Newsgroup: comp.lang.forth

    On 9/10/2026 2:29 pm, dxf wrote:
    On 8/10/2026 9:13 pm, peter wrote:
    ...
    The problem was 99.995e 2 f.n that became 100.0
    ...

    Every REPRESENT I know gives that:

    99.995e pad 4 REPRESENT drop 2drop pad 4 dump
    195FE0 | 31 30 30 30 |1000| ok

    Never mind. I didn't notice the lack of decimal places.


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Fri Oct 9 20:54:57 2026
    From Newsgroup: comp.lang.forth

    On 8/10/2026 9:13 pm, peter wrote:
    On Thu, 8 Oct 2026 13:34:33 +1100
    dxf <dxforth@gmail.com> wrote:

    On 8/10/2026 7:35 am, peter wrote:
    ...
    There were no real reason. The result at fpad is used only for
    INF and NAN. I also wanted a number larger then 17, 32 looked like
    a good round number. The importance of the first call to represent
    is to get a correct exp to use in the following calculations.
    The second time represent is called it will be with u=exp+n to get
    the correct rounding.

    Are you sure it's necessary? Your tests appear to work with it set at 5.


    You might be right!
    My first concern was for number like
    9.9999999995e that will round up all the way and get a exp+1
    But it looks like the code handles that also.
    ...

    I had a closer look using my own routines as a test bed. Using low values
    e.g. u=1 resulted in a few tests from your latest list failing to round.
    So anything less than u=17 (or whatever digits your REPRESENT can resolve) might well create rounding issues. It's similar to what I found when #EXP ('Getting the exponent of an x87 float') used an 80-bit FLOG with the last
    bits rounded off. Digits that otherwise displayed in the 18th position of
    an F. etc for certain numbers (e.g circa 1E-3) were lost!

    TL;DR AFAICS if one wants accurate rounding to 17 digits (or 700 digits)
    from F.N then that's the value of u that needs to be passed when asking
    for the exponent. It's hardly onerous since the buffer has be at least
    that. Whether asking REPRESENT for more digits than this gains one
    anything, I'd be less confident about. If the arithmetic inside REPRESENT
    was only good to 17 digits...
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Fri Oct 9 15:29:13 2026
    From Newsgroup: comp.lang.forth

    On 10/8/26 3:07 PM, peter wrote:
    On Thu, 8 Oct 2026 09:18:57 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    ...
    Would you please attach the complete code when you get a chance since
    several revisions have been made?

    Also, I found the following issue with n < 0. It's possible I introduced
    a bug in my revisions of your code, or that I missed some change.

    0.1e -1 (f.n) type 0.1 ok \ should be "0."
    0.01e -1 (f.n) type 0.01 ok \ should be "0."
    0.1e -2 (f.n) type 0.1 ok \ should be "0."

    and similar.

    ...
    No they were actually designed to behave like that! I made it so that
    when an impossible combination of exp and n were found n was set to a
    value that showed the number with one significant digit. That is exactly
    what happens in the above tests. But I agree with you when both exp and n
    are negative n will be set as 0 and the number rounded to 1. or 0.
    I have implemented that test now. I also restructured the code better
    and combined 2 cases into one case normal.

    Below follows code for both F.N and (F.N) tested on kForth64
    ...
    Thank you! I will integrate the changes into fdot.4th and fdot-test.4th
    in the kForth packages, and verify the results.

    REPRESENT in kForth now returns the three character 'inf' and 'nan'
    strings when appropriate. It can also return 'ERR' for an unspecified conversion error (when dtoa() returns 0 characters and exp is not equal
    to 9999). I don't actually know under what condition this might happen,
    but if it happens, there is a string to indicate it.

    I factored my implementation of FS. in kForth to use the string output
    word (FS.) which is a factor of "FS.". (FS.) is now intrinsic to all
    kForth variants and is part of the Forth wordlist. It enables me to
    simplify considerably one of my strings library words.

    My definition of (FS.) will only prepend a sign for the case of 'inf'.
    The possible outputs of (FS.) on conversion failure are '+inf' '-inf'
    'nan' and 'ERR'. I intend to follow this convention with (F.N) as well.

    Presently, I'm making other corrections and enhancements to my strings library, most of which came from discussion in this thread.

    --
    Krishna

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Fri Oct 9 16:54:11 2026
    From Newsgroup: comp.lang.forth

    On 10/9/26 4:54 AM, dxf wrote:
    ...
    TL;DR AFAICS if one wants accurate rounding to 17 digits (or 700 digits)
    from F.N then that's the value of u that needs to be passed when asking
    for the exponent.

    Because of the round trip requirement for IEEE binary64 you should not
    need to ask for more than 17 digits to the initial call to REPRESENT in
    order to get the exponent. In my F.N code from Peter, I have the value u
    set at 17. Of course when you actually get down to using REPRESENT to
    obtain the number of digits you want, u must be set accordingly.
    Consider the following example:

    pad 8 erase
    1 pad !
    pad df@ fs.
    4.94065645841247e-324 ok

    pad df@ 324 f.n
    0.000 ... 005 \ last digit is 324 digits to right of decimal point

    pad df@ 328 f.n
    0.000 ... 004
    940 7

    pad df@ 424 f.n
    0.000 ... 004
    940 656 458 412 465 441 765 687 928 682
    213 723 650 598 026 143 247 644 255 856
    825 006 755 072 702 087 518 652 998 363
    616 359 923 8 ok

    It is rounding correctly.

    For reference see the output below.

    Do you have an example which shows that u > 17 is needed for the initial
    call to REPRESENT?

    --
    Krishna


    800 set-precision
    ok
    pad f@ fs.

    Digits
    1 4.
    2--031 940 656 458 412 465 441 765 687 928 682
    32--061 213 723 650 598 026 143 247 644 255 856
    62--091 825 006 755 072 702 087 518 652 998 363
    92--121 616 359 923 797 965 646 954 457 177 309
    122--151 266 567 103 559 397 963 987 747 960 107
    152--181 818 781 263 007 131 903 114 045 278 458
    182--211 171 678 489 821 036 887 186 360 569 987
    212--241 307 230 500 063 874 091 535 649 843 873
    242--271 124 733 972 731 696 151 400 317 153 853
    272--301 980 741 262 385 655 911 710 266 585 566
    302--331 867 681 870 395 603 106 249 319 452 715
    332--361 914 924 553 293 054 565 444 011 274 801
    362--391 297 099 995 419 319 894 090 804 165 633
    392--421 245 247 571 478 690 147 267 801 593 552
    422--451 386 115 501 348 035 264 934 720 193 790
    452--481 268 107 107 491 703 332 226 844 753 335
    482--511 720 832 431 936 092 382 893 458 368 060
    512--541 106 011 506 169 809 753 078 342 277 318
    542--571 329 247 904 982 524 730 776 375 927 247
    572--601 874 656 084 778 203 734 469 699 533 647
    602--631 017 972 677 717 585 125 660 551 199 131
    632--661 504 891 101 451 037 862 738 167 250 955
    662--691 837 389 733 598 993 664 809 941 164 205
    692--721 702 637 090 279 242 767 544 565 229 087
    722--751 538 682 506 419 718 265 533 447 265 625
    752--781 000 000 000 000 000 000 000 000 000 000
    782--800 000 000 000 000 000 000 0
    e-324 ok




    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Sat Oct 10 10:54:18 2026
    From Newsgroup: comp.lang.forth

    On 10/10/2026 8:54 am, Krishna Myneni wrote:
    ...
    It is rounding correctly.

    For reference see the output below.

    Do you have an example which shows that u > 17 is needed for the initial call to REPRESENT?

    Using SwifthForth4 and an initial call of u=1, it took 119 tests to show
    a failure of 8. A call of u=4 resulted in a failure of 4 out 119. I've certainly no reason to trust the test of a single number as evidence.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Sat Oct 10 13:14:55 2026
    From Newsgroup: comp.lang.forth

    On 10/10/2026 8:54 am, Krishna Myneni wrote:
    On 10/9/26 4:54 AM, dxf wrote:
    ...
    TL;DR AFAICS if one wants accurate rounding to 17 digits (or 700 digits)
    from F.N then that's the value of u that needs to be passed when asking
    for the exponent.-a

    Because of the round trip requirement for IEEE binary64 you should not need to ask for more than 17 digits to the initial call to REPRESENT in order to get the exponent. In my F.N code from Peter, I have the value u set at 17. Of course when you actually get down to using REPRESENT to obtain the number of digits you want, u must be set accordingly.

    All I'm saying is the math, the numbers produced and subsequently displayed, have to correspond. A REPRESENT capable of resolving 700 digits is overkill for a system whose math is only good to 17 digits.


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Fri Oct 9 21:37:58 2026
    From Newsgroup: comp.lang.forth

    On 10/9/26 6:54 PM, dxf wrote:
    On 10/10/2026 8:54 am, Krishna Myneni wrote:
    ...
    It is rounding correctly.

    For reference see the output below.

    Do you have an example which shows that u > 17 is needed for the initial call to REPRESENT?

    Using SwifthForth4 and an initial call of u=1, it took 119 tests to show
    a failure of 8. A call of u=4 resulted in a failure of 4 out 119. I've certainly no reason to trust the test of a single number as evidence.


    You could simply say you don't have an example.

    --
    KM

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Fri Oct 16 23:31:07 2026
    From Newsgroup: comp.lang.forth

    On 10/8/26 3:07 PM, peter wrote:
    ...
    : f.n ( F:fp n -- )
    ...
    over 0< if
    dup 0 <= if nip 0 swap else \ negative e and n
    swap over 1- negate max swap \ limit negative n
    else swap over 1024 swap - min swap then then \ limit positive n
    ...

    Here is the code for (F.N)

    \ (F.N) print float with n decimals to string

    : (f.n) ( F:fp n -- )
    ...
    over 0< if
    dup 0 <= if nip 0 swap else \ negative e and n
    swap over 1- negate max swap \ limit negative n
    else swap over 1024 swap - min swap then then \ limit positive n
    ...
    The code snippets above use a control structure of the form

    IF ... IF ... ELSE ... ELSE ... THEN THEN

    Is this consistent with the standard?

    --
    Krishna



    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Sat Oct 17 05:27:57 2026
    From Newsgroup: comp.lang.forth

    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    IF ... IF ... ELSE ... ELSE ... THEN THEN

    Is this consistent with the standard?

    Yes, but

    if A if B else C else D THEN THEN

    is equivalent to

    if A if B D else C then then

    and in particular

    if A if B swap else C else swap D then then

    is also equivalent to

    if A if B D else C then then

    So one normally would not write code like this. It may be that this
    is not the intended code.

    OTOH, I have seen code like

    swap +

    or

    does> ;

    in production code, so sometimes programmers miss obvious
    simplifications; the formatting of the original code may have
    contributed to that.

    For the code you posted, the simplification would be

    over 0< if
    dup 0 <= if
    nip 0 over 1024 swap - min swap
    else \ negative e and n
    swap over 1- negate max swap \ limit negative n
    then
    then \ limit positive n

    which can be further simplified (first branch) and unified (second
    branch):

    over 0< if
    dup 0 <= if ( a b
    nip 1024 over - 0 min
    else \ negative e and n
    swap 1 over - max \ limit negative n
    then
    swap
    then \ limit positive n

    The similarities between the branches make it plausible that this code
    does what is intended.

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Sat Oct 17 11:52:21 2026
    From Newsgroup: comp.lang.forth

    On Fri, 16 Oct 2026 23:31:07 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    On 10/8/26 3:07 PM, peter wrote:
    ...
    : f.n ( F:fp n -- )
    ...
    over 0< if
    dup 0 <= if nip 0 swap else \ negative e and n
    swap over 1- negate max swap \ limit negative n
    else swap over 1024 swap - min swap then then \ limit positive n
    ...

    Here is the code for (F.N)

    \ (F.N) print float with n decimals to string

    : (f.n) ( F:fp n -- )
    ...
    over 0< if
    dup 0 <= if nip 0 swap else \ negative e and n
    swap over 1- negate max swap \ limit negative n
    else swap over 1024 swap - min swap then then \ limit positive n
    ...
    The code snippets above use a control structure of the form

    IF ... IF ... ELSE ... ELSE ... THEN THEN

    Is this consistent with the standard?

    --
    Krishna

    Thanks for noticing this! It might be standard but it does not do
    what it should! The limit positive n does not execute when it should.

    Here is a version that corrects this.

    over 0 >= if
    swap over 1024 swap - min swap else \ limit positive n
    dup 0<= if nip 0 swap else \ limit negative n when e negative
    1 over - rot max swap then then \ limit negative n

    It worked correctly until I added the test for negative n and e!

    BR
    Peter

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Sat Oct 17 10:06:20 2026
    From Newsgroup: comp.lang.forth

    peter <peter.noreply@tin.it> writes:
    Here is a version that corrects this.

    over 0 >= if
    swap over 1024 swap - min swap else \ limit positive n
    dup 0<= if nip 0 swap else \ limit negative n when e negative
    1 over - rot max swap then then \ limit negative n


    Can this be simplified? Here's what I came up with:

    over 0 >= if
    1024 2 pick - rot min
    else
    dup 0<= if
    nip 0
    else
    1 over - rot max
    then
    then
    swap

    Or, using CASE with ?OF:

    case
    dup 0 >= ?of 1024 2 pick - rot min endof
    dup 0<= ?of nip 0 endof
    1 over - rot max
    0 endcase
    swap

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Sat Oct 17 15:41:00 2026
    From Newsgroup: comp.lang.forth

    On Sat, 17 Oct 2026 10:06:20 GMT
    anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:

    peter <peter.noreply@tin.it> writes:
    Here is a version that corrects this.

    over 0 >= if
    swap over 1024 swap - min swap else \ limit positive n
    dup 0<= if nip 0 swap else \ limit negative n when e negative
    1 over - rot max swap then then \ limit negative n


    Can this be simplified? Here's what I came up with:

    over 0 >= if
    1024 2 pick - rot min
    else
    dup 0<= if
    nip 0
    else
    1 over - rot max
    then
    then
    swap

    So you are basically taken out the swap and putting it last.
    The 2 pick needs to be over to work properly.
    we have n, exp on the stack. The 3 cases we have can be summarized as

    sign of
    n exp limit of n
    + +- n=min(n, 1024-exp)
    - - n=0
    - + n=max(n, 1-e)

    Lets now compile our different implementations

    : A1
    over 0 >= if
    1024 over - rot min
    else
    dup 0<= if
    nip 0
    else
    1 over - rot max
    then
    then
    swap ;

    : P1
    over 0 >= if
    swap over 1024 swap - min swap else \ limit positive n
    dup 0<= if nip 0 swap else \ limit n when e negative
    1 over - rot max swap then then ; \ limit negative n

    seea A1
    0x4284E0 48837D0000 cmp qword ptr [rbp], 0x0
    0x4284E5 7C1E jl 0x428505
    0x4284E7 48C7C000040000 mov rax, 0x400
    0x4284EE 4829D8 sub rax, rbx
    0x4284F1 488B4D00 mov rcx, qword ptr [rbp]
    0x4284F5 4839C8 cmp rax, rcx
    0x4284F8 7D02 jge 0x4284FC
    0x4284FA 4891 xchg rcx, rax
    0x4284FC 48895D00 mov qword ptr [rbp], rbx
    0x428500 4889CB mov rbx, rcx
    0x428503 EB2F jmp 0x428534
    0x428505 4883FB00 cmp rbx, 0x0
    0x428509 7F0D jg 0x428518
    0x42850B 48895D00 mov qword ptr [rbp], rbx
    0x42850F 48C7C300000000 mov rbx, 0x0
    0x428516 EB1C jmp 0x428534
    0x428518 48C7C001000000 mov rax, 0x1
    0x42851F 4829D8 sub rax, rbx
    0x428522 488B4D00 mov rcx, qword ptr [rbp]
    0x428526 4839C8 cmp rax, rcx
    0x428529 7D02 jge 0x42852D
    0x42852B 4891 xchg rcx, rax
    0x42852D 48895D00 mov qword ptr [rbp], rbx
    0x428531 4889C3 mov rbx, rax
    0x428534 488B4500 mov rax, qword ptr [rbp]
    0x428538 48895D00 mov qword ptr [rbp], rbx
    0x42853C 4889C3 mov rbx, rax
    0x42853F C3 ret
    96 bytes, 28 instructions

    seea p1
    0x428440 48837D0000 cmp qword ptr [rbp], 0x0
    0x428445 7C1B jl 0x428462
    0x428447 48C7C000040000 mov rax, 0x400
    0x42844E 4829D8 sub rax, rbx
    0x428451 488B4D00 mov rcx, qword ptr [rbp]
    0x428455 4839C1 cmp rcx, rax
    0x428458 7D02 jge 0x42845C
    0x42845A 4891 xchg rcx, rax
    0x42845C 48894500 mov qword ptr [rbp], rax
    0x428460 EB29 jmp 0x42848B
    0x428462 4883FB00 cmp rbx, 0x0
    0x428466 7F0A jg 0x428472
    0x428468 48C7450000000000 mov qword ptr [rbp], 0x0
    0x428470 EB19 jmp 0x42848B
    0x428472 48C7C001000000 mov rax, 0x1
    0x428479 4829D8 sub rax, rbx
    0x42847C 488B4D00 mov rcx, qword ptr [rbp]
    0x428480 4839C8 cmp rax, rcx
    0x428483 7D02 jge 0x428487
    0x428485 4891 xchg rcx, rax
    0x428487 48894500 mov qword ptr [rbp], rax
    0x42848B C3 ret
    76 bytes, 22 instructions

    by moving out the swap and reducing from 3 to 1 occurrences we get
    20 bytes more code! Now this example when we look at the function
    standalone instead of inlined we are penalized by moving out the swap
    as it need to generate code, it gets a block by itself between
    then and ; In P1 we have the exp always as top of stack at all block boundaries, it is unmodified and resides always in rbx.
    In A1 the exp is second on stack and needs to be moved from rbx to memory
    after each block of the code.
    Note also that max and min are implemented to not create a block
    boundary. Generally stack movements only create code at block boundaries

    BR
    Peter

    Or, using CASE with ?OF:

    case
    dup 0 >= ?of 1024 2 pick - rot min endof
    dup 0<= ?of nip 0 endof
    1 over - rot max
    0 endcase
    swap

    - anton


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Sun Oct 18 00:57:50 2026
    From Newsgroup: comp.lang.forth

    While I never considered or designed for 'negative decimal places' it appears my version of F.N does do them - albeit with results different from tests I've seen posted here.

    Wondering if there was any convention for them, google turned up the ROUND() function in Oracle and SQL. Online examples didn't show what happens at the extremes (what I was interested in) but I did find an online SQL server where
    I could test that. For SQL at least, the results were as follows.

    SQL:

    ROUND(876.543, 0) 877.000
    ROUND(876.543,-1) 880.000
    ROUND(876.543,-2) 900.000
    ROUND(876.543,-3) <overflow error>

    ROUND(456.789, 0) 457.000
    ROUND(456.789,-1) 460.000
    ROUND(456.789,-2) 500.000
    ROUND(456.789,-3) .000

    F.N (dxf):

    876.543e 0 f.n 877.
    876.543e -1 f.n 880.
    876.543e -2 f.n 900.
    876.543e -3 f.n 1000.

    456.789e 0 f.n 457.
    456.789e -1 f.n 460.
    456.789e -2 f.n 500.
    456.789e -3 f.n 0.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Sat Oct 17 09:31:19 2026
    From Newsgroup: comp.lang.forth

    On 10/17/26 12:27 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    IF ... IF ... ELSE ... ELSE ... THEN THEN

    Is this consistent with the standard?

    Yes, but

    if A if B else C else D THEN THEN

    is equivalent to

    if A if B D else C then then
    ...
    This does not seem to be what it does in either Gforth or kForth with
    the following example, considering all possible boolean inputs.

    : test ( n1 n2 -- )
    IF
    ." n2 is true" cr
    IF
    ." n1 is true" cr
    ELSE
    ." n1 is false" cr
    ELSE
    ." ??" cr
    THEN
    THEN
    ;


    === Gforth output ===
    \ 1 false false ok
    false false test ok 1
    .s <1> 0 ok 1
    drop

    \ 2 false true ok

    \ 3 true false ok

    \ 4 true true ok
    .s <0> ok
    === end output ===

    With Gforth, nothing is ever printed.

    === kForth output ===
    \ 1 false false
    ok
    false false test .s

    0
    ok
    drop
    ok

    \ 2 false true
    ok
    false true test .s
    n2 is true
    n1 is false
    <empty>
    ok

    \ 3 true false
    ok
    true false test .s

    -1
    ok
    drop
    ok

    \ 4 true true
    ok
    true true test .s
    n2 is true
    n1 is true
    ??
    <empty>
    ok
    === end output ===

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Sat Oct 17 13:59:02 2026
    From Newsgroup: comp.lang.forth

    peter <peter.noreply@tin.it> writes:
    On Sat, 17 Oct 2026 10:06:20 GMT
    anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:

    peter <peter.noreply@tin.it> writes:
    Here is a version that corrects this.

    over 0 >= if
    swap over 1024 swap - min swap else \ limit positive n
    dup 0<= if nip 0 swap else \ limit negative n when e negative >> > 1 over - rot max swap then then \ limit negative n


    Can this be simplified? Here's what I came up with:

    over 0 >= if
    1024 2 pick - rot min
    else
    dup 0<= if
    nip 0
    else
    1 over - rot max
    then
    then
    swap

    So you are basically taken out the swap and putting it last.

    Yes, and the change to the stuff after the first IF that I got wrong.

    The 2 pick needs to be over to work properly.

    Even nicer.

    Lets now compile our different implementations
    by moving out the swap and reducing from 3 to 1 occurrences we get
    20 bytes more code!

    Yes, with your code generator that usually produces a perfect register allocation for basic blocks, the change to the code after the first if
    provides no benefit to the generated code.

    As for the SWAP, your code generator produces the canonical stack representation at every basic block end, so putting the SWAP in a
    separate basic block costs extra code in that block, and the other blocks don't necessarily get smaller, sometimes even larger. E.g.

    nip 0 nip 0 swap
    mov qword ptr [rbp], rbx mov qword ptr [rbp], 0x0
    mov rbx, 0x0

    Now this example when we look at the function
    standalone instead of inlined we are penalized by moving out the swap
    as it need to generate code, it gets a block by itself between
    then and ; In P1 we have the exp always as top of stack at all block >boundaries, it is unmodified and resides always in rbx.

    Given that you don't change exp, another alternative is to keep it on
    the return stack:

    : A2
    >r
    dup 0 >= if
    1024 r@ - min
    else
    r@ 0<= if
    drop 0
    else
    1 r@ - max
    then
    then
    r> ;

    I leave it to you to determine if any of those results in shorter code
    (my copy of lxf64 does not generate native code yet). And who knows
    if I got that right.

    Apart from inlining, there are two other ways in which the code
    generation can be improved:

    1) Extend the basic blocks by duplicating the code after control-flow
    joins (in particular for THEN) until some other limit is reached
    (e.g., the end of the definition); this would undo the move of the
    SWAP to the end, but also duplicate the EXIT, and make the ELSE
    jumps dead code, resulting in code as if the source looked like
    (for A1):

    : A1B
    over 0 >= if
    1024 over - rot min swap exit then
    dup 0<= if
    nip 0 swap exit then
    1 over - rot max swap ;

    That's closer to P1 than A1:-).

    2) Register allocation that works across basic block boundaries and
    does not need to materialize a canonical state there.

    If the code generator is good enough that it does not make a
    significant difference in the generated code which of the variants we
    have written, we can ask ourselves which version is best for
    understanding by a reader. Looking at the variants again, the
    return-stack variant looks best to me, but again, who knows if I got
    it right.

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Sat Oct 17 15:27:46 2026
    From Newsgroup: comp.lang.forth

    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    On 10/17/26 12:27 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    IF ... IF ... ELSE ... ELSE ... THEN THEN

    Is this consistent with the standard?

    Yes, but

    if A if B else C else D THEN THEN

    is equivalent to

    if A if B D else C then then
    ...
    This does not seem to be what it does in either Gforth or kForth with
    the following example, considering all possible boolean inputs.

    : test ( n1 n2 -- )
    IF
    ." n2 is true" cr
    IF
    ." n1 is true" cr
    ELSE
    ." n1 is false" cr
    ELSE
    ." ??" cr
    THEN
    THEN
    ;


    === Gforth output ===
    \ 1 false false ok
    false false test ok 1
    .s <1> 0 ok 1
    drop

    \ 2 false true ok

    \ 3 true false ok

    \ 4 true true ok
    .s <0> ok
    === end output ===

    With Gforth, nothing is ever printed.

    If n2 is false nothing should be printed. And that's the only test
    you did. The outer IF...THEN is just a distraction and is not
    involved in the IF ... ELSE ... ELSE ... THEN. Here are more
    interesting cases:

    input:
    cr true true test
    output:
    n2 is true
    n1 is true
    ??

    input:
    cr false true test
    output:
    n2 is true
    n1 is false

    That's exactly what the standard specifies: ELSE ( orig1 -- orig2 )
    continues the current execution at the place where orig2 is resolved,
    and then resolves orig1, continuing the execution from there. In a
    way it swaps between the current execution and the one in the orig.

    === kForth output ===
    \ 1 false false
    ok
    false false test .s

    0
    ok
    drop
    ok

    \ 2 false true
    ok
    false true test .s
    n2 is true
    n1 is false
    <empty>
    ok

    \ 3 true false
    ok
    true false test .s

    -1
    ok
    drop
    ok

    \ 4 true true
    ok
    true true test .s
    n2 is true
    n1 is true
    ??
    <empty>
    ok
    === end output ===

    Judging by these tests, kforth also implements ELSE correctly.

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Sat Oct 17 10:55:21 2026
    From Newsgroup: comp.lang.forth

    On 10/17/26 10:27 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    On 10/17/26 12:27 AM, Anton Ertl wrote:
    Krishna Myneni <krishna.myneni@ccreweb.org> writes:
    IF ... IF ... ELSE ... ELSE ... THEN THEN

    Is this consistent with the standard?

    Yes, but

    if A if B else C else D THEN THEN

    is equivalent to

    if A if B D else C then then
    ...
    This does not seem to be what it does in either Gforth or kForth with
    the following example, considering all possible boolean inputs.

    : test ( n1 n2 -- )
    IF
    ." n2 is true" cr
    IF
    ." n1 is true" cr
    ELSE
    ." n1 is false" cr
    ELSE
    ." ??" cr
    THEN
    THEN
    ;


    === Gforth output ===
    \ 1 false false ok
    false false test ok 1
    .s <1> 0 ok 1
    drop

    \ 2 false true ok

    \ 3 true false ok

    \ 4 true true ok
    .s <0> ok
    === end output ===

    With Gforth, nothing is ever printed.

    If n2 is false nothing should be printed. And that's the only test
    you did. The outer IF...THEN is just a distraction and is not
    involved in the IF ... ELSE ... ELSE ... THEN. Here are more
    interesting cases:


    I only had the comments, and looking back I didn't actually do the other
    tests with Gforth. Good to know there is consistency here.

    --
    KM

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Sat Oct 17 18:20:05 2026
    From Newsgroup: comp.lang.forth

    On Sat, 17 Oct 2026 13:59:02 GMT
    anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:

    peter <peter.noreply@tin.it> writes:
    On Sat, 17 Oct 2026 10:06:20 GMT
    anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:

    peter <peter.noreply@tin.it> writes:
    Here is a version that corrects this.

    over 0 >= if
    swap over 1024 swap - min swap else \ limit positive n
    dup 0<= if nip 0 swap else \ limit negative n when e negative
    1 over - rot max swap then then \ limit negative n


    Can this be simplified? Here's what I came up with:

    over 0 >= if
    1024 2 pick - rot min
    else
    dup 0<= if
    nip 0
    else
    1 over - rot max
    then
    then
    swap

    So you are basically taken out the swap and putting it last.

    Yes, and the change to the stuff after the first IF that I got wrong.

    The 2 pick needs to be over to work properly.

    Even nicer.

    Lets now compile our different implementations
    by moving out the swap and reducing from 3 to 1 occurrences we get
    20 bytes more code!

    Yes, with your code generator that usually produces a perfect register allocation for basic blocks, the change to the code after the first if provides no benefit to the generated code.

    As for the SWAP, your code generator produces the canonical stack representation at every basic block end, so putting the SWAP in a
    separate basic block costs extra code in that block, and the other blocks don't necessarily get smaller, sometimes even larger. E.g.

    nip 0 nip 0 swap
    mov qword ptr [rbp], rbx mov qword ptr [rbp], 0x0
    mov rbx, 0x0

    Now this example when we look at the function
    standalone instead of inlined we are penalized by moving out the swap
    as it need to generate code, it gets a block by itself between
    then and ; In P1 we have the exp always as top of stack at all block >boundaries, it is unmodified and resides always in rbx.

    Given that you don't change exp, another alternative is to keep it on
    the return stack:

    : A2
    >r
    dup 0 >= if
    1024 r@ - min
    else
    r@ 0<= if
    drop 0
    else
    1 r@ - max
    then
    then
    r> ;

    This is nice and easy to read.

    seea a2
    0x4285A0 48837D0000 cmp qword ptr [rbp], 0x0
    0x4285A5 48895C24F8 mov qword ptr [rsp-0x8], rbx
    0x4285AA 488B5D00 mov rbx, qword ptr [rbp]
    0x4285AE 488D6D08 lea rbp, [rbp+0x8]
    0x4285B2 488D6424F8 lea rsp, [rsp-0x8]
    0x4285B7 7C17 jl 0x4285D0
    0x4285B9 48C7C000040000 mov rax, 0x400
    0x4285C0 482B0424 sub rax, qword ptr [rsp]
    0x4285C4 4839C3 cmp rbx, rax
    0x4285C7 7D02 jge 0x4285CB
    0x4285C9 4893 xchg rbx, rax
    0x4285CB 4889C3 mov rbx, rax
    0x4285CE EB22 jmp 0x4285F2
    0x4285D0 48833C2400 cmp qword ptr [rsp], 0x0
    0x4285D5 7F09 jg 0x4285E0
    0x4285D7 48C7C300000000 mov rbx, 0x0
    0x4285DE EB12 jmp 0x4285F2
    0x4285E0 48C7C001000000 mov rax, 0x1
    0x4285E7 482B0424 sub rax, qword ptr [rsp]
    0x4285EB 4839C3 cmp rbx, rax
    0x4285EE 7D02 jge 0x4285F2
    0x4285F0 4893 xchg rbx, rax
    0x4285F2 48895DF8 mov qword ptr [rbp-0x8], rbx
    0x4285F6 488B1C24 mov rbx, qword ptr [rsp]
    0x4285FA 488D6DF8 lea rbp, [rbp-0x8]
    0x4285FE 488D642408 lea rsp, [rsp+0x8]
    0x428603 C3 ret
    100 bytes, 27 instructions

    I leave it to you to determine if any of those results in shorter code
    (my copy of lxf64 does not generate native code yet). And who knows
    if I got that right.

    Apart from inlining, there are two other ways in which the code
    generation can be improved:

    1) Extend the basic blocks by duplicating the code after control-flow
    joins (in particular for THEN) until some other limit is reached
    (e.g., the end of the definition); this would undo the move of the
    SWAP to the end, but also duplicate the EXIT, and make the ELSE
    jumps dead code, resulting in code as if the source looked like
    (for A1):

    : A1B
    over 0 >= if
    1024 over - rot min swap exit then
    dup 0<= if
    nip 0 swap exit then
    1 over - rot max swap ;

    This is how I would have written it if it was a standalone word

    seea a1b
    0x428550 48837D0000 cmp qword ptr [rbp], 0x0
    0x428555 7C1A jl 0x428571
    0x428557 48C7C000040000 mov rax, 0x400
    0x42855E 4829D8 sub rax, rbx
    0x428561 488B4D00 mov rcx, qword ptr [rbp]
    0x428565 4839C8 cmp rax, rcx
    0x428568 7D02 jge 0x42856C
    0x42856A 4891 xchg rcx, rax
    0x42856C 48894D00 mov qword ptr [rbp], rcx
    0x428570 C3 ret
    0x428571 4883FB00 cmp rbx, 0x0
    0x428575 7F09 jg 0x428580
    0x428577 48C7450000000000 mov qword ptr [rbp], 0x0
    0x42857F C3 ret
    0x428580 48C7C001000000 mov rax, 0x1
    0x428587 4829D8 sub rax, rbx
    0x42858A 488B4D00 mov rcx, qword ptr [rbp]
    0x42858E 4839C8 cmp rax, rcx
    0x428591 7D02 jge 0x428595
    0x428593 4891 xchg rcx, rax
    0x428595 48894500 mov qword ptr [rbp], rax
    0x428599 C3 ret
    74 bytes, 22 instructions


    That's closer to P1 than A1:-).

    2) Register allocation that works across basic block boundaries and
    does not need to materialize a canonical state there.

    If the code generator is good enough that it does not make a
    significant difference in the generated code which of the variants we
    have written, we can ask ourselves which version is best for
    understanding by a reader. Looking at the variants again, the
    return-stack variant looks best to me, but again, who knows if I got
    it right.
    It tests out right!
    I agree that this is the easiest to understand.

    When I started the code-generator for lxf, many years ago my first approach
    was to push the state to a state stack at a block entry and to pop it of
    at the end and there do a fixup to get both branches of an IF to the same state . It tuned out difficult to implement so I started with the easy
    way of returning to a known state at every block. This was good also
    for another reason. The longer blocks you have the more registers can be
    tied up. In lxf I have 5 registers available to the code generator. It is
    very seldom that they get over used and need to spill to memory. In lxf64
    I have 9 registers and have not yet written a spill routine. The few times
    it has been signaled it has been due to another error, like not releasing
    a register. On ARM64 there will be even more registers to play with.

    I need to think if I can use them better

    BR
    Peter

    - anton


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Sat Oct 17 18:23:26 2026
    From Newsgroup: comp.lang.forth

    On Sun, 18 Oct 2026 00:57:50 +1100
    dxf <dxforth@gmail.com> wrote:

    While I never considered or designed for 'negative decimal places' it appears my version of F.N does do them - albeit with results different from tests I've
    seen posted here.

    Wondering if there was any convention for them, google turned up the ROUND() function in Oracle and SQL. Online examples didn't show what happens at the extremes (what I was interested in) but I did find an online SQL server where I could test that. For SQL at least, the results were as follows.

    SQL:

    ROUND(876.543, 0) 877.000
    ROUND(876.543,-1) 880.000
    ROUND(876.543,-2) 900.000
    ROUND(876.543,-3) <overflow error>

    ROUND(456.789, 0) 457.000
    ROUND(456.789,-1) 460.000
    ROUND(456.789,-2) 500.000
    ROUND(456.789,-3) .000

    F.N (dxf):

    876.543e 0 f.n 877.
    876.543e -1 f.n 880.
    876.543e -2 f.n 900.
    876.543e -3 f.n 1000.

    456.789e 0 f.n 457.
    456.789e -1 f.n 460.
    456.789e -2 f.n 500.
    456.789e -3 f.n 0.


    F.N (pf)

    876.543e 0 f.n 877. ok
    876.543e -1 f.n 880 ok
    876.543e -2 f.n 900 ok
    876.543e -3 f.n 900 ok

    456.789e 0 f.n 457. ok
    456.789e -1 f.n 460 ok
    456.789e -2 f.n 500 ok
    456.789e -3 f.n 500 ok


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Sun Oct 18 17:10:27 2026
    From Newsgroup: comp.lang.forth

    On 10/8/26 3:07 PM, peter wrote:
    On Thu, 8 Oct 2026 09:18:57 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:
    ...
    Thanks to dxf's question I continued testing and found an error.

    0.999955555e 2 f.n 0.0100

    What happened was that in this case exp from the first represent is 0
    in the test to choose action f.n-case-e<=0 get chosen. In this part
    exp is recalculated and became 1!
    The correction is to move the second represent earlier before choosing.



    Would you please attach the complete code when you get a chance since
    several revisions have been made?

    Also, I found the following issue with n < 0. It's possible I introduced
    a bug in my revisions of your code, or that I missed some change.

    0.1e -1 (f.n) type 0.1 ok \ should be "0."
    0.01e -1 (f.n) type 0.01 ok \ should be "0."
    0.1e -2 (f.n) type 0.1 ok \ should be "0."

    and similar.

    ...
    No they were actually designed to behave like that! I made it so that
    when an impossible combination of exp and n were found n was set to a
    value that showed the number with one significant digit. That is exactly
    what happens in the above tests. But I agree with you when both exp and n
    are negative n will be set as 0 and the number rounded to 1. or 0.
    I have implemented that test now. I also restructured the code better
    and combined 2 cases into one case normal.

    Below follows code for both F.N and (F.N) tested on kForth64

    ...

    \ 0 [IF]
    \ Test cases
    : testing cr begin refill while source 2dup type space evaluate cr repeat ; testing
    0.9e 0 f.n
    0.3e 0 f.n
    -0.9e 0 f.n
    -0.3e 0 f.n
    ...

    I have patched the code with all recent fixes for the logic of (F.N) and revised it to work on both separate stack and unified data/fp stack in fdotn.4th. I have also revised the automated tests in fdotn-test.4th to include your tests. The two files,

    fdotn.4th
    fdotn-test.4th

    may be found in the lastest commits for the git repos for
    kForth-64/32/Win32 on github or in the repos on ccreweb.org.

    Direct links to the revised files:

    https://github.com/mynenik/kForth-64/blob/master/forth-src/fdotn.4th https://github.com/mynenik/kForth-64/blob/master/forth-src/fdotn-test.4th

    An additional change to the definition of (F.N) prevents the sign on conversion failure from being output except for "inf". The last two
    tests in fdotn-test.4th have been revised accordingly.

    --
    KM


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Mon Oct 19 15:41:05 2026
    From Newsgroup: comp.lang.forth

    On Sun, 18 Oct 2026 17:10:27 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    On 10/8/26 3:07 PM, peter wrote:
    On Thu, 8 Oct 2026 09:18:57 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:
    ...
    Thanks to dxf's question I continued testing and found an error.

    0.999955555e 2 f.n 0.0100

    What happened was that in this case exp from the first represent is 0
    in the test to choose action f.n-case-e<=0 get chosen. In this part
    exp is recalculated and became 1!
    The correction is to move the second represent earlier before choosing. >>>


    Would you please attach the complete code when you get a chance since
    several revisions have been made?

    Also, I found the following issue with n < 0. It's possible I introduced >> a bug in my revisions of your code, or that I missed some change.

    0.1e -1 (f.n) type 0.1 ok \ should be "0."
    0.01e -1 (f.n) type 0.01 ok \ should be "0."
    0.1e -2 (f.n) type 0.1 ok \ should be "0."

    and similar.

    ...
    No they were actually designed to behave like that! I made it so that
    when an impossible combination of exp and n were found n was set to a
    value that showed the number with one significant digit. That is exactly what happens in the above tests. But I agree with you when both exp and n are negative n will be set as 0 and the number rounded to 1. or 0.
    I have implemented that test now. I also restructured the code better
    and combined 2 cases into one case normal.

    Below follows code for both F.N and (F.N) tested on kForth64

    ...

    \ 0 [IF]
    \ Test cases
    : testing cr begin refill while source 2dup type space evaluate cr repeat ; testing
    0.9e 0 f.n
    0.3e 0 f.n
    -0.9e 0 f.n
    -0.3e 0 f.n
    ...

    I have patched the code with all recent fixes for the logic of (F.N) and revised it to work on both separate stack and unified data/fp stack in fdotn.4th. I have also revised the automated tests in fdotn-test.4th to include your tests. The two files,

    fdotn.4th
    fdotn-test.4th

    may be found in the lastest commits for the git repos for
    kForth-64/32/Win32 on github or in the repos on ccreweb.org.

    Direct links to the revised files:

    https://github.com/mynenik/kForth-64/blob/master/forth-src/fdotn.4th https://github.com/mynenik/kForth-64/blob/master/forth-src/fdotn-test.4th

    An additional change to the definition of (F.N) prevents the sign on conversion failure from being output except for "inf". The last two
    tests in fdotn-test.4th have been revised accordingly.

    --
    KM

    Nice to see that you could integrate it in kForth!

    I have also introduced it in ntf64/lxf64.
    I liked the possibility to directly specify how many digits to print
    instead of setting precision (that I half of the time misspell!)

    I might do a FS.N where n would be significant digits

    BR
    Peter

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Mon Oct 19 09:44:43 2026
    From Newsgroup: comp.lang.forth

    On 10/19/26 8:41 AM, peter wrote:
    On Sun, 18 Oct 2026 17:10:27 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    On 10/8/26 3:07 PM, peter wrote:
    On Thu, 8 Oct 2026 09:18:57 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:
    ...
    Thanks to dxf's question I continued testing and found an error.

    0.999955555e 2 f.n 0.0100

    What happened was that in this case exp from the first represent is 0 >>>>> in the test to choose action f.n-case-e<=0 get chosen. In this part
    exp is recalculated and became 1!
    The correction is to move the second represent earlier before choosing. >>>>>


    Would you please attach the complete code when you get a chance since
    several revisions have been made?

    Also, I found the following issue with n < 0. It's possible I introduced >>>> a bug in my revisions of your code, or that I missed some change.

    0.1e -1 (f.n) type 0.1 ok \ should be "0."
    0.01e -1 (f.n) type 0.01 ok \ should be "0."
    0.1e -2 (f.n) type 0.1 ok \ should be "0."

    and similar.

    ...
    No they were actually designed to behave like that! I made it so that
    when an impossible combination of exp and n were found n was set to a
    value that showed the number with one significant digit. That is exactly >>> what happens in the above tests. But I agree with you when both exp and n >>> are negative n will be set as 0 and the number rounded to 1. or 0.
    I have implemented that test now. I also restructured the code better
    and combined 2 cases into one case normal.

    Below follows code for both F.N and (F.N) tested on kForth64

    ...

    \ 0 [IF]
    \ Test cases
    : testing cr begin refill while source 2dup type space evaluate cr repeat ; >>> testing
    0.9e 0 f.n
    0.3e 0 f.n
    -0.9e 0 f.n
    -0.3e 0 f.n
    ...

    I have patched the code with all recent fixes for the logic of (F.N) and
    revised it to work on both separate stack and unified data/fp stack in
    fdotn.4th. I have also revised the automated tests in fdotn-test.4th to
    include your tests. The two files,

    fdotn.4th
    fdotn-test.4th

    may be found in the lastest commits for the git repos for
    kForth-64/32/Win32 on github or in the repos on ccreweb.org.

    Direct links to the revised files:

    https://github.com/mynenik/kForth-64/blob/master/forth-src/fdotn.4th
    https://github.com/mynenik/kForth-64/blob/master/forth-src/fdotn-test.4th

    An additional change to the definition of (F.N) prevents the sign on
    conversion failure from being output except for "inf". The last two
    tests in fdotn-test.4th have been revised accordingly.

    --
    KM

    Nice to see that you could integrate it in kForth!

    I have also introduced it in ntf64/lxf64.
    I liked the possibility to directly specify how many digits to print
    instead of setting precision (that I half of the time misspell!)

    I might do a FS.N where n would be significant digits


    Do you mean decimal places? The latest strings library in kForth-x has
    (FS.N) where n is decimal places. I think this corresponds to Fortran
    90's ES<w>.<n> format, but haven't verified it yet.

    Normal FS. and (FS.) converts to output in significant digits specified
    via PRECISION.

    --
    KM

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Mon Oct 19 09:51:12 2026
    From Newsgroup: comp.lang.forth

    On 10/19/26 9:44 AM, Krishna Myneni wrote:
    On 10/19/26 8:41 AM, peter wrote:
    ...
    Nice to see that you could integrate it in kForth!

    I have also introduced it in ntf64/lxf64.
    I liked the possibility to directly specify how many digits to print
    instead of setting precision (that I half of the time misspell!)

    I might do a FS.N where n would be significant digits


    Do you mean decimal places? The latest strings library in kForth-x has (FS.N) where n is decimal places. I think this corresponds to Fortran
    90's ES<w>.<n> format, but haven't verified it yet.

    Normal FS. and (FS.) converts to output in significant digits specified
    via PRECISION.

    ...

    From strings.4th:

    \ Convert r to a scientific notation string, caddr u pair,
    \ with n decimal places
    : (fs.n) ( n -- a u ) ( F: r -- ) \ ( r n -- a u )
    precision >r 1+ set-precision (fs.) strbufmove
    r> set-precision ;

    (FS.) is an intrinsic word in kForth, but it is easy to write using
    REPRESENT. I think I posted it in a previous thread.

    FS.N where n is decimal places is often what users want.

    --
    KM




    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From peter@peter.noreply@tin.it to comp.lang.forth on Mon Oct 19 18:03:23 2026
    From Newsgroup: comp.lang.forth

    On Mon, 19 Oct 2026 09:51:12 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    On 10/19/26 9:44 AM, Krishna Myneni wrote:
    On 10/19/26 8:41 AM, peter wrote:
    ...
    Nice to see that you could integrate it in kForth!

    I have also introduced it in ntf64/lxf64.
    I liked the possibility to directly specify how many digits to print
    instead of setting precision (that I half of the time misspell!)

    I might do a FS.N where n would be significant digits


    Do you mean decimal places? The latest strings library in kForth-x has (FS.N) where n is decimal places. I think this corresponds to Fortran
    90's ES<w>.<n> format, but haven't verified it yet.

    Normal FS. and (FS.) converts to output in significant digits specified via PRECISION.

    ...

    From strings.4th:

    \ Convert r to a scientific notation string, caddr u pair,
    \ with n decimal places
    : (fs.n) ( n -- a u ) ( F: r -- ) \ ( r n -- a u )
    precision >r 1+ set-precision (fs.) strbufmove
    r> set-precision ;

    (FS.) is an intrinsic word in kForth, but it is easy to write using REPRESENT. I think I posted it in a previous thread.

    FS.N where n is decimal places is often what users want.

    --
    KM
    I did it even simpler as I already had a factor for fs. and fe.

    : (FS.) fpad precision 2dup represent 1 (fx.) ;
    : (FS.N) fpad swap 1+ 1 max 2dup represent 1 (fx.) ;
    : (FE.) fpad precision 3 max 2dup represent 3 (fx.) ;

    no negative n allowed here!

    Peter

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Mon Oct 19 11:41:41 2026
    From Newsgroup: comp.lang.forth

    On 10/19/26 11:03 AM, peter wrote:
    On Mon, 19 Oct 2026 09:51:12 -0500
    Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

    ...
    \ Convert r to a scientific notation string, caddr u pair,
    \ with n decimal places
    : (fs.n) ( n -- a u ) ( F: r -- ) \ ( r n -- a u )
    precision >r 1+ set-precision (fs.) strbufmove
    r> set-precision ;

    ...
    FS.N where n is decimal places is often what users want.

    ...
    I did it even simpler as I already had a factor for fs. and fe.

    : (FS.) fpad precision 2dup represent 1 (fx.) ;
    : (FS.N) fpad swap 1+ 1 max 2dup represent 1 (fx.) ;
    : (FE.) fpad precision 3 max 2dup represent 3 (fx.) ;

    no negative n allowed here!


    That's nice and compact.

    --
    KM

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Mon Oct 19 18:18:29 2026
    From Newsgroup: comp.lang.forth

    peter <peter.noreply@tin.it> writes:
    I might do a FS.N where n would be significant digits

    Or you implement f.rdp <https://net2o.de/gforth/Floating_002dpoint-output.html#index-f_002erdp>
    and get something that is useful for a number of other use cases as
    well. F.RDP uses scientific notation if d (decimal places) is too big
    for r (field width), among other conditions. So if you want
    scientific notation, use np>nr. It does not limit itself to p digits,
    if it has more room; p is just the minimum shown precision; it's used
    for deciding between fixed-point and scientific notation.

    - 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html
    --- Synchronet 3.22a-Linux NewsLink 1.2