🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.forth
Article #201

Re: Tests for (DDFS.)

#201
From: Krishna Myneni
Date: Fri, 30 Oct 2026 12:35
93 lines
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

Technical Details
Message-ID: <11c22v6$7nhj$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11b7rcu$31u3u$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Krishna Myneni <krishna.myneni@ccreweb.org>
Newsgroups: comp.lang.forth
Subject: Re: Tests for (DDFS.)
Date: Fri, 30 Oct 2026 07:35:50 -0500
Organization: A noiseless patient Spider
Lines: 93
Message-ID: <11c22v6$7nhj$1@dont-email.me>
References: <11b7rcu$31u3u$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 30 Oct 2026 12:35:51 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="253491"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/BgbZGER3ELaxrxASbnXbB"; posting-host="8cb22e99e35151a4ee1acb78bc959c36"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:lvOp3K57Q3BsACe4b894t2Iz4IU= sha256:Y4OmySgW1X/PsPTELr+YjFMncYAEMNWT4EdnLIjMr0c=
	sha1:rj4H7JDdJ2sYL2FtSmVk2HyGacw= sha256:vNTPFqi6TURndfXCazc8rWIJIg52YGeci6C0V3WMtA0=
In-Reply-To: <11b7rcu$31u3u$1@dont-email.me>
Content-Language: en-US