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, <kris…@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 ===
Tests for (DDFS.)
- From
- Krishna Myneni <kris…@ccreweb.org>
- Organization
- A noiseless patient Spider
- Message-ID
- <11b7…@dont-email.me>
- Date
- Newsgroups
- comp.lang.forth