🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.forth
72 messages
72 total messages Page 1 of 2 Started by marcel hendrix Mon, 12 Oct 2026 10:40
Page 1 of 2 • 72 total messages
FCONSTANT specification
#63
Author: marcel hendrix
Date: Mon, 12 Oct 2026 10:40
30 lines
2375 bytes
In view of the current thread of floating-point input and output, how 
should we specify FCONSTANTs ? My concern is when the system potentially 
uses single, double, or extended-double (or worse).
Is the algorithm that guarantees that a printed number can be converted 
'losslessly' back to its internal presentation able to do that 
regardless of the number of bits in the internal representation?

We probably don't want that FP library code developed for a double 
implementation specifies table constants etc. that are depending on the 
precision of its internal implementation. (I had this problem last week 
when porting a ddfloat library to xdfloats, although there it was 
especially tricky.)

Example:
0e dfvalue t1  0e sfvalue t2
1e f>xd 7e f>xd xd/ xdconstant xd=1/7
xd=1/7 xdfe. 1.42857142857142857142857142857142857142e-1

1e 7e f/          +e. 1.4285714285714285714e-0001
1e 7e f/ TO t1 t1 +e. 1.4285714285714284921e-0001
1e 7e f/ TO t2 t2 +e. 1.4285714924335479736e-0001

You will notice that simply rounding the 80-bit output will not produce 
the correct double and single constants. (xd => extended double is ok, 
by accident?)

The standard (can't?) say(s) anything about this?

-marcel
Re: FCONSTANT specification
#65
Author: Krishna Myneni
Date: Mon, 12 Oct 2026 12:31
41 lines
3354 bytes
On 10/12/26 5:40 AM, marcel hendrix wrote:
> In view of the current thread of floating-point input and output, how 
> should we specify FCONSTANTs ? My concern is when the system potentially 
> uses single, double, or extended-double (or worse).
> Is the algorithm that guarantees that a printed number can be converted 
> 'losslessly' back to its internal presentation able to do that 
> regardless of the number of bits in the internal representation?
> 
> We probably don't want that FP library code developed for a double 
> implementation specifies table constants etc. that are depending on the 
> precision of its internal implementation. (I had this problem last week 
> when porting a ddfloat library to xdfloats, although there it was 
> especially tricky.)
> 

There is, of course, no lossless translation of decimal input strings 
into a finite internal binary representation, whether it is single 
precision, double precision, extended precision, or higher. IEEE 754 
does guarantee that a lower precision binary representation is always 
lossless when going to a supported higher precision representation e.g. 
binary32 to binary64.

The implementation of REPRESENT which I've discussed using dtoa() is 
specific to converting decimal strings to internal double precision 
binary format. There are versions of this code for IEEE extended 
precision format, and maybe also for higher precision IEEE formats. 
Please check the netlib page for dtoa.

Your question applies not just to FCONSTANTs but also to FLITERALs. One 
problem with addressing your question is that it depends on a specific 
format, and the Forth standard does not require any particular format. 
If we are talking about internal decimal format only, which no one seems 
to use, then it seems like it would be easy to specify how a decimal 
string should convert to internal representation. For all IEEE binary 
formats, the number of decimal digits which must be specified for 
roundtrip binary -> decimal -> binary are given in the IEEE 754 
standard. For double precision, it is 17.

--
KM
Re: FCONSTANT specification
#66
Author: Krishna Myneni
Date: Mon, 12 Oct 2026 13:38
38 lines
2449 bytes
On 10/12/26 7:31 AM, Krishna Myneni wrote:
> On 10/12/26 5:40 AM, marcel hendrix wrote:
>> In view of the current thread of floating-point input and output, how 
>> should we specify FCONSTANTs ? My concern is when the system 
>> potentially uses single, double, or extended-double (or worse).

> ... For all IEEE binary 
> formats, the number of decimal digits which must be specified for 
> roundtrip binary -> decimal -> binary are given in the IEEE 754 
> standard. For double precision, it is 17.
> ..

I was unable to give a more complete answer for IEEE binary formats, 
having been pulled away from the computer. Here is a more complete 
answer, from the IEEE 754 standard:

Limits on correctly rounded conversion:

binary16: Pmin = 5 digits
binary32: Pmin = 9 digits
binary64: Pmin = 17 digits
binary128: Pmin = 36 digits

For all other binary formats bf,

Pmin(bf) = 1 + ceiling(p*log_10(2)), where p is the number of 
significant bits in bf.

e.g. for double precision, p = 53 bit significand, the above formula 
gives 17 decimal digits.

For 64 bit significand (80-bit extended precision) , the formula gives 
21 digits.

--
KM

Re: FCONSTANT specification
#67
Author: Krishna Myneni
Date: Mon, 12 Oct 2026 14:14
33 lines
2081 bytes
On 10/12/26 8:38 AM, Krishna Myneni wrote:
...
> from the IEEE 754 standard:
> 
> Limits on correctly rounded conversion:
> 
> binary16: Pmin = 5 digits
> binary32: Pmin = 9 digits
> binary64: Pmin = 17 digits
> binary128: Pmin = 36 digits
> 
> For all other binary formats bf,
> 
> Pmin(bf) = 1 + ceiling(p*log_10(2)), where p is the number of 
> significant bits in bf.
> 
> e.g. for double precision, p = 53 bit significand, the above formula 
> gives 17 decimal digits.
> 
> For 64 bit significand (80-bit extended precision) , the formula gives 
> 21 digits.
> ...

In Forth:

2.0e0 FLOG FCONSTANT _FLOG2
[UNDEFINED] FCEIL [IF]
: FCEIL ( F: r1 -- r2 ) FNEGATE FLOOR FNEGATE ;
[THEN]

: P_min ( u1 -- u2) S>F _FLOG2 F* FCEIL F>D DROP 1+ ;

Re: FCONSTANT specification
#68
Author: marcel hendrix
Date: Mon, 12 Oct 2026 14:56
23 lines
2049 bytes
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]
> 
> : P_min ( u1 -- u2) S>F _FLOG2 F* FCEIL F>D DROP 1+ ;

FORTH> xd=pi (xdfe.) 2dup CR TYPE  DROP #25 4 + CR TYPE
3.14159265358979323846264338327950288422e0
3.141592653589793238462643383 ok

So here it is easy to see it is correct.
What if PI had been 3.1415926535897932384626433835121212121212 ?

FORTH> s" 3.1415926535897932384626433835121212121212e" cr 2dup TYPE
 >XD (xdfe.) DROP #25 4 + CR TYPE
3.1415926535897932384626433835121212121212e
3.141592653589793238462643383 ok

Maybe don't ever output more than 25 digits?

-marcel
Re: FCONSTANT specification
#69
Author: Krishna Myneni
Date: Mon, 12 Oct 2026 16:08
31 lines
2264 bytes
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]
>>
>> : P_min ( u1 -- u2) S>F _FLOG2 F* FCEIL F>D DROP 1+ ;
> 
> FORTH> xd=pi (xdfe.) 2dup CR TYPE  DROP #25 4 + CR TYPE
> 3.14159265358979323846264338327950288422e0
> 3.141592653589793238462643383 ok
> 
> So here it is easy to see it is correct.
> What if PI had been 3.1415926535897932384626433835121212121212 ?
> 
> FORTH> s" 3.1415926535897932384626433835121212121212e" cr 2dup TYPE
>  >XD (xdfe.) DROP #25 4 + CR TYPE
> 3.1415926535897932384626433835121212121212e
> 3.141592653589793238462643383 ok
> 
> Maybe don't ever output more than 25 digits?
> 

What binary precision (number of significand bits) are you using for 
your xdfloats?

--
KM

Re: FCONSTANT specification
#71
Author: marcel hendrix
Date: Mon, 12 Oct 2026 16:38
17 lines
1942 bytes
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).

-marcel
Re: FCONSTANT specification
#73
Author: Krishna Myneni
Date: Mon, 12 Oct 2026 18:05
45 lines
3409 bytes
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).
> 

Ok. It is a composite of two extended precision numbers. That makes it a 
little difficult to apply the P_min formula. But maybe we can go by the 
analogy with double double precision.

If a ddfloat was equivalent to a single binary significand of 106 bits, 
according to the P_min formula, the output to decimal with 33 digits 
would cycle back to the same binary pattern. Then, an xdfloat treated as 
equivalent to a single binary significand of 128 bits was output in 
decimal to P_min = 40 digits would cycle back to the same binary pattern.

In reality, the double double or double extended are probably not 
equivalent to a normalized binary encoding of the sum of the significand 
bits for two doubles/two extended for each case, so I think the number 
of digits given by P_min represent a maximum limit on the number of 
decimal digits which would cycle if they were output by the same binary 
pattern.

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.

--
KM
Re: FCONSTANT specification
#74
Author: Anton Ertl
Date: Mon, 12 Oct 2026 18:36
31 lines
2509 bytes
marcel hendrix <mhx@iae.nl> writes:
>In view of the current thread of floating-point input and output, how 
>should we specify FCONSTANTs ? My concern is when the system potentially 
>uses single, double, or extended-double (or worse).

Standard Forth only has one FP type on the FP stack, and FCONSTANT
stores that and pushes that, just like F! and F@ do.

>Is the algorithm that guarantees that a printed number can be converted 
>'losslessly' back to its internal presentation able to do that 
>regardless of the number of bits in the internal representation?

Sure.

>We probably don't want that FP library code developed for a double 
>implementation specifies table constants etc. that are depending on the 
>precision of its internal implementation.

You will have to work with some limit, but I expect that you can make
numbers with, say 36 digits, and ideally you can derive the numbers
for various formats up to binary128 from that.  But if the mathematics
behind these numbers is not just to use an approximation to something,
but to have a bias that corrects for some error elsewhere, maybe that
is not enough.

- 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: FCONSTANT specification
#77
Author: marcel hendrix
Date: Tue, 13 Oct 2026 20:29
41 lines
3150 bytes
On 10/12/2026 8:36 PM, Anton Ertl wrote:
> marcel hendrix <mhx@iae.nl> writes:
>> In view of the current thread of floating-point input and output, how
>> should we specify FCONSTANTs ? My concern is when the system potentially
>> uses single, double, or extended-double (or worse).
> 
> Standard Forth only has one FP type on the FP stack, and FCONSTANT
> stores that and pushes that, just like F! and F@ do.
> 

Procrustes Forth? On such a system SF@/! and DF@/! must convert an 
internal to an external format, and the conversion must be precise.
Switching between single and double precision is a well-known trick to 
improve convergence of certain algorithms. This conversion *could* be a 
serious headache.

>> Is the algorithm that guarantees that a printed number can be converted
>> 'losslessly' back to its internal presentation able to do that
>> regardless of the number of bits in the internal representation?
> 
> Sure.

My question is: if we have a text representation of a number with say 40 
(or whatever) digits, will that unchanged string work to give the
best approximation on single, double, ... binary internal formats?
Is your answer to that: 'Sure' ?
>> We probably don't want that FP library code developed for a double
>> implementation specifies table constants etc. that are depending on the
>> precision of its internal implementation.
> 
> You will have to work with some limit, but I expect that you can make
> numbers with, say 36 digits, and ideally you can derive the numbers
> for various formats up to binary128 from that.  But if the mathematics
> behind these numbers is not just to use an approximation to something,
> but to have a bias that corrects for some error elsewhere, maybe that
> is not enough.
...you can derive the numbers...

The question still is: How?

-marcel
Re: FCONSTANT specification
#78
Author: Anton Ertl
Date: Wed, 14 Oct 2026 05:50
103 lines
6393 bytes
marcel hendrix <mhx@iae.nl> writes:
>On 10/12/2026 8:36 PM, Anton Ertl wrote:
>> marcel hendrix <mhx@iae.nl> writes:
>>> In view of the current thread of floating-point input and output, how
>>> should we specify FCONSTANTs ? My concern is when the system potentially
>>> uses single, double, or extended-double (or worse).
>> 
>> Standard Forth only has one FP type on the FP stack, and FCONSTANT
>> stores that and pushes that, just like F! and F@ do.
>> 
>
>Procrustes Forth? On such a system SF@/! and DF@/! must convert an 
>internal to an external format, and the conversion must be precise.

Yes, at least one of them, and possibly both have to perform the
conversion.  And if you use the 387 FP instructions, both have to
perform a conversion even if you set the mantissa length to 53 or 24
bits, because the exponent length still is 16 bits, i.e., you can
represent numbers as normal number in the internal format that are
denormal or infinity in the external format.

Concerning precision, there is the double-rounding problem
<https://en.wikipedia.org/wiki/Rounding#Double_rounding>, e.g., if you
perform an FP operation like F+ at 80 bits (or even at 53+16 bits),
and then convert to binary64, in some cases you get a different (less
precise) result than if you had performed FP addition directly in
binary64 format (with only one rounding round), e.g., with SSE2.

I have read that double rounding for the FP operations where IEEE FP
requires a specific result (rather than allowing any result up to a
certain error), in particular F+ F- F* F/ FSQRT, double rounding does
not change the result compared to single rounding if the mantissa
length of the first rounding is more than twice as long than the
mantissa length of the second rounding.  E.g., F+ SF! should not
suffer from double-rounding errors if the FP stack uses a 53-bit or
64-bit mantissa.

>Switching between single and double precision is a well-known trick to 
>improve convergence of certain algorithms.

I have not heard of that.  Why should doing the first steps in SP
improve convergence over doing it all in DP or extended precision?

>>> Is the algorithm that guarantees that a printed number can be converted
>>> 'losslessly' back to its internal presentation able to do that
>>> regardless of the number of bits in the internal representation?
>> 
>> Sure.
>
>My question is: if we have a text representation of a number with say 40 
>(or whatever) digits, will that unchanged string work to give the
>best approximation on single, double, ... binary internal formats?
>Is your answer to that: 'Sure' ?

Actually, having read up on the double-rounding problem, I am no
longer sure: I have come across
<https://www.exploringbinary.com/double-rounding-errors-in-floating-point-conversions/>,
which shows that for decimal-to-FP conversion there are cases where
double rounding can give a result that's further from the actual value
than 1/2 ulp.  And when you store an irrational or otherwise
arbitrarily long number with finite length, you already have one
rounding step when performing this storing.

However, the problem affects only relatively few numbers, and you can
store as many digits of your infinitely long number that the problem
does not occur for it, for the desired mantissa lengths.  Once you
have that, you "only" need a decimal-to-binary (or, if you store the
numbers in hex format, a hex-to-binary) conversion routine that
performs the appropriate rounding (not what Visual C++ does according
to
<https://www.exploringbinary.com/double-rounding-errors-in-floating-point-conversions/>.

>> You will have to work with some limit, but I expect that you can make
>> numbers with, say 36 digits, and ideally you can derive the numbers
>> for various formats up to binary128 from that.  But if the mathematics
>> behind these numbers is not just to use an approximation to something,
>> but to have a bias that corrects for some error elsewhere, maybe that
>> is not enough.
>...you can derive the numbers...
>
>The question still is: How?

Gforth converts string-to-double with strtod(), and glibc apparently
implements it to give you a result within 1/2 ulp (and it also has
strtold() for long double); for double-extended numbers, you will have
to look at the algorithms that are used for that problem, e.g., in
strtod().

For producing numbers for your table, I would just produce longer and
longer decimal (or hexadecimal) numbers, convert them to all the
formats that you are interested in, check that the result is less than
1/2 ulp (for the format) from the actual number, and stop when that's
the case for all the target formats.  With double-extended as one of
the target formats, this will probably require 42 digits of mantissa
or more.  I have not worked with Mathematica, but from what I have
read about it, it seems to be the tool for this job.

- 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: FCONSTANT specification
#80
Author: albert
Date: Wed, 14 Oct 2026 08:10
30 lines
1994 bytes
In article <11am4ae$fte4$1@dont-email.me>, marcel hendrix  <mhx@iae.nl> wrote:
>On 10/12/2026 8:36 PM, Anton Ertl wrote:
>> marcel hendrix <mhx@iae.nl> writes:
>>> In view of the current thread of floating-point input and output, how
>>> should we specify FCONSTANTs ? My concern is when the system potentially
>>> uses single, double, or extended-double (or worse).
>>
>> Standard Forth only has one FP type on the FP stack, and FCONSTANT
>> stores that and pushes that, just like F! and F@ do.
>>
>
>Procrustes Forth? On such a system SF@/! and DF@/! must convert an
>internal to an external format, and the conversion must be precise.
>Switching between single and double precision is a well-known trick to
>improve convergence of certain algorithms. This conversion *could* be a
>serious headache.

The illusion that you can do something precise with imprecise numbers ...

>The question still is: How?
The answer is "mu".

>
>-marcel

Groetjes Albert
-- 
The Chinese government is satisfied with its military superiority over USA.
The next 5 year plan has as primary goal to advance life expectancy
over 80 years, like Western Europe.
Re: FCONSTANT specification
#82
Author: Anton Ertl
Date: Wed, 14 Oct 2026 08:25
15 lines
1889 bytes
albert@spenarnc.xs4all.nl writes:
>The illusion that you can do something precise with imprecise numbers ...

What is an "imprecise number"?  In any case, every FP number has a
precise value.  It may not be the value you are interested in, but
that does not make the value any less precise.  And thinking about FP
numbers as "imprecise" or intervals etc. leads you down the path to
wrong conclusions.

- 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: FCONSTANT specification
#83
Author: 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
Re: FCONSTANT specification
#84
Author: dxf
Date: Thu, 15 Oct 2026 01:40
15 lines
1547 bytes
On 14/10/2026 7:25 pm, Anton Ertl wrote:
> albert@spenarnc.xs4all.nl writes:
>> The illusion that you can do something precise with imprecise numbers ...
> 
> What is an "imprecise number"?  In any case, every FP number has a
> precise value.  It may not be the value you are interested in, but
> that does not make the value any less precise.  And thinking about FP
> numbers as "imprecise" or intervals etc. leads you down the path to
> wrong conclusions.

If the recently-dubbed "high quality" REPRESENTs aren't printing out
intervals then what are they doing?  Following the leader?


Re: FCONSTANT specification
#85
Author: Anton Ertl
Date: Thu, 15 Oct 2026 05:55
28 lines
2556 bytes
dxf <dxforth@gmail.com> writes:
>On 14/10/2026 7:25 pm, Anton Ertl wrote:
>> What is an "imprecise number"?  In any case, every FP number has a
>> precise value.  It may not be the value you are interested in, but
>> that does not make the value any less precise.  And thinking about FP
>> numbers as "imprecise" or intervals etc. leads you down the path to
>> wrong conclusions.
>
>If the recently-dubbed "high quality" REPRESENTs aren't printing out
>intervals then what are they doing?  Following the leader?

If you give a precise REPRESENT a big-enough buffer, it gives you the
decimal representation of the floating-point value, exactly.

If you give it a buffer that's too short for the exact representation,
you get a rounded result, rounded to the nearest decimal number that
fits in the buffer.

It seems pretty obvious to me that REPRESENT (whether high-quality or
not) does not output an interval.  An interval is indicated by two
numbers, REPRESENT only outputs one.

- 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: FCONSTANT specification
#86
Author: 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


Re: FCONSTANT specification
#87
Author: dxf
Date: Fri, 16 Oct 2026 01:22
29 lines
2257 bytes
On 15/10/2026 4:55 pm, Anton Ertl wrote:
> dxf <dxforth@gmail.com> writes:
>> On 14/10/2026 7:25 pm, Anton Ertl wrote:
>>> What is an "imprecise number"?  In any case, every FP number has a
>>> precise value.  It may not be the value you are interested in, but
>>> that does not make the value any less precise.  And thinking about FP
>>> numbers as "imprecise" or intervals etc. leads you down the path to
>>> wrong conclusions.
>>
>> If the recently-dubbed "high quality" REPRESENTs aren't printing out
>> intervals then what are they doing?  Following the leader?
> 
> If you give a precise REPRESENT a big-enough buffer, it gives you the
> decimal representation of the floating-point value, exactly.

It gives a decimal representation of the nearest storage slot that the
floating-point value was assigned.  That floating-point value never had
more than 17 useful digits.

The question then becomes why?  Why deliberately misrepresent users?
I'd have to fall on my head.

> ...
> It seems pretty obvious to me that REPRESENT (whether high-quality or
> not) does not output an interval.  An interval is indicated by two
> numbers, REPRESENT only outputs one.

Print two and the interval becomes obvious.
Re: FCONSTANT specification
#88
Author: Krishna Myneni
Date: Fri, 16 Oct 2026 03:58
93 lines
5008 bytes
On 10/14/26 8:40 PM, dxf wrote:
> On 14/10/2026 7:25 pm, Anton Ertl wrote:
>> albert@spenarnc.xs4all.nl writes:
>>> The illusion that you can do something precise with imprecise numbers ...
>>
>> What is an "imprecise number"?  In any case, every FP number has a
>> precise value.  It may not be the value you are interested in, but
>> that does not make the value any less precise.  And thinking about FP
>> numbers as "imprecise" or intervals etc. leads you down the path to
>> wrong conclusions.
> 
> If the recently-dubbed "high quality" REPRESENTs aren't printing out
> intervals then what are they doing?  Following the leader?
> 

Let's attempt to give a more precise meaning to what is meant by a "high 
quality" REPRESENT using the IEEE 754 standard as a guide. There are 
several possibilities. First, some definitions from the IEEE 754 
standard, and then some possible meanings when we say "high quality".

I. Definitions:

P_min = minimum of number of decimal digits needed, with round to 
nearest, for conversion from internal normalized binary representation 
to decimal output for the significand, which, when converted back to 
binary form gives the same binary significand:

P_min( p ) = 1 + ceiling(p*log_10(2)); p is the number of significant 
bits (both actual and implied) of the significand in the binary format.

If a Forth system supports multiple binary formats, define

M = max{P_min(p_i)} where i indexes the binary format

Example: For a Forth system supports both single-precision and 
double-precision IEEE binary formats,

M = max{ P_min(24), P_min(53) } = max{ 9, 17 } = 17

II. Possible meanings of "high quality" REPRESENT

There are 3 sensible choices, in my opinion:

II.1) On a given Forth system, REPRESENT will output, with rounding to 
nearest a minimum of digits, M, given by maximum of P_min for all 
supported binary formats.

For example, if a Forth system supports nothing above binary double 
precision (binary64), it should be capable of providing M = 17 
significant decimal digits, with round to nearest.


II.2) Follow the IEEE 754 standard and specify that the Forth system has 
"an implementation-defined limit on the number of significant digits 
that can be converted with correct rounding to and from supported binary 
formats. That limit, H, shall be such that H ≥ M + 3 and it should be 
that H is unbounded."

Then, the minimum number of significant digits for a system which 
supports nothing higher than binary64, it should provide at least H = 20 
significant digits in any specified rounding mode.

Note that the IEEE 754 standard goes to pains to specify there is no 
upper bound on H, only a lower bound.

II.3) Provide H significant decimal digits to support most *fixed 
length* binary formats currently in use, whether they are internally 
supported by the Forth system or supported via source code. Some fixed 
length binary formats currently in use are:

extended precision (p = 64 bits)
double double precision (p = 106 bits)
quad precision (p = 113 bits)
double extended precision (p = 128 bits)
double quad precision (p = 226 bits)

Then M = 70, and H >= 73 significant digits.


Of the three choices above, II.1 or II.2 is probably what smaller 
systems would choose: M = 17 or H = H_min = 20 significant digits. If 
they want to provide double double precision, then II.2 would be a 
better choice (H = H_min = 36 significant digits).

Systems with less memory constraints should choose II.3.

--
KM




Re: FCONSTANT specification
#89
Author: Anton Ertl
Date: Fri, 16 Oct 2026 05:12
54 lines
3607 bytes
dxf <dxforth@gmail.com> writes:
>On 15/10/2026 4:55 pm, Anton Ertl wrote:
>> dxf <dxforth@gmail.com> writes:
>>> On 14/10/2026 7:25 pm, Anton Ertl wrote:
>>>> What is an "imprecise number"?  In any case, every FP number has a
>>>> precise value.  It may not be the value you are interested in, but
>>>> that does not make the value any less precise.  And thinking about FP
>>>> numbers as "imprecise" or intervals etc. leads you down the path to
>>>> wrong conclusions.
>>>
>>> If the recently-dubbed "high quality" REPRESENTs aren't printing out
>>> intervals then what are they doing?  Following the leader?
>> 
>> If you give a precise REPRESENT a big-enough buffer, it gives you the
>> decimal representation of the floating-point value, exactly.
>
>It gives a decimal representation of the nearest storage slot that the
>floating-point value was assigned.

Storage slot?  Are your postings AI slop?

Anyway, every binary FP number can be represented exactly as decimal
number, but some FP numbers need a large number of digits in decimal
representation.  Gforth's E.EXACT outputs this decimal representation,
when based on an appropriate ecvt_r() (such as that in glibc 2.36).

>That floating-point value never had
>more than 17 useful digits.

How many digits are useful depends on the use.  In particular, if you
want to know the exact decimal representation of an FP value, often
more than 17 digits are necessary, and therefore, for this use,
useful.

>The question then becomes why?  Why deliberately misrepresent users?
>I'd have to fall on my head.

More AI slop?

>> It seems pretty obvious to me that REPRESENT (whether high-quality or
>> not) does not output an interval.  An interval is indicated by two
>> numbers, REPRESENT only outputs one.
>
>Print two and the interval becomes obvious.

REPRESENT does not print two.  And if you invoke REPRESENT twice with
the same parameters, you will get the same results.

- 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: FCONSTANT specification
#90
Author: Anton Ertl
Date: Fri, 16 Oct 2026 05:39
16 lines
2023 bytes
Krishna Myneni <krishna.myneni@ccreweb.org> writes:
>II. Possible meanings of "high quality" REPRESENT

Another meaning is that it produces as many digits as asked for (and
to use the correct rounding in cases where the asked-for digits are
insufficient to represent the number exactly).

This is what Gforth's REPRESENT provides when it is based on ecvt_r()
in glibc 2.36 (and probably newer, and probably some older glibcs).

- 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: FCONSTANT specification
#91
Author: marcel hendrix
Date: Fri, 16 Oct 2026 08:56
15 lines
1903 bytes
On 10/16/2026 5:58 AM, Krishna Myneni wrote:

[..]

> extended precision (p = 64 bits)
> double double precision (p = 106 bits)
> quad precision (p = 113 bits)
> double extended precision (p = 128 bits)
> double quad precision (p = 226 bits)

I think double quad extended precision (p = 256 bits) is technically 
possible. Probably not a wise choice for the next decade, but some 
people may decide to go for it.

-marcel
Re: FCONSTANT specification
#92
Author: albert
Date: Fri, 16 Oct 2026 09:55
33 lines
2424 bytes
In article <2026Oct15.075508@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>dxf <dxforth@gmail.com> writes:
>>On 14/10/2026 7:25 pm, Anton Ertl wrote:
>>> What is an "imprecise number"?  In any case, every FP number has a
>>> precise value.  It may not be the value you are interested in, but
>>> that does not make the value any less precise.  And thinking about FP
>>> numbers as "imprecise" or intervals etc. leads you down the path to
>>> wrong conclusions.
>>
>>If the recently-dubbed "high quality" REPRESENTs aren't printing out
>>intervals then what are they doing?  Following the leader?
>
>If you give a precise REPRESENT a big-enough buffer, it gives you the
>decimal representation of the floating-point value, exactly.
>
>If you give it a buffer that's too short for the exact representation,
>you get a rounded result, rounded to the nearest decimal number that
>fits in the buffer.
>
>It seems pretty obvious to me that REPRESENT (whether high-quality or
>not) does not output an interval.  An interval is indicated by two
>numbers, REPRESENT only outputs one.

A fp number represents a rational range, it nominal value plus or minus
half an ulp.

>
>- anton
-- 
The Chinese government is satisfied with its military superiority over USA.
The next 5 year plan has as primary goal to advance life expectancy
over 80 years, like Western Europe.
Re: FCONSTANT specification
#93
Author: Krishna Myneni
Date: Fri, 16 Oct 2026 12:03
17 lines
2112 bytes
On 10/16/26 12:39 AM, Anton Ertl wrote:
> Krishna Myneni <krishna.myneni@ccreweb.org> writes:
>> II. Possible meanings of "high quality" REPRESENT
> 
> Another meaning is that it produces as many digits as asked for (and
> to use the correct rounding in cases where the asked-for digits are
> insufficient to represent the number exactly).
> 
> This is what Gforth's REPRESENT provides when it is based on ecvt_r()
> in glibc 2.36 (and probably newer, and probably some older glibcs).
> 

That case is implied by II.3, H >= 73 digits, where H is unbounded.

--
KM
Re: FCONSTANT specification
#94
Author: marcel hendrix
Date: Fri, 16 Oct 2026 15:36
21 lines
2174 bytes
On 10/16/2026 5:58 AM, Krishna Myneni wrote:

 > extended precision (p = 64 bits)
 > double double precision (p = 106 bits)
 > quad precision (p = 113 bits)
 > double extended precision (p = 128 bits)
 > double quad precision (p = 226 bits)
 >
 > Then M = 70, and H >= 73 significant digits.

Which implies H >= 83 for quad double extended precision,
meaning the available QD* in that library is not sufficient.
Although only QDNEGATE , qd=10 QD* , qd=10 QD/ , and QDF+ are needed, 
one can't get by with a bit shift routine and a simple QQDF+, as +/-INF, 
NAN and subnormals must be handled.

Or give up in disgust and link to an external library.

Either that or go for II.2.

-marcel
Re: FCONSTANT specification
#95
Author: Anton Ertl
Date: Fri, 16 Oct 2026 15:40
53 lines
3124 bytes
albert@spenarnc.xs4all.nl writes:
>A fp number represents a rational range, it nominal value plus or minus
>half an ulp.

What makes you think that the result of

3 s>f

or

s" 3e" >float drop

represents a range?  This value can be represented exactly as FP
value, there is no rounding happening in this conversion.

And why should it represent the range

2.9999999999999997779553950749686919152736663818359375e to
3.0000000000000002220446049250313080847263336181640625e

in particular?

Further, when we perform

6 s>f 3 s>f f-

why should the results of the individual conversions (none of which
performs rounding) represent ranges?  Why should the result of the
subtraction (which does not perform any rounding, either, and does not
set the "inexact" flag in the FPU) represent a range.

But even if we assume that the results of the conversions are ranges,
why should the result of the subtraction be the interval above,
instead of the interval that interval arithmetic would give, which is
a range that is 3 times bigger in this case (2 times, because the
interval you claim for 6 is twice as big as that for 3, and 1 time due
to the interval of 3).

As mentioned, thinking about FP numbers as "imprecise" or intervals
etc. leads you down the path to wrong conclusions.

A better way to think about them is: Each FP number has an exact
value, but in some cases conversions to FP and FP operations round,
because there is no FP value for the exact result; this rounding leads
to errors.  The size of this error is the subject of numerical
analysis.

- 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: FCONSTANT specification
#96
Author: Krishna Myneni
Date: Fri, 16 Oct 2026 16:02
44 lines
3225 bytes
On 10/16/26 10:36, marcel hendrix wrote:
> On 10/16/2026 5:58 AM, Krishna Myneni wrote:
> 
>  > extended precision (p = 64 bits)
>  > double double precision (p = 106 bits)
>  > quad precision (p = 113 bits)
>  > double extended precision (p = 128 bits)
>  > double quad precision (p = 226 bits)
>  >
>  > Then M = 70, and H >= 73 significant digits.
> 
> Which implies H >= 83 for quad double extended precision,
> meaning the available QD* in that library is not sufficient.
> Although only QDNEGATE , qd=10 QD* , qd=10 QD/ , and QDF+ are needed, 
> one can't get by with a bit shift routine and a simple QQDF+, as +/-INF, 
> NAN and subnormals must be handled.
> 
> Or give up in disgust and link to an external library.
> 
> Either that or go for II.2.
> 
> -marcel


Yes, I expect QD* which I assume is quad double mulitply is probably not 
sufficient to handle quad extended requirements. One point I forgot to 
mention is that the Forth standard for REPRESENT requires rounding to 
nearest, in which case H_min = M (not M+3). There's no way I can see to 
avoid using big number arithmetic for the quad extended precision case.

It's not hopeless. We have big number arithmetic library code in Forth 
with which to learn how to deal with just about any case. The learning 
curve is there, of course.

To handle +/-INF and NAN, isn't it sufficient to examine the bit pattern 
for the leading extended precision number in the quad extended precision 
set i.e. no arithmetic should be needed to handle +/-INF and NAN? I'm 
not sure if subnormals will be more difficult to handle than normal 
numbers -- their precision is always less than or equal to normal numbers.

--
KM

Re: FCONSTANT specification
#97
Author: marcel hendrix
Date: Fri, 16 Oct 2026 19:55
56 lines
4172 bytes
On 10/16/2026 6:02 PM, Krishna Myneni wrote:
> On 10/16/26 10:36, marcel hendrix wrote:
>> On 10/16/2026 5:58 AM, Krishna Myneni wrote:
>>
>>  > extended precision (p = 64 bits)
>>  > double double precision (p = 106 bits)
>>  > quad precision (p = 113 bits)
>>  > double extended precision (p = 128 bits)
>>  > double quad precision (p = 226 bits)
>>  >
>>  > Then M = 70, and H >= 73 significant digits.
>>
>> Which implies H >= 83 for quad double extended precision,
>> meaning the available QD* in that library is not sufficient.
>> Although only QDNEGATE , qd=10 QD* , qd=10 QD/ , and QDF+ are needed, 
>> one can't get by with a bit shift routine and a simple QQDF+, as +/- 
>> INF, NAN and subnormals must be handled.
>>
>> Or give up in disgust and link to an external library.
>>
>> Either that or go for II.2.
>>
>> -marcel
> 
> 
> Yes, I expect QD* which I assume is quad double mulitply is probably not 
> sufficient to handle quad extended requirements. One point I forgot to 
> mention is that the Forth standard for REPRESENT requires rounding to 
> nearest, in which case H_min = M (not M+3). There's no way I can see to 
> avoid using big number arithmetic for the quad extended precision case.

An iForth QD library will have a quad double extended multiply QD* for 
256 bits. Then -256e F2^x gives 8.6e-78 ~> 77 usable decimals.
Your `2e FLOG 256e F* FCEIL F1+` formula (even rounding) gives M = 79, 
and unfortunately, QD* does not suffice.

> It's not hopeless. We have big number arithmetic library code in Forth 
> with which to learn how to deal with just about any case. The learning 
> curve is there, of course.

I don't know there is a Forth-based arbitrary *float* implementation, 
but the MPFR was ported back in 2012. I am looking at it just now. The 
Windows port suffered from a very immature MinGW64 and would need to be 
revisited.
But why want QD, QX or QD when the mpfr gives arbitrary precision on its 
own? The charm of QD is that is very small and simple, while MPFR is a 
beast. It could be that it is much faster than QD/QX and QD though. 
Maybe some tests could be done first.
> To handle +/-INF and NAN, isn't it sufficient to examine the bit pattern 
> for the leading extended precision number in the quad extended precision 
> set i.e. no arithmetic should be needed to handle +/-INF and NAN? I'm 
> not sure if subnormals will be more difficult to handle than normal 
> numbers -- their precision is always less than or equal to normal numbers.
I hope that is true, I don't particularly enjoy looking into the MPFR again.

-marcel
Re: FCONSTANT specification
#98
Author: Krishna Myneni
Date: Fri, 16 Oct 2026 20:44
77 lines
5043 bytes
On 10/16/26 2:55 PM, marcel hendrix wrote:
> On 10/16/2026 6:02 PM, Krishna Myneni wrote:
>> On 10/16/26 10:36, marcel hendrix wrote:
>>> On 10/16/2026 5:58 AM, Krishna Myneni wrote:
>>>
>>>  > extended precision (p = 64 bits)
>>>  > double double precision (p = 106 bits)
>>>  > quad precision (p = 113 bits)
>>>  > double extended precision (p = 128 bits)
>>>  > double quad precision (p = 226 bits)
>>>  >
>>>  > Then M = 70, and H >= 73 significant digits.
>>>
>>> Which implies H >= 83 for quad double extended precision,
>>> meaning the available QD* in that library is not sufficient.
>>> Although only QDNEGATE , qd=10 QD* , qd=10 QD/ , and QDF+ are needed, 
>>> one can't get by with a bit shift routine and a simple QQDF+, as +/- 
>>> INF, NAN and subnormals must be handled.
>>>
>>> Or give up in disgust and link to an external library.
>>>
>>> Either that or go for II.2.
>>>
>>> -marcel
>>
>>
>> Yes, I expect QD* which I assume is quad double mulitply is probably 
>> not sufficient to handle quad extended requirements. One point I 
>> forgot to mention is that the Forth standard for REPRESENT requires 
>> rounding to nearest, in which case H_min = M (not M+3). There's no way 
>> I can see to avoid using big number arithmetic for the quad extended 
>> precision case.
> 
> An iForth QD library will have a quad double extended multiply QD* for 
> 256 bits. Then -256e F2^x gives 8.6e-78 ~> 77 usable decimals.
> Your `2e FLOG 256e F* FCEIL F1+` formula (even rounding) gives M = 79, 
> and unfortunately, QD* does not suffice.
> 
>> It's not hopeless. We have big number arithmetic library code in Forth 
>> with which to learn how to deal with just about any case. The learning 
>> curve is there, of course.
> 
> I don't know there is a Forth-based arbitrary *float* implementation, 
> but the MPFR was ported back in 2012. I am looking at it just now. The 
> Windows port suffered from a very immature MinGW64 and would need to be 
> revisited.
> But why want QD, QX or QD when the mpfr gives arbitrary precision on its 
> own? The charm of QD is that is very small and simple, while MPFR is a 
> beast. It could be that it is much faster than QD/QX and QD though. 
> Maybe some tests could be done first.
>> To handle +/-INF and NAN, isn't it sufficient to examine the bit 
>> pattern for the leading extended precision number in the quad extended 
>> precision set i.e. no arithmetic should be needed to handle +/-INF and 
>> NAN? I'm not sure if subnormals will be more difficult to handle than 
>> normal numbers -- their precision is always less than or equal to 
>> normal numbers.
> I hope that is true, I don't particularly enjoy looking into the MPFR 
> again.
> 

The use of MPFR seems like overkill, since we can just do all higher 
precision (any value of p) floating point calculations using the library.

I had been working on writing REPRESENT using the FSL big.4th library, 
with my own extensions for necessary functions which were not in the 
original. I hope to get back to that after sorting out my own needs for 
floating point output formats. If we have working Forth implementations 
of REPRESENT for various values of p, it provides a reference for 
efficient implementation.

The reason dtoa() is so complex is that it was designed to demonstrate 
high efficiency compared to just simply doing big number arithmetic for 
all cases.

--
Krishna
Re: FCONSTANT specification
#99
Author: dxf
Date: Sat, 17 Oct 2026 02:37
49 lines
3060 bytes
On 16/10/2026 4:12 pm, Anton Ertl wrote:
> dxf <dxforth@gmail.com> writes:
>> On 15/10/2026 4:55 pm, Anton Ertl wrote:
>>> dxf <dxforth@gmail.com> writes:
>>>> On 14/10/2026 7:25 pm, Anton Ertl wrote:
>>>>> What is an "imprecise number"?  In any case, every FP number has a
>>>>> precise value.  It may not be the value you are interested in, but
>>>>> that does not make the value any less precise.  And thinking about FP
>>>>> numbers as "imprecise" or intervals etc. leads you down the path to
>>>>> wrong conclusions.
>>>>
>>>> If the recently-dubbed "high quality" REPRESENTs aren't printing out
>>>> intervals then what are they doing?  Following the leader?
>>>
>>> If you give a precise REPRESENT a big-enough buffer, it gives you the
>>> decimal representation of the floating-point value, exactly.
>>
>> It gives a decimal representation of the nearest storage slot that the
>> floating-point value was assigned.
> 
> Storage slot?  Are your postings AI slop?

Did you have a problem understanding it?  I've never used AI.
 
> Anyway, every binary FP number can be represented exactly as decimal
> number, but some FP numbers need a large number of digits in decimal
> representation.  Gforth's E.EXACT outputs this decimal representation,
> when based on an appropriate ecvt_r() (such as that in glibc 2.36).
> 
>> That floating-point value never had
>> more than 17 useful digits.
> 
> How many digits are useful depends on the use.  In particular, if you
> want to know the exact decimal representation of an FP value, often
> more than 17 digits are necessary, and therefore, for this use,
> useful.

There's 'uses' but you can't give any.

>> The question then becomes why?  Why deliberately misrepresent users?
>> I'd have to fall on my head.
> 
> More AI slop?

Somebody sold GCC 'The Emperor's New Clothes' and now it is showing off
its apparel.  Sorry, but all I see is vanity laid bare.

> ...
Re: FCONSTANT specification
#101
Author: Krishna Myneni
Date: Sat, 17 Oct 2026 04:37
49 lines
3661 bytes
On 10/16/26 9:37 PM, dxf wrote:
> On 16/10/2026 4:12 pm, Anton Ertl wrote:
>> dxf <dxforth@gmail.com> writes:
>>> On 15/10/2026 4:55 pm, Anton Ertl wrote:
>>>> dxf <dxforth@gmail.com> writes:
>>>>> On 14/10/2026 7:25 pm, Anton Ertl wrote:
>>>>>> What is an "imprecise number"?  In any case, every FP number has a
>>>>>> precise value.  It may not be the value you are interested in, but
>>>>>> that does not make the value any less precise.  And thinking about FP
>>>>>> numbers as "imprecise" or intervals etc. leads you down the path to
>>>>>> wrong conclusions.
>>>>>
>>>>> If the recently-dubbed "high quality" REPRESENTs aren't printing out
>>>>> intervals then what are they doing?  Following the leader?
>>>>
>>>> If you give a precise REPRESENT a big-enough buffer, it gives you the
>>>> decimal representation of the floating-point value, exactly.
>>>
>>> It gives a decimal representation of the nearest storage slot that the
>>> floating-point value was assigned.
>>
>> Storage slot?  Are your postings AI slop?
> 
> Did you have a problem understanding it?  I've never used AI.
>   
>> Anyway, every binary FP number can be represented exactly as decimal
>> number, but some FP numbers need a large number of digits in decimal
>> representation.  Gforth's E.EXACT outputs this decimal representation,
>> when based on an appropriate ecvt_r() (such as that in glibc 2.36).
>>
>>> That floating-point value never had
>>> more than 17 useful digits.
>>
>> How many digits are useful depends on the use.  In particular, if you
>> want to know the exact decimal representation of an FP value, often
>> more than 17 digits are necessary, and therefore, for this use,
>> useful.
> 
> There's 'uses' but you can't give any.
> 

Yes, you are clearly smarter than the entire IEEE 754 standards 
committee, which specified that a system should leave the number of 
digits requested in a binary to decimal conversion to be unbounded.

One use case clearly shows up in this thread with Marcel's 
implementation of xdfloats.

Re: FCONSTANT specification
#102
Author: dxf
Date: Sat, 17 Oct 2026 05:45
68 lines
5013 bytes
On 16/10/2026 2:58 pm, Krishna Myneni wrote:
> On 10/14/26 8:40 PM, dxf wrote:
>> On 14/10/2026 7:25 pm, Anton Ertl wrote:
>>> albert@spenarnc.xs4all.nl writes:
>>>> The illusion that you can do something precise with imprecise numbers ...
>>>
>>> What is an "imprecise number"?  In any case, every FP number has a
>>> precise value.  It may not be the value you are interested in, but
>>> that does not make the value any less precise.  And thinking about FP
>>> numbers as "imprecise" or intervals etc. leads you down the path to
>>> wrong conclusions.
>>
>> If the recently-dubbed "high quality" REPRESENTs aren't printing out
>> intervals then what are they doing?  Following the leader?
>>
> 
> Let's attempt to give a more precise meaning to what is meant by a "high quality" REPRESENT using the IEEE 754 standard as a guide. There are several possibilities. First, some definitions from the IEEE 754 standard, and then some possible meanings when we say "high quality".
> 
> I. Definitions:
> 
> P_min = minimum of number of decimal digits needed, with round to nearest, for conversion from internal normalized binary representation to decimal output for the significand, which, when converted back to binary form gives the same binary significand:
> 
> P_min( p ) = 1 + ceiling(p*log_10(2)); p is the number of significant bits (both actual and implied) of the significand in the binary format.
> 
> If a Forth system supports multiple binary formats, define
> 
> M = max{P_min(p_i)} where i indexes the binary format
> 
> Example: For a Forth system supports both single-precision and double-precision IEEE binary formats,
> 
> M = max{ P_min(24), P_min(53) } = max{ 9, 17 } = 17
> 
> II. Possible meanings of "high quality" REPRESENT
> 
> There are 3 sensible choices, in my opinion:
> 
> II.1) On a given Forth system, REPRESENT will output, with rounding to nearest a minimum of digits, M, given by maximum of P_min for all supported binary formats.
> 
> For example, if a Forth system supports nothing above binary double precision (binary64), it should be capable of providing M = 17 significant decimal digits, with round to nearest.
> 
> 
> II.2) Follow the IEEE 754 standard and specify that the Forth system has "an implementation-defined limit on the number of significant digits that can be converted with correct rounding to and from supported binary formats. That limit, H, shall be such that H ≥ M + 3 and it should be that H is unbounded."
> 
> Then, the minimum number of significant digits for a system which supports nothing higher than binary64, it should provide at least H = 20 significant digits in any specified rounding mode.
> 
> Note that the IEEE 754 standard goes to pains to specify there is no upper bound on H, only a lower bound.
> 
> II.3) Provide H significant decimal digits to support most *fixed length* binary formats currently in use, whether they are internally supported by the Forth system or supported via source code. Some fixed length binary formats currently in use are:
> 
> extended precision (p = 64 bits)
> double double precision (p = 106 bits)
> quad precision (p = 113 bits)
> double extended precision (p = 128 bits)
> double quad precision (p = 226 bits)
> 
> Then M = 70, and H >= 73 significant digits.
> 
> 
> Of the three choices above, II.1 or II.2 is probably what smaller systems would choose: M = 17 or H = H_min = 20 significant digits. If they want to provide double double precision, then II.2 would be a better choice (H = H_min = 36 significant digits).
> 
> Systems with less memory constraints should choose II.3.

When Intel developed the 8087 it was with IEEE double-precision in mind.
There's little doubt its the reason they chose an internal representation
of 80 bits to handle at least some of IEEE's arithmetic and conversion
requirements.  For me - and perhaps other x87 users - the REPRESENT I can
build using basic x87 instructions is "high quality" enough.
Re: FCONSTANT specification
#104
Author: dxf
Date: Sat, 17 Oct 2026 09:11
55 lines
3603 bytes
On 17/10/2026 3:37 pm, Krishna Myneni wrote:
> On 10/16/26 9:37 PM, dxf wrote:
>> On 16/10/2026 4:12 pm, Anton Ertl wrote:
>>> dxf <dxforth@gmail.com> writes:
>>>> On 15/10/2026 4:55 pm, Anton Ertl wrote:
>>>>> dxf <dxforth@gmail.com> writes:
>>>>>> On 14/10/2026 7:25 pm, Anton Ertl wrote:
>>>>>>> What is an "imprecise number"?  In any case, every FP number has a
>>>>>>> precise value.  It may not be the value you are interested in, but
>>>>>>> that does not make the value any less precise.  And thinking about FP
>>>>>>> numbers as "imprecise" or intervals etc. leads you down the path to
>>>>>>> wrong conclusions.
>>>>>>
>>>>>> If the recently-dubbed "high quality" REPRESENTs aren't printing out
>>>>>> intervals then what are they doing?  Following the leader?
>>>>>
>>>>> If you give a precise REPRESENT a big-enough buffer, it gives you the
>>>>> decimal representation of the floating-point value, exactly.
>>>>
>>>> It gives a decimal representation of the nearest storage slot that the
>>>> floating-point value was assigned.
>>>
>>> Storage slot?  Are your postings AI slop?
>>
>> Did you have a problem understanding it?  I've never used AI.
>>  
>>> Anyway, every binary FP number can be represented exactly as decimal
>>> number, but some FP numbers need a large number of digits in decimal
>>> representation.  Gforth's E.EXACT outputs this decimal representation,
>>> when based on an appropriate ecvt_r() (such as that in glibc 2.36).
>>>
>>>> That floating-point value never had
>>>> more than 17 useful digits.
>>>
>>> How many digits are useful depends on the use.  In particular, if you
>>> want to know the exact decimal representation of an FP value, often
>>> more than 17 digits are necessary, and therefore, for this use,
>>> useful.
>>
>> There's 'uses' but you can't give any.
>>
> 
> Yes, you are clearly smarter than the entire IEEE 754 standards committee,

I wouldn't know about that but I can think for myself.  I see no reason to
delegate my thinking to another.  It doesn't matter how 'smart' they are.
But if that's what I think and I follow, I become a second-hand person,
dependent upon another.

> which specified that a system should leave the number of digits requested in a binary to decimal conversion to be unbounded.
> 
> One use case clearly shows up in this thread with Marcel's implementation of xdfloats.

Can't make head or tail of that.
Re: FCONSTANT specification
#107
Author: albert
Date: Sat, 17 Oct 2026 10:55
60 lines
2995 bytes
In article <2026Oct16.174024@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>albert@spenarnc.xs4all.nl writes:
>>A fp number represents a rational range, it nominal value plus or minus
>>half an ulp.
>
>What makes you think that the result of
>
>3 s>f
>
>or
>
>s" 3e" >float drop
>
>represents a range?  This value can be represented exactly as FP
>value, there is no rounding happening in this conversion.
>
>And why should it represent the range
>
>2.9999999999999997779553950749686919152736663818359375e to
>3.0000000000000002220446049250313080847263336181640625e
>
>in particular?
>
>Further, when we perform
>
>6 s>f 3 s>f f-
>
>why should the results of the individual conversions (none of which
>performs rounding) represent ranges?  Why should the result of the
>subtraction (which does not perform any rounding, either, and does not
>set the "inexact" flag in the FPU) represent a range.
>
>But even if we assume that the results of the conversions are ranges,
>why should the result of the subtraction be the interval above,
>instead of the interval that interval arithmetic would give, which is
>a range that is 3 times bigger in this case (2 times, because the
>interval you claim for 6 is twice as big as that for 3, and 1 time due
>to the interval of 3).
>
>As mentioned, thinking about FP numbers as "imprecise" or intervals
>etc. leads you down the path to wrong conclusions.
>
>A better way to think about them is: Each FP number has an exact
>value, but in some cases conversions to FP and FP operations round,
>because there is no FP value for the exact result; this rounding leads
>to errors.  The size of this error is the subject of numerical
>analysis.

Exactly
0.0001E0 DUP FSIN F-
looses a whole lot of precision.
Maybe "imprecise numbers" is not a bad name after all.
I aim for psychological impact.

>- anton
-- 
The Chinese government is satisfied with its military superiority over USA.
The next 5 year plan has as primary goal to advance life expectancy
over 80 years, like Western Europe.
Re: FCONSTANT specification
#108
Author: Krishna Myneni
Date: Sat, 17 Oct 2026 12:44
16 lines
2101 bytes
On 10/17/26 4:11 AM, dxf wrote:
> On 17/10/2026 3:37 pm, Krishna Myneni wrote:
...
>>
>> One use case clearly shows up in this thread with Marcel's implementation of xdfloats.
> 
> Can't make head or tail of that.
> 

Taking the position that anything you don't understand at first glance, 
without effort, works for you, ok. But it may not be an indication that 
there is a conspiracy of mathematicians and computer scientists.

--
KM
Re: FCONSTANT specification
#113
Author: marcel hendrix
Date: Sat, 17 Oct 2026 15:36
31 lines
2537 bytes
On 10/17/2026 12:55 PM, albert@spenarnc.xs4all.nl wrote:
> In article <2026Oct16.174024@mips.complang.tuwien.ac.at>,
> Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>> albert@spenarnc.xs4all.nl writes:

> Exactly
> 0.0001E0 DUP FSIN F-
> looses a whole lot of precision.
> Maybe "imprecise numbers" is not a bad name after all.
> I aim for psychological impact.
I think you meant (done with xopg, mpfr, mpc):

FORTH> LET sin(0.0001e):
.print      9.9999999833333333416666666646825396828152e-0005 ok
FORTH> S" 0.0001e" >XD XDSIN
XDFE.       9.99999998333333334166666666468253968286e-5  ok
FORTH> 0.0001e FSIN
        +e.  9.9999999833333333426e-0005 ok
FORTH> LET sin(0.1001e):
.print      9.9932916564023038037792141684528699818587e-0002 ok
FORTH> S" 0.1001e" >XD XDSIN
XDFE.       9.99329165640230380377921416845286998177e-2  ok
FORTH> 0.1001e FSIN
        +e.  9.9932916564023038040e-0002 ok

... although this is most probably due to improper range reduction.

The target (non-AI) audience knows what they are doing, so why not
give them the best possible tools?

-marcel
Re: FCONSTANT specification
#118
Author: albert
Date: Sat, 17 Oct 2026 17:32
44 lines
2657 bytes
In article <11b04lt$1vpog$1@dont-email.me>, marcel hendrix  <mhx@iae.nl> wrote:
>On 10/17/2026 12:55 PM, albert@spenarnc.xs4all.nl wrote:
>> In article <2026Oct16.174024@mips.complang.tuwien.ac.at>,
>> Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>> albert@spenarnc.xs4all.nl writes:
>
>> Exactly
>> 0.0001E0 DUP FSIN F-
>> looses a whole lot of precision.
>> Maybe "imprecise numbers" is not a bad name after all.
>> I aim for psychological impact.
>I think you meant (done with xopg, mpfr, mpc):
>
>FORTH> LET sin(0.0001e):
>.print      9.9999999833333333416666666646825396828152e-0005 ok
>FORTH> S" 0.0001e" >XD XDSIN
>XDFE.       9.99999998333333334166666666468253968286e-5  ok
>FORTH> 0.0001e FSIN
>        +e.  9.9999999833333333426e-0005 ok
>FORTH> LET sin(0.1001e):
>.print      9.9932916564023038037792141684528699818587e-0002 ok
>FORTH> S" 0.1001e" >XD XDSIN
>XDFE.       9.99329165640230380377921416845286998177e-2  ok
>FORTH> 0.1001e FSIN
>        +e.  9.9932916564023038040e-0002 ok
>
>... although this is most probably due to improper range reduction.

Seriously? This is abc of computer science. You loose precision if
you subtract numbers of equal size that cannot be exactly represented
in your system.
>
>The target (non-AI) audience knows what they are doing, so why not
>give them the best possible tools?

I gave them the best possible impression. Be aware that these numbers
are imprecise.

>
>-marcel
-- 
The Chinese government is satisfied with its military superiority over USA.
The next 5 year plan has as primary goal to advance life expectancy
over 80 years, like Western Europe.
Re: FCONSTANT specification
#119
Author: marcel hendrix
Date: Sat, 17 Oct 2026 17:44
34 lines
2617 bytes
On 10/16/2026 9:55 PM, marcel hendrix wrote:
[..]

> But why want QD, QX or QD when the mpfr gives arbitrary precision on its 
> own? The charm of QD is that is very small and simple, while MPFR is a 
> beast. It could be that it is much faster than QD/QX and QD though. 
> Maybe some tests could be done first.
As MPFR and MPC again work in iForth (inside XOPG), I did the testing.

LET sin(PI/16): GVAL x

#100000 value #iters
: TEST1  CR TIMER-RESET  #iters 0 ?do  LET sin(x):            LOOP 
.ELAPSED ;

: TEST2  CR TIMER-RESET  #iters 0 ?do  xd=pi/16 xdsin xddrop  LOOP 
.ELAPSED ;

: BENCH #100000 TO #iters
	TEST1
	TEST2 ;

FORTH> BENCH
0.826 seconds elapsed.
0.095 seconds elapsed. ok

The mpfr library is about 8 times faster than the XD-FP Forth library 
based on the ideas of Julian V. Noble, Seppo Linnainmaa, and David H. 
Bailey. As my mpfr .so is from 2012, I guess it will be even more 
dramatic with a modern binary. Still, a few xd-fp words might find a
permanent place in the iForth kernel.

-marcel
Re: FCONSTANT specification
#120
Author: Anton Ertl
Date: Sun, 18 Oct 2026 06:15
33 lines
2657 bytes
albert@spenarnc.xs4all.nl writes:
>In article <2026Oct16.174024@mips.complang.tuwien.ac.at>,
>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>A better way to think about them is: Each FP number has an exact
>>value, but in some cases conversions to FP and FP operations round,
>>because there is no FP value for the exact result; this rounding leads
>>to errors.  The size of this error is the subject of numerical
>>analysis.
>
>Exactly
>0.0001E0 DUP FSIN F-

I assume you mean FDUP here.

>looses a whole lot of precision.
>Maybe "imprecise numbers" is not a bad name after all.

It is.  It's not the numbers that are imprecise, it's the operations.
They round (but not in every case).

In the present case the conversion from the decimal string to the FP
number rounds (but that makes little difference for what follows), and
FSIN rounds.  F- does not round in this case, but the absolute error
from the FSIN rounding is still present in the result and is
relatively larger compared to the result, so the number of significant
digits is smaller; this phenomenon is called cancellation.

- 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: FCONSTANT specification
#121
Author: Anton Ertl
Date: Sun, 18 Oct 2026 09:40
58 lines
4292 bytes
dxf <dxforth@gmail.com> writes:
>When Intel developed the 8087 it was with IEEE double-precision in mind.
>There's little doubt its the reason they chose an internal representation
>of 80 bits to handle at least some of IEEE's arithmetic and conversion
>requirements.

Citation needed.  Several things make this very unlikely:


*) The recounts of the development of the 8087 and IEEE 754 I have
   read do not provide support for such claims.  On the contrary, the
   idea behind the 8087 is reported to be "the best", and everything I
   read from Kahan about 80-bit formats is along the lines of them
   being being better than IEEE 754 DP format, and he deplores that
   they are not more widely available.  E.g.: "But the Macintosh based
   on the 68000 gave way to the PowerPC, whose arithmetic is
   inferior." [1]

   [1] 8087: http://web.archive.org/web/20190301193516/http://www.drdobbs.com/architecture-and-design/a-conversation-with-william-kahan/184410314

   BTW, this article was written by Jack Woehr, the author of JaxForth
   and Forth: The New Model.

   [2] IEEE 754: https://people.eecs.berkeley.edu/~wkahan/ieee754status/754story.html

*) The 8087 project was started before IEEE 754 and launched in 1980,
   IEEE 754 was released in 1985.  And in particular, it took at least
   until 1981 to decide between K-C-S (what eventually became IEEE
   754) and VAX F/G FP formats [2].

*) The 8087 and none of its successors imlements the IEEE 754
   double-precision operations fully.  Even with the 53-bit mode for
   the mantissa, the longer exponent means that there are cases where
   the result differs from that of binary64.  [That was a sore point
   for Java's write-once-run-anywhere promise until they started to
   rely on SSE2 on AMD64 processors.]

*) The 80-bit format is not just an internal representation.  It's
   exposed to software, and software makes use of it.  By contrast,
   many FPUs tend to have three extra bits that are not exposed to the
   users, and which you only see indirectly.  E.g., SSE2 has
   instructions MOVUPD, MOVUPS, and MOVDQU, which all do the same
   thing (take a look at the "Operation" description), but may differ
   in how they set up the internal representation, so if you follow a
   load performed with MOVUPS by a MULPD working on the loaded
   register, you may see a slowdown compared to using MOVUPD for the
   load, because the extra bits have to be generated first, before
   performing the actual work of the MULPD.

*) Lots of other architectures target IEEE double-precision without
   implementing 80-bit FP, much less providing it to users.

- 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: FCONSTANT specification
#122
Author: Hans Bezemer
Date: Sun, 18 Oct 2026 12:10
42 lines
3686 bytes
On 17-10-2026 06:37, Krishna Myneni wrote:
 > Yes, you are clearly smarter than the entire IEEE 754 standards
 > committee, which specified that a system should leave the number of
 > digits requested in a binary to decimal conversion to be unbounded.

Err. Not quite. IEEE 754-2008 permits an implementation-defined limit H, 
provided it meets the standard's minimum requirements. It recommends 
that H be unbounded, but doesn't make an unbounded limit mandatory for 
binary-format conversions.

Small correction ;-) It's the difference between "shall" and "should". 
In technical specifications, ISO standards, and quality management 
systems, shall and should have distinct, legally binding meanings:

* Shall: Indicates a strict, mandatory requirement with zero deviation 
tolerance. You must comply with it to achieve certification or 
legal/regulatory compliance.

* Should: Indicates a recommendation, guideline, or preferred goal. It 
is not mandatory, and noncompliance is permitted if you have valid 
reasons and weigh the implications.

BTW, AFAIK there isn't a single reference to the IEEE 754-2008 standard 
in even Forth-2012. I quote: "A single- or double-precision 
floating-point number as defined in ANSI/IEEE 754-1985."

Furthermore, the standard states: "12.3.1.2 Floating-point numbers; The 
internal representation of a floating-point number, including the format 
and precision of the significand and the format and range of the 
exponent, is implementation defined. Any rounding or truncation of 
floating-point numbers is implementation defined."

I.e. a floating point number doesn't have to be any IEEE 754 format. 
Under the ANS standard my ZEN and Eckert FP are still considered 
"floating point numbers". (Yes, ZEN is no longer considered to be 
compliant FP format under Forth-2012, I know).

That also means that the requirements of the IEEE 754 committee are moot 
to me (well, honestly so are the requirements of the Forth-2012 
committee to me, but that's another story ;-)

Hans Bezemer
Re: FCONSTANT specification
#123
Author: albert
Date: Sun, 18 Oct 2026 12:47
73 lines
3692 bytes
In article <2026Oct18.081501@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>albert@spenarnc.xs4all.nl writes:
>>In article <2026Oct16.174024@mips.complang.tuwien.ac.at>,
>>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>>A better way to think about them is: Each FP number has an exact
>>>value, but in some cases conversions to FP and FP operations round,
>>>because there is no FP value for the exact result; this rounding leads
>>>to errors.  The size of this error is the subject of numerical
>>>analysis.
>>
>>Exactly
>>0.0001E0 DUP FSIN F-
>
>I assume you mean FDUP here.
Good catch.

>
>>looses a whole lot of precision.
>>Maybe "imprecise numbers" is not a bad name after all.
>
>It is.  It's not the numbers that are imprecise, it's the operations.
>They round (but not in every case).

F- generates the exact result of the number that is supposed
to represent 0.001 (maybe imprecisely)  and the number that
represents sin(0.001) imprecisely. The latter is bound to be imprecise
because sin(0.001) is transcendental, so irrational.

So F- is not to blame that the result is imprecise.
: thou 0.001E0 ; OK
 HEX OK
  thou FS.
  4.189374BC6A7EC00000_-3  OK
  thou FSIN FS.
  4.18936948629841A800_-3  OK
 OK
 thou FSIN thou F- FDUP FS.
 -B.7407E67E5800000000_-9  OK

Now it can be demonstrated by adding the thou back to the result,
that F- doesn't introduce loss of precision.
 thou F+ FDUP FS.
 4.18936948629841A800_-3  OK
 thou FSIN FS.
 4.18936948629841A800_-3  OK

Summary F- is working with precision on imprecise numbers.

>In the present case the conversion from the decimal string to the FP
>number rounds (but that makes little difference for what follows), and
>FSIN rounds.  F- does not round in this case, but the absolute error
>from the FSIN rounding is still present in the result and is
>relatively larger compared to the result, so the number of significant
>digits is smaller; this phenomenon is called cancellation.

FSIN doesn't round. It is not magically bound to the math sine function.
It is defined as an operation that returns a rational number that
is close within x ULP to the mathematical sine function.

More succinctly: the sine function is beholden to be represented
by an imprecise number. All operation results  with imprecise numbers
should be regarded with suspicion.


>
>- anton

Groetjes Albert
-- 
The Chinese government is satisfied with its military superiority over USA.
The next 5 year plan has as primary goal to advance life expectancy
over 80 years, like Western Europe.
Re: FCONSTANT specification
#124
Author: dxf
Date: Sun, 18 Oct 2026 14:52
23 lines
2180 bytes
On 17/10/2026 11:44 pm, Krishna Myneni wrote:
> On 10/17/26 4:11 AM, dxf wrote:
>> On 17/10/2026 3:37 pm, Krishna Myneni wrote:
> ...
>>>
>>> One use case clearly shows up in this thread with Marcel's implementation of xdfloats.
>>
>> Can't make head or tail of that.
>>
> 
> Taking the position that anything you don't understand at first glance, without effort, works for you, ok.

"One use case clearly shows up" - but you can't state what it is and I'm
supposed to glean it from reading a thread?

> But it may not be an indication that there is a conspiracy of mathematicians and computer scientists.

For my part I've clearly shown an alternate REPRESENT results in shorter
application code - shorter than anyone using a 'standard' REPRESENT has
been able to achieve.  As one of the 'mathematicians and computer scientists'
on the Forth committee, what has been your expert response to that?  I can
tell you.  You didn't want to know about it.
Re: FCONSTANT specification
#125
Author: Krishna Myneni
Date: Sun, 18 Oct 2026 15:08
23 lines
2629 bytes
On 10/18/26 7:10 AM, Hans Bezemer wrote:
> On 17-10-2026 06:37, Krishna Myneni wrote:
>  > Yes, you are clearly smarter than the entire IEEE 754 standards
>  > committee, which specified that a system should leave the number of
>  > digits requested in a binary to decimal conversion to be unbounded.
> 
> Err. Not quite. IEEE 754-2008 permits an implementation-defined limit H, 
> provided it meets the standard's minimum requirements. It recommends 
> that H be unbounded, but doesn't make an unbounded limit mandatory for 
> binary-format conversions.
> 
> Small correction ;-) It's the difference between "shall" and "should". 
> In technical specifications, ISO standards, and quality management 
> systems, shall and should have distinct, legally binding meanings:
> 

Yes, I know what "should" means. There is no claim for legal binding, 
and my suggested meanings for "high quality REPRESENT" allow for H to be 
set to a fixed value.

--
KM
Re: FCONSTANT specification
#129
Author: Paul Rubin
Date: Sun, 18 Oct 2026 22:00
5 lines
1530 bytes
albert@spenarnc.xs4all.nl writes:
> Maybe "imprecise numbers" is not a bad name after all.
> I aim for psychological impact.

In math it's preferable to aim for mathematical correctness.
Re: FCONSTANT specification
#130
Author: Paul Rubin
Date: Sun, 18 Oct 2026 22:10
12 lines
2027 bytes
marcel hendrix <mhx@iae.nl> writes:
> Which implies H >= 83 for quad double extended precision,

Extended precision = 80 bit numbers?  So double extended = 160 bits, and
quad double extended = 640 bits?  Do you mean double quad extended which
would be 320 bits?  I think for all of these, anything above 256 bits
and maybe anything above 128 bits, you probably want some MPFR-like
arbitrary precision.

80 bit extended is looking like an x86 artifact by now, maybe.  I wonder
if anything implements 128 bit extended.  There's a spec for it in
RISC-V but no implementations that I know of.
Re: FCONSTANT specification
#132
Author: marcel hendrix
Date: Sun, 18 Oct 2026 22:45
37 lines
3272 bytes
On 10/19/2026 12:10 AM, Paul Rubin wrote:
> marcel hendrix <mhx@iae.nl> writes:
>> Which implies H >= 83 for quad double extended precision,
> 
> Extended precision = 80 bit numbers?  So double extended = 160 bits, and
> quad double extended = 640 bits?  Do you mean double quad extended which
> would be 320 bits?  

No, extended double is an IEEE format that, e.g., matches the Intel 
FPU's 10 byte memory storage and has a mantissa of 64 bits. With 2 * 64 
bits the mantissa of a double extended double becomes 128 bits, and a 
quad extended double will have a 256 bit mantissa. The extended variants 
appear not to exist (or are not very common), I have found no references 
for them yet (outside of the mainframe area). Double extended double is 
now working, but I have not looked at quad extended double yet.

With the old Motorola 96-bit format one could have had 80 and 160 bit 
mantissas, and then quad Motorola double would indeed be 320 bits.

> I think for all of these, anything above 256 bits
> and maybe anything above 128 bits, you probably want some MPFR-like
> arbitrary precision. 

MPFR is definitely much faster.

> 80 bit extended is looking like an x86 artifact by now, maybe.  I wonder
> if anything implements 128 bit extended.  There's a spec for it in
> RISC-V but no implementations that I know of.

Given that the MPFR is 8 times faster than (my) double extended double, 
an FPU with > 80 bits probably can't compete on speed, although it might 
save memory. The MPFR is much too large if you only need a few functions
for large decimal input and output strings. The xd-fp library, with a 
full set of math functions, is only 800 lines of Forth including comments.

-marcel
Re: FCONSTANT specification
#134
Author: dxf
Date: Mon, 19 Oct 2026 06:45
10 lines
1530 bytes
On 19/10/2026 9:10 am, Paul Rubin wrote:
> ... 
> 80 bit extended is looking like an x86 artifact by now, maybe.

As there's still much crowing about 64 bit, extended would fulfil
most people's needs.  The issue is hardware support.  If it wasn't
for the x87 largely-complete-fp-on-a-chip just waiting for me to
access it, I'd have stayed with simple s/w fp.  I'm speaking of
course as an implementer - which is a dying breed.
Re: FCONSTANT specification
#145
Author: Paul Rubin
Date: Tue, 20 Oct 2026 02:55
22 lines
2263 bytes
marcel hendrix <mhx@iae.nl> writes:
>>> Which implies H >= 83 for quad double extended precision, ...
> No, extended double is an IEEE format that, e.g., matches the Intel
> FPU's 10 byte memory storage and has a mantissa of 64 bits.

Ah ok, that's what I meant by 80 bit number, because of the other 16
bits (sign and exponent).

> a quad extended double will have a 256 bit mantissa.

Nice, what is the memory representation?

> MPFR is definitely much faster.

MPFR is probably slower than machine coded fixed precision such as
double extended double or whatever.

> The xd-fp library, with a full set of math functions, is only 800
> lines of Forth including comments.

That's pretty good, I thought carefully done math functions could be
messy.
Re: FCONSTANT specification
#146
Author: marcel hendrix
Date: Tue, 20 Oct 2026 06:52
24 lines
2698 bytes
On 10/20/2026 4:55 AM, Paul Rubin wrote:
> Nice, what is the memory representation?

They look like an array of 4 extended doubles, and in fact, they are.
The trick is that *sum* of these four normal 64 bit floats is precisely
equal to a single float with a 4*64 = 256 bit mantissa. This is done by 
manipulating the exponents. See "Software for Doubled-Precision 
Floating-Point Computations", Seppo Linnainmaa, ACM Transactions on 
Mathematical Software, Vol 7, No 3, September 1981, Pages 272-283.

>> The xd-fp library, with a full set of math functions, is only 800
>> lines of Forth including comments.

> That's pretty good, I thought carefully done math functions could be
> messy.

The float library is based on David H. Bailey's paper and is very 
concise. I used only the paper, but there are special issues with 
specifying constants and literals that I originally ignored, see a few 
other threads here. Looking at the (bulky) C, source helped a little:
https://github.com/greggroth/im_learning_cpp/blob/master/comp_programing_exam_solution/qd-2.3.12/src 


-marcel
Re: FCONSTANT specification
#176
Author: Hans Bezemer
Date: Sun, 25 Oct 2026 14:05
37 lines
3435 bytes
On 18-10-2026 17:08, Krishna Myneni wrote:
> On 10/18/26 7:10 AM, Hans Bezemer wrote:
>> On 17-10-2026 06:37, Krishna Myneni wrote:
>>  > Yes, you are clearly smarter than the entire IEEE 754 standards
>>  > committee, which specified that a system should leave the number of
>>  > digits requested in a binary to decimal conversion to be unbounded.
>>
>> Err. Not quite. IEEE 754-2008 permits an implementation-defined limit 
>> H, provided it meets the standard's minimum requirements. It 
>> recommends that H be unbounded, but doesn't make an unbounded limit 
>> mandatory for binary-format conversions.
>>
>> Small correction ;-) It's the difference between "shall" and "should". 
>> In technical specifications, ISO standards, and quality management 
>> systems, shall and should have distinct, legally binding meanings:
>>
> 
> Yes, I know what "should" means. There is no claim for legal binding, 
> and my suggested meanings for "high quality REPRESENT" allow for H to be 
> set to a fixed value.

Well, let's see your exact quote here:
"Yes, you are clearly smarter than the entire IEEE 754 standards 
committee" What has that got to do with anything? I thought we were 
talking arguments here -- not taking IQ tests.

"which specified that a system should leave the number of digits 
requested in a binary to decimal conversion to be unbounded." Actually 
-- it didn't, as I've proven beyond a reasonable doubt. That means you 
were wrong -- and making more than one claim that wasn't supported on 
any standard.

I advise you to do your home work properly before publicly stating that 
a commenter is stupid and ignorant. If you wanna play lazy, be my guest. 
But watch your mouth.

Hans Bezemer
Page 1 of 2 • 72 total messages
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