Thread View: comp.lang.forth
26 messages
26 total messages
Started by Krishna Myneni
Tue, 20 Oct 2026 13:47
Tests for (DDFS.)
Author: Krishna Myneni
Date: Tue, 20 Oct 2026 13:47
Date: Tue, 20 Oct 2026 13:47
83 lines
4048 bytes
4048 bytes
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
Link to latest dd_io.4th, providing (DDFS.), for use with ddarith.4th:
https://github.com/mynenik/kForth-32/blob/master/forth-src/dd_io.4th
=== begin ddfsdot-test.4th ===
\ ddfsdot-test.4th
\
\ Test (ddfs.) double double precision binary to
\ decimal string conversion.
\
\ Use double precision fp to generate reference
\ outputs for ddfs. This requires a high quality
\ REPRESENT capable of providing properly rounded
\ binary to decimal conversion with 33 digits.
\
\ p = significand bits
\ PRECISION (P_min) = 1 + ceiling(p*log10(2))
\
\ p = 53, PRECISION = 17
\ p = 106, PRECISION = 33
\
\ K. Myneni, <krishna.myneni@ccreweb.org>
include ans-words
include ttester
include ddarith
include dd_io
32 set-precision
[UNDEFINED] (ddfs.) ABORT" Needs definition of (DDFS.)" [THEN]
\ Compare the decimal significands of two scientific notation
\ strings e.g. one generated by (fs.) and one by (ddfs.) to
\ PRECISION digits.
: compsig ( caddr1 u1 caddr2 u2 -- n )
\ replace both string lengths u1 and u2 with PRECISION+1
PRECISION 1+ swap drop swap >r swap drop r> over compare
;
fvariable r
TESTING (DDFS.)
t{ ( 1) 0.30000000000000003e0 r df! r df@ (fs.) r df@ 0e (ddfs.)
compsig -> 0 }t
t{ ( 2) 9.9999993504564039e-39 r df! r df@ (fs.) r df@ 0e (ddfs.)
compsig -> 0 }t
t{ ( 3) -1.0000000133514319e-10 r df! r df@ (fs.) r df@ 0e (ddfs.)
compsig -> 0 }t
t{ ( 4) -9007199254740991.5e0 r df! r df@ (fs.) r df@ 0e (ddfs.)
compsig -> 0 }t
=== end ddfsdot-test.4th ===
Re: Tests for (DDFS.)
Author: Krishna Myneni
Date: Tue, 20 Oct 2026 16:15
Date: Tue, 20 Oct 2026 16:15
19 lines
1872 bytes
1872 bytes
On 10/20/26 8:47 AM, Krishna Myneni wrote: ... > > 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. > ... Typing the string outputs from (FS.) and (DDFS.) shows that (DDFS.) is not rounding properly. -- KM
Re: Tests for (DDFS.)
Author: marcel hendrix
Date: Tue, 20 Oct 2026 17:26
Date: Tue, 20 Oct 2026 17:26
16 lines
1787 bytes
1787 bytes
On 10/20/2026 6:15 PM, Krishna Myneni wrote: > On 10/20/26 8:47 AM, Krishna Myneni wrote: > ... >> >> ... >> 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. 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 ? -marcel
Re: Tests for (DDFS.)
Author: marcel hendrix
Date: Tue, 20 Oct 2026 17:41
Date: Tue, 20 Oct 2026 17:41
31 lines
2537 bytes
2537 bytes
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: >> ... >>> >>> ... >>> 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. > 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 ? > FORTH> 53-bits! S" 9.9999993504564039e-39" >DD fswap +E. 2 spaces +E. 9.9999993504564044884e-0039 -2.4574614153997716484e-0056 ok FORTH> 53-bits! S" 0.30000000000000003e0" >DD fswap +E. 2 spaces +E. 3.0000000000000005126e-0001 -1.4408920985006246408e-0017 ok FORTH> 53-bits! S" -1.0000000133514319e-10" >DD fswap +E. 2 spaces +E. -1.0000000133514319362e-0010 6.0018089739605790726e-0027 ok FORTH> 53-bits! S" -9007199254740991.5e0" >DD fswap +E. 2 spaces +E. -9.0071992547409920000e+0015 5.0000000000000000000e-0001 ok The second number is critical, on the fourth one may be lucky because the low word is exactly 0.5? -marcel
Re: Tests for (DDFS.)
Author: marcel hendrix
Date: Tue, 20 Oct 2026 17:51
Date: Tue, 20 Oct 2026 17:51
29 lines
2503 bytes
2503 bytes
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: >> ... >>> >>> ... >>> 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. > 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 ? Or, using xdfloats and showing the low and high xfloat separately: FORTH> S" 9.9999993504564039e-39" >XD fswap +E. 2 spaces +E. 9.9999993504564038992e-0039 2.7761965966859100882e-0058 ok FORTH> S" 0.30000000000000003e0" >XD fswap +E. 2 spaces +E. 3.0000000000000002998e-0001 1.0967909050947355352e-0020 ok FORTH> S" -1.0000000133514319e-10" >XD fswap +E. 2 spaces +E. -1.0000000133514319000e-0010 1.5520703912062604677e-0031 ok FORTH> S" -9007199254740991.5e0" >XD fswap +E. 2 spaces +E. -9.0071992547409915000e+0015 0.0000000000000000000e+0000 ok Here only the 2nd test might have trouble. -marcel
Re: Tests for (DDFS.)
Author: Krishna Myneni
Date: Tue, 20 Oct 2026 17:55
Date: Tue, 20 Oct 2026 17:55
70 lines
4025 bytes
4025 bytes
On 10/20/26 12:41 PM, marcel hendrix wrote: > 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: >>> ... >>>> >>>> ... >>>> 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. >> 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 ? >> > > FORTH> 53-bits! S" 9.9999993504564039e-39" >DD fswap +E. 2 spaces +E. > 9.9999993504564044884e-0039 -2.4574614153997716484e-0056 ok > FORTH> 53-bits! S" 0.30000000000000003e0" >DD fswap +E. 2 spaces +E. > 3.0000000000000005126e-0001 -1.4408920985006246408e-0017 ok > FORTH> 53-bits! S" -1.0000000133514319e-10" >DD fswap +E. 2 spaces +E. > -1.0000000133514319362e-0010 6.0018089739605790726e-0027 ok > FORTH> 53-bits! S" -9007199254740991.5e0" >DD fswap +E. 2 spaces +E. > -9.0071992547409920000e+0015 5.0000000000000000000e-0001 ok > > The second number is critical, on the fourth one may be lucky because > the low word is exactly 0.5? > Below is a comparison of the output from (fs.) with a precision of 32 digits, from Bailey's ddfun package, and the implementation of (ddfs.) used here. The output from (fs.) uses just the first double. A space has been inserted between the printed significand and the exponent in each case to make comparing the last digits easier. -- KM === begin output comparisons === 20 Oct 2026 Comparison of (ddfs.) output vs dp2_to_dd output to 32 digits dp2_to_dd conversion is based on Bailey's Fortran 90 ddfun library (ddfs.) output is from kForth-64/32/Win32 dd_io.4th ( 1 ) 0.30000000000000003d0,0.0e0 (fs.) 3.0000000000000004440892098500626 e-01 dp2_to_dd 3.0000000000000004440892098500626 e-1 (ddfs.) 3.0000000000000004440892098500619 dd-1 ( 2 ) 9.9999993504564039d-39,0.0d0 (fs.) 9.9999993504564039245746141539977 e-39 dp2_to_dd 9.9999993504564039245746141539976 e-39 (ddfs.) 9.9999993504564039245746141539972 dd-39 ( 3 ) -1.0000000133514319d-10,0.0d0 (fs.) -1.0000000133514319600180897396058 e-10 dp2_to_dd -1.0000000133514319600180897396057 e-10 (ddfs.) -1.0000000133514319600180897396057 dd-10 ( 4 ) (fs.) -9.0071992547409920000000000000000 e+15 dp2_to_dd -9.0071992547409920000000000000000 e15 (ddfs.) -9.0071992547409920000000000000000 dd15 === end output comparisons ===
Re: Tests for (DDFS.)
Author: Krishna Myneni
Date: Tue, 20 Oct 2026 18:48
Date: Tue, 20 Oct 2026 18:48
76 lines
4420 bytes
4420 bytes
On 10/20/26 12:41 PM, marcel hendrix wrote: > 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: >>> ... >>>> >>>> ... >>>> 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. >> 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 ? >> > > FORTH> 53-bits! S" 9.9999993504564039e-39" >DD fswap +E. 2 spaces +E. > 9.9999993504564044884e-0039 -2.4574614153997716484e-0056 ok > FORTH> 53-bits! S" 0.30000000000000003e0" >DD fswap +E. 2 spaces +E. > 3.0000000000000005126e-0001 -1.4408920985006246408e-0017 ok > FORTH> 53-bits! S" -1.0000000133514319e-10" >DD fswap +E. 2 spaces +E. > -1.0000000133514319362e-0010 6.0018089739605790726e-0027 ok > FORTH> 53-bits! S" -9007199254740991.5e0" >DD fswap +E. 2 spaces +E. > -9.0071992547409920000e+0015 5.0000000000000000000e-0001 ok > > The second number is critical, on the fourth one may be lucky because > the low word is exactly 0.5? > All of the doubles have 17 decimal digits, which means they reduce in double precision to a reproducible binary number. Furthermore, they are 17 digit roundings of exactly representable numbers in binary64. I don't believe there is a problem with using 0.0e0 for the second double for this case. One can see that even Bailey's ddfun conversion routines don't always reproduce the 32nd digit of the reference output (from (f.s)). Even in Bailey's paper [1], there are two different numbers given for the number of digits that are meaningful with respect to the input decimal string: "For some of these problems, twice the normal level, or roughly 32-digit accuracy, is sufficient." "DDFUN. This packages provide double-double (approx. 31 digits) arithmetic, in an all-Fortran-90 environment." "QD. This package includes routines to perform “double-double” (approx. 31 digits) and “quad-double” (approx. 62 digits) arithmetic. ... The QD package is much faster than using arbitrary precision software in applications where 31 or 62 digits is sufficient." It's not clear to me whether we can expect 32 digits of accuracy for an input decimal string to dd conversion or not, but he clearly states that one can only trust 31 digits from the ddfun package to be correctly rounded. The output of dp2_to_dd shows this to be the case. The output of the implementation of (DDFS.) tested here is clearly much worse than the matching of the reference string from the Fortran 90 ddfun conversion routine. -- KM [1]. High-Precision Floating-Point Arithmetic in Scientific Computation, David H. Bailey, 28 January 2005. ( I found this on the internet, but I have to find the link again )
Re: Tests for (DDFS.)
Author: Krishna Myneni
Date: Tue, 20 Oct 2026 18:53
Date: Tue, 20 Oct 2026 18:53
12 lines
1693 bytes
1693 bytes
On 10/20/26 1:48 PM, Krishna Myneni wrote: > ... Furthermore, they are > 17 digit roundings of exactly representable numbers in binary64. > ... The above sentence is not stated correctly. It should be, "Furthermore, they are 17 digit roundings of known exact decimal representations of double-precision numbers.
Re: Tests for (DDFS.)
Author: Krishna Myneni
Date: Tue, 20 Oct 2026 22:41
Date: Tue, 20 Oct 2026 22:41
26 lines
2213 bytes
2213 bytes
On 10/20/26 12: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: >> ... >>> >>> ... >>> 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. > Simply setting the low part of a double double to 0 might be a bit too > simplistic? No, it is correct. Remember that the double double precision is considered to be the sum of the two double precision numbers within a wider binary format. The 0.0e is an extension of the same binary pattern of the first double padded with 0 bits, so it does not change the value of the exact decimal representation, when the double is extended in this way to dd. -- KM
Re: Tests for (DDFS.)
Author: dxf
Date: Wed, 21 Oct 2026 00:15
Date: Wed, 21 Oct 2026 00:15
16 lines
1622 bytes
1622 bytes
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: >> ... >>> >>> ... >>> 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. > 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 ? 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.
Re: Tests for (DDFS.)
Author: Krishna Myneni
Date: Wed, 21 Oct 2026 01:05
Date: Wed, 21 Oct 2026 01:05
72 lines
4050 bytes
4050 bytes
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:
>>> ...
>>>>
>>>> ...
>>>> 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.
>> 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 ?
>
> 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.
>
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?
--
KM
=== 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:
! $ 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
! shell script gnu-complib-dd.scr
! The script will generate the .o files for linking to the program below.
!
! Revisions:
! 2026-09-18 km; directly set the two DP numbers of a DD variable
!
program dp2todd
use ddmodule
implicit none
real (ddknd) a(2)
type (dd_real) t1, t2
print *, 'Enter a pair of double precision (DP) numbers:'
read(*, '(D28.16,D28.16)') a(1), a(2)
print *, 'The two DP numbers are:'
write(*,'(E30.17,2X,E30.17)') a(1), a(2)
print *, 'The two DP hex values are:'
write(*, '(Z16,2X,Z16)') a(1), a(2)
print *, 'The double double (DD) value of the pair is:'
t1%ddr(1) = a(1)
t1%ddr(2) = a(2)
call ddwrite(6,40,32,t1)
end program dp2todd
=== end code ===
Re: Tests for (DDFS.)
Author: dxf
Date: Wed, 21 Oct 2026 03:23
Date: Wed, 21 Oct 2026 03:23
43 lines
3253 bytes
3253 bytes
On 21/10/2026 12:05 pm, Krishna Myneni wrote: > 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: >>>> ... >>>>> >>>>> ... >>>>> 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. >>> 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 ? >> >> 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. >> > > 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). The input routine had a different issue. Debugging proved so onerous that I just replaced the lot and it solved original problem. In retrospect the issue was likely due to the original's use of >FLOAT which split the conversion into two. My routine was the equivalent of a >DDFLOAT written from scratch. The code proved simpler than JVN's state machine >FLOAT thingy. > > It is more productive to make (DDFS.) a Forth equivalent to ddwrite(), to provide the same performance. I wouldn't know. I've only ever considered my patches to JVN's DDFS. to be just that - patches. The 'peeldigit' routine should never produce 'negative digits' - but it does. I've no idea how Bailey did things or whether JVN was cutting corners but the latter's routine clearly had/has issues. > What does your present version of (DDFS.) output on these tests? As I consider my present DDFS. routine merely a 'sticky-taped' version of the original that doesn't produce glaring errors, I don't hold it up as any solution. The latter is for others more interested than me to develop. > ...
Re: Tests for (DDFS.)
Author: marcel hendrix
Date: Wed, 21 Oct 2026 07:26
Date: Wed, 21 Oct 2026 07:26
25 lines
2552 bytes
2552 bytes
On 10/21/2026 2:15 AM, dxf wrote: > On 21/10/2026 4:26 am, marcel hendrix wrote: >> On 10/20/2026 6:15 PM, 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 ? > I wasn't aware any JVN packages performed rounding. By now, most of JVN's code has been replaced. The splitting code has been revised. > 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. 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. However, current threads make interesting arguments for automatic internal rounding if constants and literals are to be portable, and/or if it is known that the user intends the number to be exact in some sense of the word for whatever reason. I still have fundamental questions there and follow the threads to be able to eventually formulate them (or see them answered). -marcel
Re: Tests for (DDFS.)
Author: Krishna Myneni
Date: Wed, 21 Oct 2026 08:50
Date: Wed, 21 Oct 2026 08:50
94 lines
4682 bytes
4682 bytes
On 10/20/26 8:05 PM, Krishna Myneni wrote:
> ...
> === 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:
> ! $ 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
> ! shell script gnu-complib-dd.scr
> ! The script will generate the .o files for linking to the program below.
> !
> ! Revisions:
> ! 2026-09-18 km; directly set the two DP numbers of a DD variable
> !
> program dp2todd
> use ddmodule
> implicit none
> real (ddknd) a(2)
> type (dd_real) t1, t2
> print *, 'Enter a pair of double precision (DP) numbers:'
> read(*, '(D28.16,D28.16)') a(1), a(2)
> print *, 'The two DP numbers are:'
> write(*,'(E30.17,2X,E30.17)') a(1), a(2)
> print *, 'The two DP hex values are:'
> write(*, '(Z16,2X,Z16)') a(1), a(2)
> print *, 'The double double (DD) value of the pair is:'
> t1%ddr(1) = a(1)
> t1%ddr(2) = a(2)
> call ddwrite(6,40,32,t1)
> end program dp2todd
> === end code ===
>
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.
( 1)
$ ./dp2_to_dd
Enter a pair of double precision (DP) numbers:
0.30000000000000003d0,0.0d0
The two DP numbers are:
0.30000000000000004E+00 0.00000000000000000E+00
The two DP hex values are:
3FD3333333333334 0
The double double (DD) value of the pair is:
3.0000000000000004440892098500626e-1
( 2)
$ ./dp2_to_dd
Enter a pair of double precision (DP) numbers:
9.9999993504564039d-39,0.0d0
The two DP numbers are:
0.99999993504564039E-38 0.00000000000000000E+00
The two DP hex values are:
380B38FB80000000 0
The double double (DD) value of the pair is:
9.9999993504564039245746141539976e-39
( 3)
$ ./dp2_to_dd
Enter a pair of double precision (DP) numbers:
-1.0000000133514319d-10,0.0d0
The two DP numbers are:
-0.10000000133514320E-09 0.00000000000000000E+00
The two DP hex values are:
BDDB7CDFE0000000 0
The double double (DD) value of the pair is:
-1.0000000133514319600180897396057e-10
( 4)
$ ./dp2_to_dd
Enter a pair of double precision (DP) numbers:
-9007199254740991.5d0,0.0d0
The two DP numbers are:
-0.90071992547409920E+16 0.00000000000000000E+00
The two DP hex values are:
C340000000000000 0
The double double (DD) value of the pair is:
-9.0071992547409920000000000000000e15
Re: Tests for (DDFS.)
Author: marcel hendrix
Date: Wed, 21 Oct 2026 10:45
Date: Wed, 21 Oct 2026 10:45
52 lines
3744 bytes
3744 bytes
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 3.7865323450608573444e-0042 ok Or, trying to compensate for the FPU 80-bit stack: FORTH> 0e dfvalue aa ok FORTH> 53-bits! s" -1.0000000133514319600180897396057e-10" >dd cr fswap TO aa aa +e. space TO aa aa +e. -1.0000000133514319362e-0010 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 0.00000000000000000E+00 cr fover +e. space fdup +e. cr ddfe. cr .( 3.0000000000000004440892098500626e-1 ) 3.0000000000000005126e-0001 0.0000000000000000000e+0000 3.0000000000000004440892098500626e-1 3.0000000000000004440892098500626e-1 ok FORTH> 53-bits! 0.99999993504564039E-38 0.00000000000000000E+00 cr fover +e. space fdup +e. cr ddfe. cr .( 9.9999993504564039245746141539976e-39 ) 9.9999993504564044884e-0039 0.0000000000000000000e+0000 9.9999993504564039245746141539976e-39 9.9999993504564039245746141539976e-39 ok FORTH> 53-bits! -0.10000000133514320E-09 0.00000000000000000E+00 cr fover +e. space fdup +e. cr ddfe. cr .( -1.0000000133514319600180897396057e-10 ) -1.0000000133514321920e-0010 0.0000000000000000000e+0000 -1.0000000133514322185120311624269e-10 -1.0000000133514319600180897396057e-10 ok FORTH> 53-bits! -0.90071992547409920E+16 0.00000000000000000E+00 cr fover +e. space fdup +e. cr ddfe. cr .( -9.0071992547409920000000000000000e15 ) -9.0071992547409920000e+0015 0.0000000000000000000e+0000 -9.0071992547409920000000000000000e15 -9.0071992547409920000000000000000e15 ok
Re: Tests for (DDFS.)
Author: dxf
Date: Wed, 21 Oct 2026 12:52
Date: Wed, 21 Oct 2026 12:52
37 lines
2644 bytes
2644 bytes
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
Re: Tests for (DDFS.)
Author: Krishna Myneni
Date: Wed, 21 Oct 2026 13:53
Date: Wed, 21 Oct 2026 13:53
83 lines
4470 bytes
4470 bytes
On 10/21/26 5:45 AM, 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 . > > Also: > FORTH> s" -1.0000000133514319600180897396057e-10" >dd cr fswap +e. +e. > -1.0000000133514319362e-0010 3.7865323450608573444e-0042 ok > > Or, trying to compensate for the FPU 80-bit stack: > FORTH> 0e dfvalue aa ok > FORTH> 53-bits! s" -1.0000000133514319600180897396057e-10" >dd cr fswap > TO aa aa +e. space TO aa aa +e. > -1.0000000133514319362e-0010 3.7865323450608573444e-0042 ok > > However, note that the float from >DD is -1.0000000133514319362e-0010. , > not -0.10000000133514320E-09 as in your case. > These two numbers have the same hex values for double precision floats: fvariable r ok -1.0000000133514319362e-0010 r df! ok r @ hex u. decimal BDDB7CDFE0000000 ok ok -0.10000000133514320E-09 r df! ok r @ hex u. decimal BDDB7CDFE0000000 ok Your floating point output for double precision is broken: 20 set-precision ok -0.10000000133514320E-09 (fs.) type -1.0000000133514319600e-10 ok \ not -1.0000000133514319362e-0010 -- KM > -marcel > > FORTH> 53-bits! 0.30000000000000004E+00 0.00000000000000000E+00 > cr fover +e. space fdup +e. cr ddfe. cr .( > 3.0000000000000004440892098500626e-1 ) > 3.0000000000000005126e-0001 0.0000000000000000000e+0000 > 3.0000000000000004440892098500626e-1 > 3.0000000000000004440892098500626e-1 ok > FORTH> 53-bits! 0.99999993504564039E-38 0.00000000000000000E+00 > cr fover +e. space fdup +e. cr ddfe. cr .( > 9.9999993504564039245746141539976e-39 ) > 9.9999993504564044884e-0039 0.0000000000000000000e+0000 > 9.9999993504564039245746141539976e-39 > 9.9999993504564039245746141539976e-39 ok > FORTH> 53-bits! -0.10000000133514320E-09 0.00000000000000000E+00 > cr fover +e. space fdup +e. cr ddfe. cr . > ( -1.0000000133514319600180897396057e-10 ) > -1.0000000133514321920e-0010 0.0000000000000000000e+0000 > -1.0000000133514322185120311624269e-10 > -1.0000000133514319600180897396057e-10 ok > FORTH> 53-bits! -0.90071992547409920E+16 0.00000000000000000E+00 > cr fover +e. space fdup +e. cr ddfe. cr . > ( -9.0071992547409920000000000000000e15 ) > -9.0071992547409920000e+0015 0.0000000000000000000e+0000 > -9.0071992547409920000000000000000e15 > -9.0071992547409920000000000000000e15 ok
Re: Tests for (DDFS.)
Author: marcel hendrix
Date: Wed, 21 Oct 2026 17:05
Date: Wed, 21 Oct 2026 17:05
60 lines
4160 bytes
4160 bytes
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 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
FORTH> s" 3.0000000000000004440892098500626e-1"
2dup >DD cr 10 htab DDFE. >DD pad dd! cr pad 32 dump
3.0000000000000004440892098500626e-1
$013A60D0 34 33 33 33 33 33 D3 3F--00 00 00 00 00 00 00 00--00 00 00
00 00 00 00 00--00 00 00 00 00 00 00 00
FORTH> s" -1.0000000133514319600180897396057e-10"
2dup >DD cr 10 htab DDFE. >DD pad dd! cr pad 32 dump
-1.0000000133514319600180897396057e-10
$013A60D0 00 00 00 E0 DF 7C DB BD--E2 18 37 CE 51 1C 55 37--00 00 00
00 00 00 00 00--00 00 00 00 00 00 00 00
FORTH> s" -9.0071992547409920000000000000000e15"
2dup >DD cr 10 htab DDFE. >DD pad dd! cr pad 32 dump
-9.0071992547409920000000000000000e15
$013A60D0 00 00 00 00 00 00 40 C3--00 00 00 00 00 00 00 00--00 00 00
00 00 00 00 00--00 00 00 00 00 00 00 00
It seems we have the same bitpatterns but slightly different text printouts.
-marcel
Re: Tests for (DDFS.)
Author: dxf
Date: Thu, 22 Oct 2026 00:26
Date: Thu, 22 Oct 2026 00:26
66 lines
4460 bytes
4460 bytes
On 22/10/2026 4:05 am, marcel hendrix wrote: > 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? > > ?? It's not a valid question? Who enters literals in parts??? What was the necessity? What was the rationale? If testing 'ddfsdot' was actually the goal then the method of data entry is flawed as it introduced a dependency on the host being IEEE compliant. It's the latter that failed you - not your 'ddfsdot'. All the user needed were the hex values and the DD literal they represented as references. >> 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 > > FORTH> s" 3.0000000000000004440892098500626e-1" > 2dup >DD cr 10 htab DDFE. >DD pad dd! cr pad 32 dump > 3.0000000000000004440892098500626e-1 > $013A60D0 34 33 33 33 33 33 D3 3F--00 00 00 00 00 00 00 00--00 00 00 00 00 00 00 00--00 00 00 00 00 00 00 00 > > FORTH> s" -1.0000000133514319600180897396057e-10" > 2dup >DD cr 10 htab DDFE. >DD pad dd! cr pad 32 dump > -1.0000000133514319600180897396057e-10 > $013A60D0 00 00 00 E0 DF 7C DB BD--E2 18 37 CE 51 1C 55 37--00 00 00 00 00 00 00 00--00 00 00 00 00 00 00 00 > > FORTH> s" -9.0071992547409920000000000000000e15" > 2dup >DD cr 10 htab DDFE. >DD pad dd! cr pad 32 dump > -9.0071992547409920000000000000000e15 > $013A60D0 00 00 00 00 00 00 40 C3--00 00 00 00 00 00 00 00--00 00 00 00 00 00 00 00--00 00 00 00 00 00 00 00 > > It seems we have the same bitpatterns but slightly different text printouts. > > -marcel
Re: Tests for (DDFS.)
Author: Anton Ertl
Date: Thu, 22 Oct 2026 06:32
Date: Thu, 22 Oct 2026 06:32
22 lines
2284 bytes
2284 bytes
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"
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: https://forth-standard.org/
EuroForth 2026 CFP: http://www.euroforth.org/ef26/cfp.html
Re: Tests for (DDFS.)
Author: Krishna Myneni
Date: Thu, 22 Oct 2026 12:37
Date: Thu, 22 Oct 2026 12:37
25 lines
2519 bytes
2519 bytes
On 10/22/26 1:32 AM, Anton Ertl wrote: > 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" > 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. -- KM
Re: Tests for (DDFS.)
Author: Krishna Myneni
Date: Thu, 22 Oct 2026 12:41
Date: Thu, 22 Oct 2026 12:41
27 lines
2420 bytes
2420 bytes
On 10/22/26 7:37 AM, Krishna Myneni wrote: > On 10/22/26 1:32 AM, Anton Ertl wrote: >> ... 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" >> > > 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. -- KM
Re: Tests for (DDFS.)
Author: Anton Ertl
Date: Thu, 22 Oct 2026 16:42
Date: Thu, 22 Oct 2026 16:42
34 lines
2726 bytes
2726 bytes
Krishna Myneni <krishna.myneni@ccreweb.org> writes:
>On 10/22/26 7:37 AM, Krishna Myneni wrote:
>> On 10/22/26 1:32 AM, Anton Ertl wrote:
>
>>> ... 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"
>>>
>>
>> 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
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: https://forth-standard.org/
EuroForth 2026 CFP: http://www.euroforth.org/ef26/cfp.html
Re: Tests for (DDFS.)
Author: Krishna Myneni
Date: Thu, 22 Oct 2026 21:05
Date: Thu, 22 Oct 2026 21:05
78 lines
4718 bytes
4718 bytes
On 10/22/26 11:42 AM, Anton Ertl wrote: > Krishna Myneni <krishna.myneni@ccreweb.org> writes: ... >>>> ... 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" >>>> >>> >>> 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 > "120 +/-5", or simply, "120" means something quite different from "123 +/- 5". The latter means that the third digit has some significance so there are three significant digits i.e. there was some basis for obtaining the third digit in measurement, or for retaining it, in computation. "123 +/- 5" is not different from "123. +/- 5" For example, in computation, you may have a set of measurements of the same quantity with two significant digits in each measurement, 120 160 110 120 130 120 140 110 110 110 The uncertainty in each individual measurement in the set is implied to be +/- 5 unless a different measurement uncertainty is specified. If we compute the mean of the set, it is 123 and its uncertainty, the uncertainty of the mean, is 5/sqrt(N), where N=10 (this is only true when there are statistical errors; it does not include systematic errors). The computed mean should be expressed as 123. +/- 1.6 The trailing decimal point in "123." is optional. The uncertainty in the mean cannot just be implied anymore. Since the uncertainty of this computed number is larger than +/- 0.5 it must be explicitly printed. 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. Again, it would have the same mean, but the uncertainty of the mean is now ten times smaller, owing to the implied uncertainty in each measurement of +/- 0.5. The mean uncertainty now is 0.5/sqrt(10), and again, we must explicitly print it, since it smaller than +/- 0.5. 123. +/- 0.16 Therefore, the placement of the decimal point is important, but when the uncertainty is greater than or less than 5 in the next decimal place, the uncertainty should be explicitly specified. For rounding a floating point number to n significant digits, the uncertainty in the number is always +/- 5 in the n+1 digit. -- Krishna
Re: Tests for (DDFS.)
Author: Krishna Myneni
Date: Thu, 22 Oct 2026 21:29
Date: Thu, 22 Oct 2026 21:29
22 lines
2354 bytes
2354 bytes
On 10/22/26 4:05 PM, Krishna Myneni wrote: ... > 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. > It is, of course, highly improbable that the last digit would always turn out to be zero given the size of the fluctuations. But this artificial example was meant to illustrate the importance of the fixed point convention for the number of significant digits. > ...For rounding a floating point number to n significant digits, the > uncertainty in the number is always +/- 5 in the n+1 digit. > The above statement should read, "For rounding to nearest ..." -- Krishna
Re: Tests for (DDFS.)
Author: Krishna Myneni
Date: Fri, 30 Oct 2026 12:35
Date: Fri, 30 Oct 2026 12:35
93 lines
4705 bytes
4705 bytes
On 10/20/26 8:47 AM, Krishna Myneni wrote:
> 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
> ...
It occurred to me to use the MPFR library to determine the correct
binary to decimal conversion strings for any pair of binary64 floating
point numbers representing a double-double precision number, which
effectively provides a 106 bit significand.
This is possible because we can declare two MPFR variables, each with a
128 bit significand, and load these variables from the two binary64
numbers and then add them, to obtain the 128 bit-precision result. The
result can then be converted to a string with n=32 significant digits
using the MPFR function mpfr_get_str():
=== begin code ===
\ Set precision before initializing mp vars
128 mpfr_set_default_prec
mpfr_t hi
mpfr_t lo
mpfr_t sum
hi mpfr_init
lo mpfr_init
sum mpfr_init
FPSTACK? [IF]
: ddwrite ( F: r_hi r_lo -- )
lo GMP_RNDN mpfr_set_d drop
hi GMP_RNDN mpfr_set_d drop
sum hi lo GMP_RNDN mpfr_add drop
sum 32 mpfr.
;
[ELSE]
: ddwrite ( r_hi r_lo -- )
2>r lo 2r> GMP_RNDN mpfr_set_d drop
2>r hi 2r> GMP_RNDN mpfr_set_d drop
sum hi lo GMP_RNDN mpfr_add drop
sum 32 mpfr.
;
[THEN]
=== end code ===
The above code defines a word DDWRITE which is similar to the function
from David Bailey's ddfun package. I've already tested the above
definition of DDWRITE and it works, except for one minor issue having to
do with the implementation of "MPFR." ; also, I need a string output
version.
The word MPFR. is defined in kForth's mpfr-utils.4th (
forth-src/libs/gmp/mpfr-utils.4th ) . The underlying mpfr variable to
decimal string conversion word is MP>STR (also defined in
mpfr-utils.4th), which calls mpfr_get_str(). However, I am reworking
this currently to define a REPRESENT for mpfr variables. The function
mpfr_get_str() provides more options than the behavior of REPRESENT but
it will be useful to define REPRESENT-MPFR which behaves in the same
manner as Forth's REPRESENT.
--
Krishna Myneni
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads