On Monday, July 24, 2017 at 5:24:05 PM UTC-5, Anton Ertl wrote:
> krishna...org writes:
...
> >... But, there is no way to ensure F.RDP will
> >always use fixed point format for output, and the behavior of
> >F.RDP is too complicated to be easily predicted.
>
> It's pretty easy: If you want fixed point and hardly care care about
> significant digits, use
>
> : f.rd 1 f.rdp ;
>
F.RDP can have its uses, but, in practice, it is not a
convenient choice for formatted floating point output.
The point is not that one does not care about significant
digits for fixed point output, but that the number of
significant digits varies for like-kind of numbers in a
column. For example, calculations with a well defined
absolute uncertainty of some quantity as a function of
an independent variable may be made to an error tolerance,
e.g. +/- 0.001 meters -- in such a case, we want to
display the column of numbers (in units of meters) to
3 decimal places. However, the integer portion of the
number may vary from zero to 10 meters. Then, the number
of significant digits varies from 3 to 5, in this case.
F.RDP will not guarantee that your output stays in
fixed point format.
> and you will get fixed point whenever fixed point makes some sense
> (i.e., when the result fits, and as long as there is at least 1
> significant digit. E.g., you will get fixed point notation for
>
> 1.23e4 12 6 1 f.rdp \ outputs "12300.000000"
> 1.23e-6 12 6 1 f.rdp \ outputs " 0.000001"
>
The above is ok, when you want fixed point output and you
specify 6 decimal places.
> but gives exponential notation for
>
> 1.23e5 12 6 1 f.rdp \ outputs "1.23000000E5"
> 1.23e-7 12 6 1 f.rdp \ outputs "1.2300000E-7"
>
> What would you prefer instead of exponential notation in these cases?
>
This is not ok, because I want fixed point format in
my column of numbers. The column is not easily readable
if the format changes, even if the field width is the
same. My preference is that it stays in fixed point format
with the specified number of decimal places, e.g.
1.23e5 12 6 1 f.rdp \ outputs "123000.000000"
1.23e-7 12 6 1 f.rdp \ outputs " 0.000000"
Note that the first number overflows the field width,
and this is acceptable. It means the programmer did
not estimate his required field width correctly, and
he can go back and fix his field width if he wants
fixed point output. This would be entirely appropriate
if the tolerance on the numbers was ~1e-6. If, however,
it is important to express the column of numbers to
a fixed number of significant digits, then the programmer
should have chosen scientific notation as the output
format.
> If you always want exponential notation, use np>nr, as recommended by
> the documentation.
>
> So it's easy to predict the behaviour, you just have to invest the
> time to think through the the parameters.
>
I feel that F.RDP tries to do too many things. It suffers
from the same problem as F~ in ANS-Forth.
When you have a range that spans many orders of magnitude,
(35 in this case) there is simply no useful way of preparing
fixed width column output to represent a fixed number of
significant digits other than to use scientific or engineering
notation.
> But anyway, if you want something like this, use 14 14 15 f.rdp, and
> you get
>
> 3.1415926536E0
>
> F.RDP prefers showing mantissa digits over the kind of fixed
> exponential format that you outline above, but does that hurt
> readability more than exponential notation itself? I don't think so.
If you set np>nr, both the first and second arguments to
F.RDP are meaningless -- the output is determined only
by the number of significant digits, and the sign of the
number. This does not make for a nicely aligned
justified column, unless you assume the sign to be
uniform.
>
> >case 2)
> >The column output should display a fixed point format
> >with a constant number of decimal places (in contrast
> >with a constant number of significant digits, as in
> >case 1). The number of of significant digits may vary
> >for each number, e.g.
> >
> >12345678901234
> >--------------
> > 21.3657
> > -1.0021
> > 1020.7448
> > -15384.0931
> >
> >Once again, we use a field width of 14. Now, the number
> >of decimal places is constant, but the number of
> >significant digits vary from row to row. The numbers are
> >all aligned to the decimal point, which is very easy to
> >do since right justification of the output string within
> >the field will produce the appropriate alignment.
>
> That's pretty much what the F.RD above gives you, if you limit
> yourself to numbers that fit fixed-point notation. However, what do
> you do if you have to print 1.23456e20 or 1.23456e-10?
>
I assume you meant F.RDP in the sentence above.
If you have to print numbers over such a wide range of
magnitude as 1e20 and 1e-10, you should choose case 1),
i.e. use scientific notation for the entire column, not
fixed point output. This is a programmer decision, not one
which should be made by the output word. The fixed point
output word should do what it's told to do.
> >case 3)
> >The column output is desired in fixed point format within
> >a constant field width, but with neither a constant number
> >of decimal places nor a constant number of significant
> >digits. Alignment should be to the decimal point.
> >
> >12345678901234
> >--------------
> > 21.3657206
> > 1.0021
> > -516.7
> > 65532.
> >
> >The range of numbers in this last example is exaggerated
> >from the typical use cases I've encountered, but it is
> >common to need this type of formatting within a fixed-width
> >column.
>
> Common? Not really. I cannot remember ever seeing this before.
>
It is required when a column of numbers aren't like-kinds
of quantities, for example, and need different tolerances
(different number of decimal places) and different number
of significant digits (scale of numbers). Even for like-kind
of quantities it is sometimes needed. For example, consider
measurements of various lengths describing an object, which
may range from meter to cm scale, each measured to a
different tolerance, but all expressed in the same units.
Another instance in which the number of decimal places and
the number of significant digits may change is when a
measurement instrument's scale changes.
> >For this case, the output word does need three
> >parameters: the field width, the number of decimal places,
> >and the offset (column position) of the decimal point.
>
> Sounds like nr, np, and nd to me (F.RDP does not produce output
> like this).
>
Yes, almost, but the problem with specifying nr, np, and nd
is that there is no way to align to the decimal point. However,
this case is perhaps a special case, and will require special
word(s) to handle.
Krishna