🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.forth
Article #83

Re: FCONSTANT specification

#83
From: marcel hendrix
Date: Wed, 14 Oct 2026 22:47
138 lines
8593 bytes
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

FORTH> 37 >XD-TEST
full input                 2.7182818284590452353602874713526624977572e0
input cut to 37 places =   2.7182818284590452353602874713526624977e0
estimate                   2.7182818284590452353602874713526624977e0
estimate of estimate       2.7182818284590452353602874713526624977e0
estimate2 - input =  0e0
full input                 6.2831853071795864769252867665590057683943e0
input cut to 37 places =   6.2831853071795864769252867665590057683e0
estimate                   6.2831853071795864769252867665590057682e0
estimate of estimate       6.2831853071795864769252867665590057682e0
estimate2 - input = 2.3509887016445750159374730744444913556e-38
full input                 2.3561944901923449288469825374596271631478e0
input cut to 37 places =   2.3561944901923449288469825374596271631e0
estimate                   2.3561944901923449288469825374596271630e0
estimate of estimate       2.3561944901923449288469825374596271630e0
estimate2 - input = 8.2284604557560125557811557605557197447e-38
( expect optimal result for XDPRECISION = 38 ) ok

FORTH> 27 >XD-TEST
full input                 2.7182818284590452353602874713526624977572e0
input cut to 27 places =   2.718281828459045235360287471e0
estimate                   2.718281828459045235360287471e0
estimate of estimate       2.718281828459045235360287471e0
estimate2 - input =  0e0
full input                 6.2831853071795864769252867665590057683943e0
input cut to 27 places =   6.283185307179586476925286766e0
estimate                   6.283185307179586476925286765e0
estimate of estimate       6.283185307179586476925286765e0
estimate2 - input = 9.999999999502223297179835753e-28
full input                 2.3561944901923449288469825374596271631478e0
input cut to 27 places =   2.356194490192344928846982537e0
estimate                   2.356194490192344928846982535e0
estimate of estimate       2.356194490192344928846982535e0
estimate2 - input = 1.999999999970974320485304401e-27
( expect optimal result for XDPRECISION = 38 ) ok

I also have a >DD-TEST for 106 bit mantissas. The results are 
qualitatively the same. A test for iForth's extended floats shows a lot 
of potential for improvement but that will be something for the next 
release.

-marcel
Technical Details
Message-ID: <11ap0ps$hfkr$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>

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: marcel hendrix <mhx@iae.nl>
Newsgroups: comp.lang.forth
Subject: Re: FCONSTANT specification
Date: Thu, 15 Oct 2026 00:47:24 +0200
Organization: A noiseless patient Spider
Lines: 138
Message-ID: <11ap0ps$hfkr$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 14 Oct 2026 22:47:25 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="573083"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18PgmhcMSeZeKjG2oIWuGY+5CDjm2bIDMQ="; posting-host="71b9a0e399787dbe460b5ff91bd951ca"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:08Q7mEw06QXByyV+yak4A98FPC4= sha256:IwQj7gd4WjGfxVayyX8HnmizGVsi18/BGR4TfxbxX80=
	sha1:I0LbMgK5/64yw/AA6FLPbubLaUM= sha256:/rSlRhrKqkoC+MuUFM5/BOSMqx4wFmu0JvLijkU2CWQ=
In-Reply-To: <11aj7gg$3r545$1@dont-email.me>
Content-Language: en-US