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.
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
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
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.
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 frontThank you.
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
...
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.
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 tosignificant digits) or the number of decimal places?
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
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.
127.9e 2 e.p \ prints 128eWhat is the 2? It does not appear to be either the precision (number of >significant digits) or the number of decimal places?
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.
display a digit after the decimal point. E.g.:significant digits) or the number of decimal places?
127.9e 2 e.p \ prints 128e
What is the 2? It does not appear to be either the precision (number of
Krishna Myneni <krishna.myneni@ccreweb.org> writes:
127.9e 2 e.p \ prints 128eWhat 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.
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.
...
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
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.
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.
I think that for many uses of FP output words the significant digitsIt is generally true that the actual number of significant digits for a calculation are not known by the programmer, unless they have done
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.
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?
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>
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.
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.
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.
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.
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.
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.
...
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.
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
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.
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 ===
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!
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
-1 warnings ! works when entered manually. Tried inserting in gforthrc0|gforthrc
definitions but no luck.
-1 warnings ! works when entered manually. Tried inserting in gforthrc0|gforthrc
definitions but no luck.
I notice that "warnings on" also works, opposite of "warnings off".
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 ===
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?
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
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
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.
...
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.
...
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.
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 -
... 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.
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.
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 ===
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!
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.
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.nThe output from F.RD is not only farther from the input value, it
429228004229873.62-a ok
The F.N output is a more accurate representation of the average
measurement. ...
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.
...
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?
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 -
...
Since binary -> decimal conversion with 17 significant digits is
guaranteed to cycle in a round trip for binary64
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.
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).
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 #> ;
...
FPSTR before converting to a double length integer. The actual numberswhich can be represented around -0.6e-17 are spaced like this:
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
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.
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.
...
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.
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!
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.
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
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
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
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
...
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
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.
...
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
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 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?
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.
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.
: 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
IF ... IF ... ELSE ... ELSE ... THEN THEN
Is this consistent with the standard?
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
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
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
Krishna Myneni <krishna.myneni@ccreweb.org> writes:This does not seem to be what it does in either Gforth or kForth with
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
...
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.
Lets now compile our different implementations
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.
On 10/17/26 12:27 AM, Anton Ertl wrote:
Krishna Myneni <krishna.myneni@ccreweb.org> writes:This does not seem to be what it does in either Gforth or kForth with
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
...
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 ===
Krishna Myneni <krishna.myneni@ccreweb.org> writes:
On 10/17/26 12:27 AM, Anton Ertl wrote:
Krishna Myneni <krishna.myneni@ccreweb.org> writes:This does not seem to be what it does in either Gforth or kForth with
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
...
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:
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:-).It tests out right!
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
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.
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
...
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
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:Nice to see that you could integrate it in kForth!
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
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
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.
On 10/19/26 9:44 AM, Krishna Myneni wrote:I did it even simpler as I already had a factor for fs. and fe.
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
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!
I might do a FS.N where n would be significant digits
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 76 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 55:03:10 |
| Calls: | 1,265 |
| Calls today: | 1 |
| Files: | 1,362 |
| D/L today: |
3 files (2,684K bytes) |
| Messages: | 285,585 |