The following test program illustrates the use of double precision...
numbers to check the binary to decimal conversion of dd precision
numbers with the word (DDFS.). In kForth-x, this word is provided in the latest update of dd_io.4th (link below) -- the test program is based on
this assumption.
The output shows that (DDFS.) as presently implemented in dd_io.4th
fails for one of the test cases (test 2), and probably for many more cases. ...
On 10/20/26 8:47 AM, Krishna Myneni wrote:Simply setting the low part of a double double to 0 might be a bit too simplistic? Is the difference in the range of 1e-15 .. 1e-17 ?
...
...
The output shows that (DDFS.) as presently implemented in dd_io.4th
fails for one of the test cases (test 2), and probably for many more
cases.
...
Typing the string outputs from (FS.) and (DDFS.) shows that (DDFS.) is
not rounding properly.
On 10/20/2026 6:15 PM, Krishna Myneni wrote:
On 10/20/26 8:47 AM, Krishna Myneni wrote:Simply setting the low part of a double double to 0 might be a bit too simplistic? Is the difference in the range of 1e-15 .. 1e-17 ?
...
...
The output shows that (DDFS.) as presently implemented in dd_io.4th
fails for one of the test cases (test 2), and probably for many more
cases.
...
Typing the string outputs from (FS.) and (DDFS.) shows that (DDFS.) is
not rounding properly.
On 10/20/2026 6:15 PM, Krishna Myneni wrote:Or, using xdfloats and showing the low and high xfloat separately:
On 10/20/26 8:47 AM, Krishna Myneni wrote:Simply setting the low part of a double double to 0 might be a bit too simplistic? Is the difference in the range of 1e-15 .. 1e-17 ?
...
...
The output shows that (DDFS.) as presently implemented in dd_io.4th
fails for one of the test cases (test 2), and probably for many more
cases.
...
Typing the string outputs from (FS.) and (DDFS.) shows that (DDFS.) is
not rounding properly.
On 10/20/2026 7:26 PM, marcel hendrix wrote:
On 10/20/2026 6:15 PM, Krishna Myneni wrote:
On 10/20/26 8:47 AM, Krishna Myneni wrote:Simply setting the low part of a double double to 0 might be a bit too
...
...
The output shows that (DDFS.) as presently implemented in dd_io.4th
fails for one of the test cases (test 2), and probably for many more
cases.
...
Typing the string outputs from (FS.) and (DDFS.) shows that (DDFS.)
is not rounding properly.
simplistic? Is the difference in the range of 1e-15 .. 1e-17 ?
FORTH> 53-bits!-a S" 9.9999993504564039e-39" >DD fswap +E. 2 spaces +E. 9.9999993504564044884e-0039-a -2.4574614153997716484e-0056 ok
FORTH> 53-bits!-a S" 0.30000000000000003e0"-a >DD fswap +E. 2 spaces +E. 3.0000000000000005126e-0001-a -1.4408920985006246408e-0017 ok
FORTH> 53-bits! S" -1.0000000133514319e-10" >DD fswap +E. 2 spaces +E. -1.0000000133514319362e-0010-a-a 6.0018089739605790726e-0027 ok
FORTH> 53-bits! S" -9007199254740991.5e0"-a-a >DD fswap +E. 2 spaces +E. -9.0071992547409920000e+0015-a-a 5.0000000000000000000e-0001 ok
The second number is critical, on the fourth one may be lucky because
the low word is exactly 0.5?
On 10/20/2026 7:26 PM, marcel hendrix wrote:
On 10/20/2026 6:15 PM, Krishna Myneni wrote:
On 10/20/26 8:47 AM, Krishna Myneni wrote:Simply setting the low part of a double double to 0 might be a bit too
...
...
The output shows that (DDFS.) as presently implemented in dd_io.4th
fails for one of the test cases (test 2), and probably for many more
cases.
...
Typing the string outputs from (FS.) and (DDFS.) shows that (DDFS.)
is not rounding properly.
simplistic? Is the difference in the range of 1e-15 .. 1e-17 ?
FORTH> 53-bits!-a S" 9.9999993504564039e-39" >DD fswap +E. 2 spaces +E. 9.9999993504564044884e-0039-a -2.4574614153997716484e-0056 ok
FORTH> 53-bits!-a S" 0.30000000000000003e0"-a >DD fswap +E. 2 spaces +E. 3.0000000000000005126e-0001-a -1.4408920985006246408e-0017 ok
FORTH> 53-bits! S" -1.0000000133514319e-10" >DD fswap +E. 2 spaces +E. -1.0000000133514319362e-0010-a-a 6.0018089739605790726e-0027 ok
FORTH> 53-bits! S" -9007199254740991.5e0"-a-a >DD fswap +E. 2 spaces +E. -9.0071992547409920000e+0015-a-a 5.0000000000000000000e-0001 ok
The second number is critical, on the fourth one may be lucky because
the low word is exactly 0.5?
... Furthermore, they are
17 digit roundings of exactly representable numbers in binary64.
...
On 10/20/2026 6:15 PM, Krishna Myneni wrote:
On 10/20/26 8:47 AM, Krishna Myneni wrote:Simply setting the low part of a double double to 0 might be a bit too simplistic?
...
...
The output shows that (DDFS.) as presently implemented in dd_io.4th
fails for one of the test cases (test 2), and probably for many more
cases.
...
Typing the string outputs from (FS.) and (DDFS.) shows that (DDFS.) is
not rounding properly.
On 10/20/2026 6:15 PM, Krishna Myneni wrote:
On 10/20/26 8:47 AM, Krishna Myneni wrote:Simply setting the low part of a double double to 0 might be a bit too simplistic? Is the difference in the range of 1e-15 .. 1e-17 ?
...
...
The output shows that (DDFS.) as presently implemented in dd_io.4th fails for one of the test cases (test 2), and probably for many more cases.
...
Typing the string outputs from (FS.) and (DDFS.) shows that (DDFS.) is not rounding properly.
On 21/10/2026 4:26 am, marcel hendrix wrote:
On 10/20/2026 6:15 PM, Krishna Myneni wrote:
On 10/20/26 8:47 AM, Krishna Myneni wrote:Simply setting the low part of a double double to 0 might be a bit too simplistic? Is the difference in the range of 1e-15 .. 1e-17 ?
...
...
The output shows that (DDFS.) as presently implemented in dd_io.4th fails for one of the test cases (test 2), and probably for many more cases.
...
Typing the string outputs from (FS.) and (DDFS.) shows that (DDFS.) is not rounding properly.
I wasn't aware any JVN packages performed rounding. AFAIK some implementations
(yours?) limited numbers printed to PRECISION but that this was truncation - not
rounding. Rounding presented a whole new problem - why I never attempted it.
On 10/20/26 7:15 PM, dxf wrote:
On 21/10/2026 4:26 am, marcel hendrix wrote:
On 10/20/2026 6:15 PM, Krishna Myneni wrote:
On 10/20/26 8:47 AM, Krishna Myneni wrote:Simply setting the low part of a double double to 0 might be a bit too simplistic? Is the difference in the range of 1e-15 .. 1e-17 ?
...
...
The output shows that (DDFS.) as presently implemented in dd_io.4th fails for one of the test cases (test 2), and probably for many more cases.
...
Typing the string outputs from (FS.) and (DDFS.) shows that (DDFS.) is not rounding properly.
I wasn't aware any JVN packages performed rounding.-a AFAIK some implementations
(yours?) limited numbers printed to PRECISION but that this was truncation - not
rounding.-a Rounding presented a whole new problem - why I never attempted it.
The present iteration of (DDFS.) in kForth's dd_io.4th includes some changes you introduced. I would have to back and check JVN's original code (which uses a state machine) to see it performs differently than the subroutine ddwrite() in Bailey's ddfun Fortran 90 package, which is what is used in my program dp2_to_dd.f90 (listed below).
It is more productive to make (DDFS.) a Forth equivalent to ddwrite(), to provide the same performance.
What does your present version of (DDFS.) output on these tests?
...
On 21/10/2026 4:26 am, marcel hendrix wrote:[..]>> Simply setting the low part of a double double to 0 might be a
On 10/20/2026 6:15 PM, Krishna Myneni wrote:
I wasn't aware any JVN packages performed rounding.
AFAIK some implementations
(yours?) limited numbers printed to PRECISION but that this was truncation - not
rounding. Rounding presented a whole new problem - why I never attempted it.
...
=== begin code for dp2_to_dd ===
! dp2_to_dd.f90
!
! K. Myneni, 16 Sep 2026
!
! Input a double double precision (DD) number as a
! pair of double precision (DP) numbers and display
! the DD number in scientific notation. The program
! also displays the input DP numbers in scientific
! notation and their hex values.
!
! Build:
!-a-a $ gfortran -O3 -o dp2_to_dd dp2_to_dd.f90 ddmodule.o ddfuna.o
ddfune.o second.o
!
! Build assumes you have built the Fortran ddfun-v04 package using the
!-a-a shell script gnu-complib-dd.scr
! The script will generate the .o files for linking to the program below.
!
! Revisions:
!-a-a 2026-09-18 km; directly set the two DP numbers of a DD variable
!
program dp2todd
-a-a-a-a-a-a-a use ddmodule
-a-a-a-a-a-a-a implicit none
-a-a-a-a-a-a-a real (ddknd) a(2)
-a-a-a-a-a-a-a type (dd_real) t1, t2
-a-a-a-a-a-a-a print *, 'Enter a pair of double precision (DP) numbers:'
-a-a-a-a-a-a-a read(*, '(D28.16,D28.16)') a(1), a(2)
-a-a-a-a-a-a-a print *, 'The two DP numbers are:'
-a-a-a-a-a-a-a write(*,'(E30.17,2X,E30.17)') a(1), a(2)
-a-a-a-a-a-a-a print *, 'The two DP hex values are:'
-a-a-a-a-a-a-a write(*, '(Z16,2X,Z16)') a(1), a(2)
-a-a-a-a-a-a-a print *, 'The double double (DD) value of the pair is:'
-a-a-a-a-a-a-a t1%ddr(1) = a(1)
-a-a-a-a-a-a-a t1%ddr(2) = a(2)
-a-a-a-a-a-a-a call ddwrite(6,40,32,t1)
end program dp2todd
=== end code ===
On 10/20/26 8:05 PM, Krishna Myneni wrote:[...]> I post the execution output from dp2_to_dd for the 4 test cases in
ddfsdot-test.4th for anyone who wants to reproduce this output. The hex values of the two double precision numbers input to the program are
shown (the second number is, of course, 64-bit 0). Note that the "D" exponent marker must be used to enter a double precision number in Fortran.
On 10/21/2026 10:50 AM, Krishna Myneni wrote:
On 10/20/26 8:05 PM, Krishna Myneni wrote:[...]> I post the execution output from dp2_to_dd for the 4 test cases in
ddfsdot-test.4th for anyone who wants to reproduce this output. The hex values of the two double precision numbers input to the program are shown (the second number is, of course, 64-bit 0). Note that the "D" exponent marker must be used to enter a double precision number in Fortran.
[...]
Strange. I can duplicate 1, 2, and 4 exactly, but not 3: the pair -0.10000000133514320E-09 0.00000000000000000E+00 .
On 10/21/2026 10:50 AM, Krishna Myneni wrote:
On 10/20/26 8:05 PM, Krishna Myneni wrote:[...]> I post the execution output from dp2_to_dd for the 4 test cases in
ddfsdot-test.4th for anyone who wants to reproduce this output. The
hex values of the two double precision numbers input to the program
are shown (the second number is, of course, 64-bit 0). Note that the
"D" exponent marker must be used to enter a double precision number in
Fortran.
[...]
Strange. I can duplicate 1, 2, and 4 exactly, but not 3: the pair -0.10000000133514320E-09 0.00000000000000000E+00 .
Also:
FORTH> s" -1.0000000133514319600180897396057e-10" >dd cr fswap +e. +e. -1.0000000133514319362e-0010-a 3.7865323450608573444e-0042 ok
Or, trying to compensate for the FPU 80-bit stack:
FORTH> 0e dfvalue aa-a ok
FORTH> 53-bits!-a s" -1.0000000133514319600180897396057e-10" >dd cr fswap
TO aa aa +e. space TO aa aa +e.
-1.0000000133514319362e-0010-a 3.7865323450608573444e-0042 ok
However, note that the float from >DD is -1.0000000133514319362e-0010. ,
not -0.10000000133514320E-09 as in your case.
-marcel
FORTH> 53-bits! 0.30000000000000004E+00-a-a-a-a-a-a-a-a 0.00000000000000000E+00
-acr fover +e. space fdup +e.-a cr ddfe. cr .(
-a3.0000000000000004440892098500626e-1 )
-a3.0000000000000005126e-0001-a 0.0000000000000000000e+0000
-a3.0000000000000004440892098500626e-1
-a3.0000000000000004440892098500626e-1-a ok
FORTH> 53-bits! 0.99999993504564039E-38-a-a-a-a-a-a-a-a 0.00000000000000000E+00
-acr fover +e. space fdup +e.-a cr ddfe. cr .(
-a9.9999993504564039245746141539976e-39 )
-a9.9999993504564044884e-0039-a 0.0000000000000000000e+0000
-a9.9999993504564039245746141539976e-39
-a9.9999993504564039245746141539976e-39-a ok
FORTH> 53-bits! -0.10000000133514320E-09-a-a-a-a-a-a-a 0.00000000000000000E+00
-acr fover +e. space fdup +e.-a cr ddfe. cr .
( -1.0000000133514319600180897396057e-10 )
-1.0000000133514321920e-0010-a 0.0000000000000000000e+0000 -1.0000000133514322185120311624269e-10 -1.0000000133514319600180897396057e-10-a ok
FORTH> 53-bits! -0.90071992547409920E+16-a-a-a-a-a-a-a 0.00000000000000000E+00
-acr fover +e. space fdup +e.-a cr ddfe. cr .
( -9.0071992547409920000000000000000e15 )
-9.0071992547409920000e+0015-a 0.0000000000000000000e+0000 -9.0071992547409920000000000000000e15
-9.0071992547409920000000000000000e15-a ok
On 21/10/2026 9:45 pm, marcel hendrix wrote:
On 10/21/2026 10:50 AM, Krishna Myneni wrote:
On 10/20/26 8:05 PM, Krishna Myneni wrote:[...]> I post the execution output from dp2_to_dd for the 4 test cases in >>> ddfsdot-test.4th for anyone who wants to reproduce this output. The hex values of the two double precision numbers input to the program are shown (the second number is, of course, 64-bit 0). Note that the "D" exponent marker must be used to enter a double precision number in Fortran.
[...]
Strange. I can duplicate 1, 2, and 4 exactly, but not 3: the pair -0.10000000133514320E-09 0.00000000000000000E+00 .
Is your >DD broken that you need to enter literals using another way?
enter 3.0000000000000004440892098500626e-1
print 3.0000000000000004440892098500625E-1
4 5 6 7 8 9 A B C D E F 0 1
0193:2DF4 34 33 33 33 33 33 D3 3F 00 00 00 00 00 00
\ 3F D3 33 33 33 33 33 34 0
enter 9.9999993504564039245746141539976e-39
print 9.9999993504564039245746141539977E-39
4 5 6 7 8 9 A B C D E F 0 1
0193:2DF4 00 00 00 80 FB 38 0B 38 00 00 00 00 00 00
\ 38 0B 38 FB 80 00 00 00 0
enter -1.0000000133514319600180897396057e-10
print -1.0000000133514319600180897396056E-10
4 5 6 7 8 9 A B C D E F 0 1
0193:2DF4 00 00 00 E0 DF 7C DB BD 00 00 00 00 00 00
\ BD DB 7C DF E0 00 00 00 0
enter -9.0071992547409920000000000000000e15
print -9.0071992547409920000000000000000E15
4 5 6 7 8 9 A B C D E F 0 1
0193:2DF4 00 00 00 00 00 00 40 C3 00 00 00 00 00 00
\ C3 40 00 00 00 00 00 00 0
On 10/21/2026 2:52 PM, dxf wrote:
On 21/10/2026 9:45 pm, marcel hendrix wrote:
On 10/21/2026 10:50 AM, Krishna Myneni wrote:
On 10/20/26 8:05 PM, Krishna Myneni wrote:[...]> I post the execution output from dp2_to_dd for the 4 test cases in >>>> ddfsdot-test.4th for anyone who wants to reproduce this output. The hex values of the two double precision numbers input to the program are shown (the second number is, of course, 64-bit 0). Note that the "D" exponent marker must be used to enter a double precision number in Fortran.
[...]
Strange. I can duplicate 1, 2, and 4 exactly, but not 3: the pair -0.10000000133514320E-09 0.00000000000000000E+00 .
Is your >DD broken that you need to enter literals using another way?
??
enter-a 3.0000000000000004440892098500626e-1
print-a 3.0000000000000004440892098500625E-1
-a-a-a-a-a-a-a-a-a-a 4-a 5-a 6-a 7-a 8-a 9-a A-a B-a C-a D-a E-a F-a 0-a 1 >> 0193:2DF4 34 33 33 33 33 33 D3 3F 00 00 00 00 00 00
\ 3F D3 33 33 33 33 33 34-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a 0
enter-a 9.9999993504564039245746141539976e-39
print-a 9.9999993504564039245746141539977E-39
-a-a-a-a-a-a-a-a-a-a 4-a 5-a 6-a 7-a 8-a 9-a A-a B-a C-a D-a E-a F-a 0-a 1 >> 0193:2DF4 00 00 00 80 FB 38 0B 38 00 00 00 00 00 00
\ 38 0B 38 FB 80 00 00 00-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a 0
enter-a -1.0000000133514319600180897396057e-10
print-a -1.0000000133514319600180897396056E-10
-a-a-a-a-a-a-a-a-a-a 4-a 5-a 6-a 7-a 8-a 9-a A-a B-a C-a D-a E-a F-a 0-a 1 >> 0193:2DF4 00 00 00 E0 DF 7C DB BD 00 00 00 00 00 00
\ BD DB 7C DF E0 00 00 00-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a 0
enter-a -9.0071992547409920000000000000000e15
print-a -9.0071992547409920000000000000000E15
-a-a-a-a-a-a-a-a-a-a 4-a 5-a 6-a 7-a 8-a 9-a A-a B-a C-a D-a E-a F-a 0-a 1 >> 0193:2DF4 00 00 00 00 00 00 40 C3 00 00 00 00 00 00
\ C3 40 00 00 00 00 00 00-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a 0
FORTH> s" 3.0000000000000004440892098500626e-1"
2dup >DD cr 10 htab DDFE.-a-a >DD pad dd! cr pad 32 dump
-a-a-a-a-a-a-a-a-a 3.0000000000000004440892098500626e-1
$013A60D0-a 34 33 33 33-a 33 33 D3 3F--00 00 00 00-a 00 00 00 00--00 00 00 00-a 00 00 00 00--00 00 00 00-a 00 00 00 00
FORTH> s" -1.0000000133514319600180897396057e-10"
2dup >DD cr 10 htab DDFE.-a-a >DD pad dd! cr pad 32 dump
-a-a-a-a-a-a-a-a-a -1.0000000133514319600180897396057e-10
$013A60D0-a 00 00 00 E0-a DF 7C DB BD--E2 18 37 CE-a 51 1C 55 37--00 00 00 00-a 00 00 00 00--00 00 00 00-a 00 00 00 00
FORTH> s" -9.0071992547409920000000000000000e15"
2dup >DD cr 10 htab DDFE.-a-a >DD pad dd! cr pad 32 dump
-a-a-a-a-a-a-a-a-a -9.0071992547409920000000000000000e15
$013A60D0-a 00 00 00 00-a 00 00 40 C3--00 00 00 00-a 00 00 00 00--00 00 00 00-a 00 00 00 00--00 00 00 00-a 00 00 00 00
It seems we have the same bitpatterns but slightly different text printouts.
-marcel
None of my floating point code rounds in any of the printing words, it >indeed truncates. For it to be automatic, an idea about the precision
of the calculation is needed and the printing knows nothing about that.
marcel hendrix <mhx@iae.nl> writes:
None of my floating point code rounds in any of the printing words, it
indeed truncates. For it to be automatic, an idea about the precision
of the calculation is needed and the printing knows nothing about that.
I don't see a difference between rounding and truncation here. If the program knows the precision, it can use a appropriate word that
outputs only the significant digits or marks the last significant
digit (e.g., by underlining it). However, given that the program
usually does not compute this information, the Gforth words that you
can pass a precision to, such as F.RDP and E.P, treat it as a minimum
rather than exact number of significant digits to be shown, i.e., they
may show more digits. E.g.:
123e 2 e.p \ prints "123e"
On 10/22/26 1:32 AM, Anton Ertl wrote:
...-a However, given that the program
usually does not compute this information, the Gforth words that you
can pass a precision to, such as F.RDP and E.P, treat it as a minimum
rather than exact number of significant digits to be shown, i.e., they
may show more digits.-a E.g.:
123e 2 e.p \ prints "123e"
This sort of behavior, not getting what you asked for, is not likely to
be used by the scientific community. In calculations or experiments, it
is important to show the actual number of significant digits.
On 10/22/26 7:37 AM, Krishna Myneni wrote:
On 10/22/26 1:32 AM, Anton Ertl wrote:
...-a However, given that the program
usually does not compute this information, the Gforth words that you
can pass a precision to, such as F.RDP and E.P, treat it as a minimum
rather than exact number of significant digits to be shown, i.e., they
may show more digits.-a E.g.:
123e 2 e.p \ prints "123e"
This sort of behavior, not getting what you asked for, is not likely to
be used by the scientific community. In calculations or experiments, it
is important to show the actual number of significant digits.
In calculations or experiments, it is important to show the actual
number of *requested* significant digits, often followed by an
uncertainty estimate. If an uncertainty is not specified, then the >uncertainty is assumed to be +/-5 units in the n+1th digit, where n is
the number of significant digits shown.
Krishna Myneni <krishna.myneni@ccreweb.org> writes:...
...-a However, given that the program
usually does not compute this information, the Gforth words that you
can pass a precision to, such as F.RDP and E.P, treat it as a minimum
rather than exact number of significant digits to be shown, i.e., they >>>> may show more digits.-a E.g.:
123e 2 e.p \ prints "123e"
This sort of behavior, not getting what you asked for, is not likely to
be used by the scientific community. In calculations or experiments, it
is important to show the actual number of significant digits.
In calculations or experiments, it is important to show the actual
number of *requested* significant digits, often followed by an
uncertainty estimate. If an uncertainty is not specified, then the
uncertainty is assumed to be +/-5 units in the n+1th digit, where n is
the number of significant digits shown.
E.P is obviously not made for showing 1.2e2, but I see no harm in
showing 123e +/-5e
Now suppose we had a set of measurements with three significant digits
in each measurement with the same numbers as above. The measurements
would be written with the trailing decimal point as
120. 160. 110. 120. 130. 120. 140. 110. 110. 110.
...For rounding a floating point number to n significant digits, the uncertainty in the number is always +/- 5 in the n+1 digit.
The double-double (dd) precision floating format consists of a pair of
IEEE 754 binary64 (double precision) floats. It effectively provides a significand which has twice the precision of an ordinary binary64 float:
p = 2*53 = 106 bits
An ordinary binary64 number can be converted to a decimal string using REPRESENT. With a high-quality REPRESENT which provides >= 33
significant decimal digits we can generate test cases for binary to
decimal conversion of dd precision numbers simply by using binary64
numbers.
Furthermore, if REPRESENT can provide a larger number of digits, it is possible to generate test cases for much larger p e.g. binary128 or binary256 numbers, simply using double-precision floats.
The following test program illustrates the use of double precision
numbers to check the binary to decimal conversion of dd precision
numbers with the word (DDFS.). In kForth-x, this word is provided in the latest update of dd_io.4th (link below) -- the test program is based on
this assumption.
I will emphasize again the important part: The reference string is the
one obtained with (FS.) from a double-precision number with a PRECISION
set to 32.
The output shows that (DDFS.) as presently implemented in dd_io.4th
fails for one of the test cases (test 2), and probably for many more cases.
--
Krishna Myneni
...
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 76 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 54:18:43 |
| Calls: | 1,265 |
| Calls today: | 1 |
| Files: | 1,362 |
| D/L today: |
3 files (2,684K bytes) |
| Messages: | 285,563 |