🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.forth
Article #86

Re: FCONSTANT specification

#86
From: Krishna Myneni
Date: Thu, 15 Oct 2026 12:22
117 lines
7521 bytes
On 10/14/26 5:47 PM, marcel hendrix wrote:
> On 10/12/2026 8:05 PM, Krishna Myneni wrote:
>> On 10/12/26 11:38 AM, marcel hendrix wrote:
>>> On 10/12/2026 6:08 PM, Krishna Myneni wrote:
>>>> On 10/12/26 9:56 AM, marcel hendrix wrote:
>>>>> On 10/12/2026 4:14 PM, Krishna Myneni wrote:
>>>>> [..]> 2.0e0 FLOG FCONSTANT _FLOG2
>>>>>> [UNDEFINED] FCEIL [IF]
>>>>>> : FCEIL ( F: r1 -- r2 ) FNEGATE FLOOR FNEGATE ;
>>>>>> [THEN]
>>>
>>> [..]
>>>
>>>> What binary precision (number of significand bits) are you using for 
>>>> your xdfloats?
>>> xdfloats are 128 bits ( 2 extended doubles [80 bits] ).
>>> ddfloats are 106 bits ( 2 doubles [53 bits] ).
>>> The '25' is based on an extended float (64 bit mantissa).
>>>
>>
> 
> [..]
> 
>>
>> The problem could be at the front end (decimal string to binary 
>> conversion) or for the inverse case (binary to decimal string), or 
>> possibly both. For now, you could test with a single specified 
>> extended float binary value and output it to 21 decimal digits and see 
>> if it cycles back to the same binary value. To test the cycling, you 
>> have to start with the binary value. If that fails, it would indicate 
>> a problem.
> This is a very good and helpful suggestion. It deepened my 
> understanding, although a full solution is not obvious yet.
> 
> Here are the results for the 128 bit package. Testing is done with three 
> 40 digit numbers, xd=E, xd=PI*2 and xd=3*PI/4. I first convert the full 
> number from text (with the mantissa cut to XDPRECISION digits) to 
> binary. That binary output is converted back to text (estimate) and then
> estimate is converted to estimate estimate. The binary of estimate 
> estimate is compared to the binary of input cut.
> It can be observed that the numbers eventually cycle if XDPRECISION is 
> sufficiently high, and they approach the full input better and better 
> (but not exactly). That doesn't matter because the binary values become 
> indistinguishable although the text representations don't. For instance, 
> with xdprecision = 39,
> 2.718281828459045235360287471352662497757e0  and
> 2.718281828459045235360287471352662497770e0  give the same binary result.
> 
> For lower xdprecision (37) the value for xd=2*pi differs by ~ 2e-38
> from its cycled result. This is what I expect from a 128 bit mantissa,
> -128e F2^X +e. prints 2.9387358770557187700e-0039.
> 
> I interpret this as follows:
>   1. Always use #38 SET-XDPRECISION for computations
>   2. Do not worry when the cycled value of a constant *prints*
>      differently, it's the binary value that counts
>   3. Rounding numbers must be done by rounding the full precision binary
>      value like `a human`, not by choosing a lower XDPRECISION. This is
>      counter-intuitive, but look at the the 27 >XD-TEST result below: the
>      (estimate2 - input) values differ by 1 decimal, depending on
>      the input value's digit pattern.
> 
> FORTH> 39 >XD-TEST
> full input                 2.7182818284590452353602874713526624977572e0
> input cut to 39 places =   2.718281828459045235360287471352662497757e0
> estimate                   2.718281828459045235360287471352662497770e0
> estimate of estimate       2.718281828459045235360287471352662497770e0
> estimate2 - input =  0e0
> full input                 6.2831853071795864769252867665590057683943e0
> input cut to 39 places =   6.283185307179586476925286766559005768394e0
> estimate                   6.283185307179586476925286766559005768349e0
> estimate of estimate       6.283185307179586476925286766559005768349e0
> estimate2 - input =  0e0
> full input                 2.3561944901923449288469825374596271631478e0
> input cut to 39 places =   2.356194490192344928846982537459627163147e0
> estimate                   2.356194490192344928846982537459627163137e0
> estimate of estimate       2.356194490192344928846982537459627163137e0
> estimate2 - input =  0e0
> ( expect optimal result for XDPRECISION = 38 ) ok
> 
> FORTH> 38 >XD-TEST
> full input                 2.7182818284590452353602874713526624977572e0
> input cut to 38 places =   2.71828182845904523536028747135266249775e0
> estimate                   2.71828182845904523536028747135266249777e0
> estimate of estimate       2.71828182845904523536028747135266249777e0
> estimate2 - input =  0e0
> full input                 6.2831853071795864769252867665590057683943e0
> input cut to 38 places =   6.28318530717958647692528676655900576839e0
> estimate                   6.28318530717958647692528676655900576844e0
> estimate of estimate       6.28318530717958647692528676655900576844e0
> estimate2 - input =  0e0
> full input                 2.3561944901923449288469825374596271631478e0
> input cut to 38 places =   2.35619449019234492884698253745962716314e0
> estimate                   2.35619449019234492884698253745962716313e0
> estimate of estimate       2.35619449019234492884698253745962716313e0
> estimate2 - input =  0e0
> ( expect optimal result for XDPRECISION = 38 ) ok
> 
...

These tests look encouraging.

IEEE 754 guarantees that lower precision binary formats are lossless 
when converted to higher precision binary formats. So if you need binary 
significands which convert accurately to 40 decimal digits or higher you 
can do so with double precision alone, assuming you have a REPRESENT 
that will output a sufficient number of digits, properly rounded. The 53 
bit significand from the double, extended with 0 bit values, can then be 
used within the higher precision format, and the conversion from the 
higher format should show the same digits (the unbiased base 2 exponent 
should remain the same).

--
Krishna


Technical Details
Message-ID: <11aqghu$2cftn$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: <11aide4$1ibse$1@dont-email.me> <11aijvt$3iobp$1@dont-email.me> <11ainru$3kbfc$1@dont-email.me> <11aipvm$3kbfc$2@dont-email.me> <11aisee$e9sc$1@dont-email.me> <11aj0ma$3oci3$1@dont-email.me> <11aj2eq$ed42$1@dont-email.me> <11aj7gg$3r545$1@dont-email.me> <11ap0ps$hfkr$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: FCONSTANT specification
Date: Thu, 15 Oct 2026 07:22:22 -0500
Organization: A noiseless patient Spider
Lines: 117
Message-ID: <11aqghu$2cftn$1@dont-email.me>
References: <11aide4$1ibse$1@dont-email.me> <11aijvt$3iobp$1@dont-email.me>
 <11ainru$3kbfc$1@dont-email.me> <11aipvm$3kbfc$2@dont-email.me>
 <11aisee$e9sc$1@dont-email.me> <11aj0ma$3oci3$1@dont-email.me>
 <11aj2eq$ed42$1@dont-email.me> <11aj7gg$3r545$1@dont-email.me>
 <11ap0ps$hfkr$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 15 Oct 2026 12:22:23 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2506679"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18OVYkk5O+kZAY3amqcfIDI"; posting-host="4d7c7aa7f18884cced98d4752616bdc7"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:xLLDAZUIvFuCfz3DmKmdNRcedf4= sha256:smPEKsxPBAClwinTt0SKdsH0Kccp5lyuQRtSLbL5FGI=
	sha1:9nojwQ7vWNEGajjwe0Qej2CbX6A= sha256:pKaaAEwThmtCuHFHjRn1odMNv/ZvinIb5TUa4A4Z3q8=
In-Reply-To: <11ap0ps$hfkr$1@dont-email.me>
Content-Language: en-US