Proposal: OPTIONAL IEEE 754 BINARY FLOATING-POINT WORD SET

Formal

This page is dedicated to discussing this specific proposal

ContributeContributions

KrishnaMyneniavatar of KrishnaMyneni [148] OPTIONAL IEEE 754 BINARY FLOATING-POINT WORD SETProposal2020-08-21 21:03:51

Author:

Krishna Myneni

Change Log:

2020-08-18 v 0.0.1 first draft posted on comp.lang.forth 2020-08-21 v 0.0.2 revised to introduce essential word for defining double-precision IEEE floating point value.

Problem:

The IEEE 754-2008 standard for floating point arithmetic [1] provides numerous advantages for those who write numerical floating point programs, including standardized floating point number formats which have been widely adopted for several decades, as well as a significantly simpler approach to dealing with exceptions in floating point arithmetic. Although significant parts of an optional IEEE floating point word set for Forth have been developed as RfD's since 2009, the proposal(s) [2] have languished now for 11 years without any progress towards including their features within a standard. This RfD takes the view that the lack of progress is primarily a result of two factors:

  1. the complexity of the problem in specifying even a partially complete solution for support of the features IEEE 754-2008 standard, particularly with the setup and enabling of traps for floating point arithmetic exceptions, and

  2. the relatively low use of floating point arithmetic, and specifically of programs which require more than simple floating point numerical calculations, within the Forth user community.

It should be noted that even in language standards which have adopted many of the IEEE 754 arithmetic features, support is often incomplete. One such example is the C99 standard, which specifies extensions for features such as setting the rounding modes and masking floating point exceptions, but does not specify a way to enable and disable floating point exception traps.

Several Forth systems [3] have already extended their floating point capabilities to include IEEE 754 features such as special binary values representing signed infinity (+/-INF) and "not a number" (NAN) values, with possibly different names.

Solution:

Instead of a more or less comprehensive proposal, specifying words to provide most of the functionality within the IEEE 754 standard, we propose the formal inclusion within the standard of the "optional IEEE 754 binary floating-point word set", initially containing a minimal set of words to allow creating IEEE binary floating point values with bit-level precision. Further functionality provided by the IEEE 754-2008 standard may be added by subsequent proposals.

In this proposal, in addition to the inclusion of the "optional IEEE 754 binary floating-point word set", also adding the word MAKE-IEEE-DFLOAT which permits the creation of any recognized double precision floating point value. It will allow definition of special IEEE 754 floating point values which are returned by default upon certain arithmetic exceptions (+/-INF, +/-NAN), and are useful for detecting an arithmetic exception. The IEEE 754 standard also provides other mechanisms for detecting and dealing with floating point arithmetic exceptions.

Subsequent proposals can incrementally add IEEE 754-2008 or IEEE 754-2019 functionality to the standard optional word set. For example, another proposal can add standardized named constants for special binary values returned upon arithmetic exceptions. Another proposal may formally update the specifications for existing floating point arithmetic words for consistency with the IEEE 754 standard, and yet another proposal may add words for exception detection by providing access to the exception flags of the floating point unit. Such changes may be introduced individually so that the problem of providing consistent floating point arithmetic consistent with the IEEE 754 standard can be tackled in pieces rather than all at once. Given the substantial amount of work already done towards such an optional word set [2], the problem can be reduced to identifying groups of words which may be added separately to provide enhanced capabilities.

The adoption of an "optional IEEE 754 binary floating-point word set" into the Forth 20xx standard, initially with minimal provisions, will be immediately useful for practitioners of numerical floating-point computation in Forth. The proposed addition to the new word set is

MAKE-IEEE-DFLOAT ( F: -- r ) ( signbit udfraction uexp -- error )

which will return an IEEE 754 double precision floating point value from the specified bit fields for the sign, binary fraction, and exponent. It will also validate the binary fraction and exponent fields for consistency with the IEEE binary format and return a error value on the data stack, 0 for no error and non-zero values to indicate the type of failure. The least significant bit of the "signbit" value represents the sign of the floating point value (0 is positive, 1 is negative), the lower 32-bits of each cell value of udfraction are concatenated to provide the binary fraction bits of the mantissa, and uexp provides the binary representation of the exponent.

Typical use:

HEX 0 54442D18 921FB 1 MAKE-IEEE-DFLOAT fconstant pi

Proposal:

  1. Adopt the Optional IEEE 754 binary floating point word set into the Forth 20xx standard.

  2. The new word set will provide the word MAKE-IEEE-DFLOAT with the specifications given above.

Reference implementation:

The reference implementation is specific to a 32-bit, little-endian Forth system.

HEX \ Make an IEEE 754 double precision floating point value from \ the specified bits for the sign, binary fraction, and exponent. \ Return the fp value and error code with the following meaning: \ 0 no error \ 1 exponent out of range \ 2 fraction out of range fvariable temp

: MAKE-IEEE-DFLOAT ( signbit udfraction uexp -- r nerror ) dup 800 u< invert IF 2drop 2drop F=ZERO 1 EXIT THEN 14 lshift 3 pick 1F lshift or >r dup 100000 u< invert IF r> 2drop 2drop F=ZERO 2 EXIT THEN r> or [ temp cell+ ] literal ! temp ! drop temp df@ 0 ;

Testing: (Optional)

MarcelHendrixavatar of MarcelHendrix

I don't see any of the references. Is this text incomplete?

KrishnaMyneniavatar of KrishnaMyneni

@MarcelHendrix, sorry I have formatting problems as well as the lack of references. I will update the proposal to fix these issues.

KrishnaMyneniavatar of KrishnaMyneniNew Version: OPTIONAL IEEE 754 BINARY FLOATING-POINT WORD SET

Hide differences

Author:

Krishna Myneni

Change Log:

2020-08-18 v 0.0.1 first draft posted on comp.lang.forth 2020-08-21 v 0.0.2 revised to introduce essential word for defining double-precision IEEE floating point value.

2020-08-18 v 0.0.1 first draft posted on comp.lang.forth

2020-08-21 v 0.0.2 revised to introduce essential word for defining double-precision IEEE floating point value.

2020-08-22 v 0.0.3 fix code formatting and add references

Problem:

The IEEE 754-2008 standard for floating point arithmetic [1] provides numerous advantages for those who write numerical floating point programs, including standardized floating point number formats which have been widely adopted for several decades, as well as a significantly simpler approach to dealing with exceptions in floating point arithmetic. Although significant parts of an optional IEEE floating point word set for Forth have been developed as RfD's since 2009, the proposal(s) [2] have languished now for 11 years without any progress towards including their features within a standard. This RfD takes the view that the lack of progress is primarily a result of two factors:

The IEEE 754-2008 standard for floating point arithmetic [1] provides numerous advantages for those who write numerical floating point programs [2], including standardized floating point number formats which have been widely adopted for several decades, as well as a significantly simpler approach to dealing with exceptions in floating point arithmetic. Although significant parts of an optional IEEE floating point word set for Forth have been developed as RfD's since 2009, the proposal(s) [3] have languished now for 11 years without any progress towards including their features within a standard. This RfD takes the view that the lack of progress is primarily a result of two factors:

  1. the complexity of the problem in specifying even a partially complete solution for support of the features IEEE 754-2008 standard, particularly with the setup and enabling of traps for floating point arithmetic exceptions, and

  2. the relatively low use of floating point arithmetic, and specifically of programs which require more than simple floating point numerical calculations, within the Forth user community.

It should be noted that even in language standards which have adopted many of the IEEE 754 arithmetic features, support is often incomplete. One such example is the C99 standard, which specifies extensions for features such as setting the rounding modes and masking floating point exceptions, but does not specify a way to enable and disable floating point exception traps.

<p>Even in language standards which have adopted many of the IEEE 754 arithmetic features, support is often incomplete. One such example is the C99 standard, which specifies extensions for features such as setting the rounding modes and masking floating point exceptions, but does not specify a way to enable and disable floating point exception traps.

Several Forth systems [3] have already extended their floating point capabilities to include IEEE 754 features such as special binary values representing signed infinity (+/-INF) and "not a number" (NAN) values, with possibly different names.

<p>Several Forth systems [4] have already extended their floating point capabilities to include IEEE 754 features such as special binary values representing signed infinity (+/-INF) and "not a number" (NAN) values, with possibly different names.

Solution:

Instead of a more or less comprehensive proposal, specifying words to provide most of the functionality within the IEEE 754 standard, we propose the formal inclusion within the standard of the "optional IEEE 754 binary floating-point word set", initially containing a minimal set of words to allow creating IEEE binary floating point values with bit-level precision. Further functionality provided by the IEEE 754-2008 standard may be added by subsequent proposals.

<p>Instead of a more or less comprehensive proposal, specifying words to provide most of the functionality within the IEEE 754 standard, we propose the formal inclusion within the standard of the "optional IEEE 754 binary floating-point word set", initially containing a minimal set of words to allow creating IEEE binary floating point values with bit-level precision. Further functionality provided by the IEEE 754-2008 standard may be added by subsequent proposals.

In this proposal, in addition to the inclusion of the "optional IEEE 754 binary floating-point word set", also adding the word MAKE-IEEE-DFLOAT which permits the creation of any recognized double precision floating point value. It will allow definition of special IEEE 754 floating point values which are returned by default upon certain arithmetic exceptions (+/-INF, +/-NAN), and are useful for detecting an arithmetic exception. The IEEE 754 standard also provides other mechanisms for detecting and dealing with floating point arithmetic exceptions.

<p>In this proposal, in addition to the inclusion of the "optional IEEE 754 binary floating-point word set", also adding the word MAKE-IEEE-DFLOAT which permits the creation of any recognized double precision floating point value. It will allow definition of special IEEE 754 floating point values which are returned by default upon certain arithmetic exceptions (+/-INF, NAN), and are useful for detecting an arithmetic exception. The IEEE 754 standard also provides other mechanisms for detecting and dealing with floating point arithmetic exceptions.

Subsequent proposals can incrementally add IEEE 754-2008 or IEEE 754-2019 functionality to the standard optional word set. For example, another proposal can add standardized named constants for special binary values returned upon arithmetic exceptions. Another proposal may formally update the specifications for existing floating point arithmetic words for consistency with the IEEE 754 standard, and yet another proposal may add words for exception detection by providing access to the exception flags of the floating point unit. Such changes may be introduced individually so that the problem of providing consistent floating point arithmetic consistent with the IEEE 754 standard can be tackled in pieces rather than all at once. Given the substantial amount of work already done towards such an optional word set [2], the problem can be reduced to identifying groups of words which may be added separately to provide enhanced capabilities.

<p>Subsequent proposals can incrementally add IEEE 754-2008 or IEEE 754-2019 functionality to the standard optional word set. For example, another proposal can add standardized named constants for special binary values returned upon arithmetic exceptions. Another proposal may formally update the specifications for existing floating point arithmetic words for consistency with the IEEE 754 standard, and yet another proposal may add words for exception detection by providing access to the exception flags of the floating point unit. Such changes may be introduced individually so that the problem of providing consistent floating point arithmetic consistent with the IEEE 754 standard can be tackled in pieces rather than all at once. Given the substantial amount of work already done towards such an optional word set [2], the problem can be reduced to identifying groups of words which may be added separately to provide enhanced capabilities.

The adoption of an "optional IEEE 754 binary floating-point word set" into the Forth 20xx standard, initially with minimal provisions, will be immediately useful for practitioners of numerical floating-point computation in Forth. The proposed addition to the new word set is

<p>The adoption of an "optional IEEE 754 binary floating-point word set" into the Forth 20xx standard, initially with minimal provisions, will be immediately useful for practitioners of numerical floating-point computation in Forth. The proposed addition to the new word set is

MAKE-IEEE-DFLOAT ( F: -- r ) ( signbit udfraction uexp -- error )

which will return an IEEE 754 double precision floating point value from the specified bit fields for the sign, binary fraction, and exponent. It will also validate the binary fraction and exponent fields for consistency with the IEEE binary format and return a error value on the data stack, 0 for no error and non-zero values to indicate the type of failure. The least significant bit of the "signbit" value represents the sign of the floating point value (0 is positive, 1 is negative), the lower 32-bits of each cell value of udfraction are concatenated to provide the binary fraction bits of the mantissa, and uexp provides the binary representation of the exponent.

which will return an IEEE 754 double precision floating point value from the specified bit fields for the sign, binary fraction, and exponent. It will also validate the binary fraction and exponent fields for consistency with the IEEE binary format and return a error value on the data stack, 0 for no error and non-zero values to indicate the type of failure. The least significant bit of the signbit value represents the sign of the floating point value (0 is positive, 1 is negative), the lower 32-bits of each cell value of udfraction are concatenated to provide the binary fraction bits of the mantissa, and uexp provides the binary representation of the exponent.

Typical use:

HEX 0 54442D18 921FB 1 MAKE-IEEE-DFLOAT fconstant pi

HEX
0 54442D18 921FB 1 MAKE-IEEE-DFLOAT fconstant pi

Proposal:

  1. Adopt the Optional IEEE 754 binary floating point word set into the Forth 20xx standard.

<p>

  1. Adopt the Optional IEEE 754 binary floating point word set into the Forth 20xx standard.
  1. The new word set will provide the word MAKE-IEEE-DFLOAT with the specifications given above.
  1. The new word set will provide the word MAKE-IEEE-DFLOAT with the specifications given above.

Reference implementation:

The reference implementation is specific to a 32-bit, little-endian Forth system.

HEX \ Make an IEEE 754 double precision floating point value from \ the specified bits for the sign, binary fraction, and exponent. \ Return the fp value and error code with the following meaning: \ 0 no error \ 1 exponent out of range \ 2 fraction out of range fvariable temp

HEX
\ Make an IEEE 754 double precision floating point value from
\ the specified bits for the sign, binary fraction, and exponent.
\ Return the fp value and error code with the following meaning:
\   0  no error
\   1  exponent out of range
\   2  fraction out of range
fvariable temp

: MAKE-IEEE-DFLOAT ( signbit udfraction uexp -- r nerror ) dup 800 u< invert IF 2drop 2drop F=ZERO 1 EXIT THEN 14 lshift 3 pick 1F lshift or >r dup 100000 u< invert IF r> 2drop 2drop F=ZERO 2 EXIT THEN r> or [ temp cell+ ] literal ! temp ! drop temp df@ 0 ;

: MAKE-IEEE-DFLOAT ( signbit udfraction uexp -- r nerror )
    dup 800 u< invert IF 2drop 2drop F=ZERO 1 EXIT THEN
    14 lshift 3 pick 1F lshift or >r
    dup 100000 u< invert IF
    r> 2drop 2drop F=ZERO 2 EXIT
 THEN
 r> or [ temp cell+ ] literal ! temp !
 drop temp df@ 0 ;

Testing: (Optional)

References

  1. IEEE, 754-2008 - IEEE Standard for Floating-Point Arithmetic - Redline, https://ieeexplore.ieee.org/document/5976968 (2008).
  2. W. Kahan, Lecture Notes on the Status of IEEE Standard 754 for Binary Floating-Point Arithmetic, https://people.eecs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF (1997).
  3. D. N. Williams, Proposal for an Optional IEEE 754 Binary Floating-Point Word Set, v 0.5.4, http://www.forth200x.org/ieee-fp.txt (2009); Also, see older and more recent versions of this draft proposal and another proposal for supporting IEEE 754 exceptions and exception handling at http://www-personal.umich.edu/~williams/archive/forth/ieeefp-drafts/.
  4. Based on discussions in comp.lang.forth during August 2020, the following systems appear to be able to output IEEE 754 values for signed INF: iForth gforth, lxf, kForth-32. Only iForth appears to support an intrinsic definition of fp values for +/-INF.

KrishnaMyneniavatar of KrishnaMyneni

That doesn't look like the preview! This view is not satisfactory. I will crosspost this to comp.lang.forth.

KrishnaMyneniavatar of KrishnaMyneniNew Version: OPTIONAL IEEE 754 BINARY FLOATING-POINT WORD SET

Hide differences

Author:

Krishna Myneni

Change Log:

2020-08-18 v 0.0.1 first draft posted on comp.lang.forth

2020-08-21 v 0.0.2 revised to introduce essential word for defining double-precision IEEE floating point value.

2020-08-22 v 0.0.3 fix code formatting and add references

2020-08-23 v 0.0.4 fix reference

Problem:

The IEEE 754-2008 standard for floating point arithmetic [1] provides numerous advantages for those who write numerical floating point programs [2], including standardized floating point number formats which have been widely adopted for several decades, as well as a significantly simpler approach to dealing with exceptions in floating point arithmetic. Although significant parts of an optional IEEE floating point word set for Forth have been developed as RfD's since 2009, the proposal(s) [3] have languished now for 11 years without any progress towards including their features within a standard. This RfD takes the view that the lack of progress is primarily a result of two factors:

  1. the complexity of the problem in specifying even a partially complete solution for support of the features IEEE 754-2008 standard, particularly with the setup and enabling of traps for floating point arithmetic exceptions, and

  2. the relatively low use of floating point arithmetic, and specifically of programs which require more than simple floating point numerical calculations, within the Forth user community.

<p>Even in language standards which have adopted many of the IEEE 754 arithmetic features, support is often incomplete. One such example is the C99 standard, which specifies extensions for features such as setting the rounding modes and masking floating point exceptions, but does not specify a way to enable and disable floating point exception traps.

<p>Several Forth systems [4] have already extended their floating point capabilities to include IEEE 754 features such as special binary values representing signed infinity (+/-INF) and "not a number" (NAN) values, with possibly different names.

Solution:

<p>Instead of a more or less comprehensive proposal, specifying words to provide most of the functionality within the IEEE 754 standard, we propose the formal inclusion within the standard of the "optional IEEE 754 binary floating-point word set", initially containing a minimal set of words to allow creating IEEE binary floating point values with bit-level precision. Further functionality provided by the IEEE 754-2008 standard may be added by subsequent proposals.

<p>In this proposal, in addition to the inclusion of the "optional IEEE 754 binary floating-point word set", also adding the word MAKE-IEEE-DFLOAT which permits the creation of any recognized double precision floating point value. It will allow definition of special IEEE 754 floating point values which are returned by default upon certain arithmetic exceptions (+/-INF, NAN), and are useful for detecting an arithmetic exception. The IEEE 754 standard also provides other mechanisms for detecting and dealing with floating point arithmetic exceptions.

<p>Subsequent proposals can incrementally add IEEE 754-2008 or IEEE 754-2019 functionality to the standard optional word set. For example, another proposal can add standardized named constants for special binary values returned upon arithmetic exceptions. Another proposal may formally update the specifications for existing floating point arithmetic words for consistency with the IEEE 754 standard, and yet another proposal may add words for exception detection by providing access to the exception flags of the floating point unit. Such changes may be introduced individually so that the problem of providing consistent floating point arithmetic consistent with the IEEE 754 standard can be tackled in pieces rather than all at once. Given the substantial amount of work already done towards such an optional word set [2], the problem can be reduced to identifying groups of words which may be added separately to provide enhanced capabilities.

<p>Subsequent proposals can incrementally add IEEE 754-2008 or IEEE 754-2019 functionality to the standard optional word set. For example, another proposal can add standardized named constants for special binary values returned upon arithmetic exceptions. Another proposal may formally update the specifications for existing floating point arithmetic words for consistency with the IEEE 754 standard, and yet another proposal may add words for exception detection by providing access to the exception flags of the floating point unit. Such changes may be introduced individually so that the problem of providing consistent floating point arithmetic consistent with the IEEE 754 standard can be tackled in pieces rather than all at once. Given the substantial amount of work already done towards such an optional word set [3], the problem can be reduced to identifying groups of words which may be added separately to provide enhanced capabilities.

<p>The adoption of an "optional IEEE 754 binary floating-point word set" into the Forth 20xx standard, initially with minimal provisions, will be immediately useful for practitioners of numerical floating-point computation in Forth. The proposed addition to the new word set is

MAKE-IEEE-DFLOAT ( F: -- r ) ( signbit udfraction uexp -- error )

which will return an IEEE 754 double precision floating point value from the specified bit fields for the sign, binary fraction, and exponent. It will also validate the binary fraction and exponent fields for consistency with the IEEE binary format and return a error value on the data stack, 0 for no error and non-zero values to indicate the type of failure. The least significant bit of the signbit value represents the sign of the floating point value (0 is positive, 1 is negative), the lower 32-bits of each cell value of udfraction are concatenated to provide the binary fraction bits of the mantissa, and uexp provides the binary representation of the exponent.

Typical use:

HEX
0 54442D18 921FB 1 MAKE-IEEE-DFLOAT fconstant pi

Proposal:

<p>

  1. Adopt the Optional IEEE 754 binary floating point word set into the Forth 20xx standard.

  2. The new word set will provide the word MAKE-IEEE-DFLOAT with the specifications given above.

Reference implementation:

The reference implementation is specific to a 32-bit, little-endian Forth system.

HEX
\ Make an IEEE 754 double precision floating point value from
\ the specified bits for the sign, binary fraction, and exponent.
\ Return the fp value and error code with the following meaning:
\   0  no error
\   1  exponent out of range
\   2  fraction out of range
fvariable temp

: MAKE-IEEE-DFLOAT ( signbit udfraction uexp -- r nerror )
    dup 800 u< invert IF 2drop 2drop F=ZERO 1 EXIT THEN
    14 lshift 3 pick 1F lshift or >r
    dup 100000 u< invert IF
    r> 2drop 2drop F=ZERO 2 EXIT
 THEN
 r> or [ temp cell+ ] literal ! temp !
 drop temp df@ 0 ;

Testing: (Optional)

References

  1. IEEE, 754-2008 - IEEE Standard for Floating-Point Arithmetic - Redline, https://ieeexplore.ieee.org/document/5976968 (2008).
  2. W. Kahan, Lecture Notes on the Status of IEEE Standard 754 for Binary Floating-Point Arithmetic, https://people.eecs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF (1997).
  3. D. N. Williams, Proposal for an Optional IEEE 754 Binary Floating-Point Word Set, v 0.5.4, http://www.forth200x.org/ieee-fp.txt (2009); Also, see older and more recent versions of this draft proposal and another proposal for supporting IEEE 754 exceptions and exception handling at http://www-personal.umich.edu/~williams/archive/forth/ieeefp-drafts/.
  4. Based on discussions in comp.lang.forth during August 2020, the following systems appear to be able to output IEEE 754 values for signed INF: iForth gforth, lxf, kForth-32. Only iForth appears to support an intrinsic definition of fp values for +/-INF.

StephenPelcavatar of StephenPelc

Re: MAKE-IEEE-DFLOAT ( F: -- r ) ( signbit udfraction uexp -- error )

I fully support the need for such a word (and its reciprocal) but having covered several IEEE handling CPUs, the natural way to look at an IEEE value is

sign exp fraction

and this also applies for non-IEEE values as used for some embedded systems without FPUs. I also worry about the error return. What do Nan and Inf result in. If there is no error, then +/-Nan is surely the right thing to return, and the error code can disappear, leaving no problems with ambiguous conditions or error codes. The TC voted some years back that error codes should be unique so that they can be used as THROW codes.

The reciprocal operation is also useful:

<code> FLOAT>PARTS ( F: -- ; -- sign exp fraction )

KrishnaMyneniavatar of KrishnaMyneni

Changing the order of the inputs on the data stack for MAKE-IEEE-DFLOAT to sign uexp udfraction is fine if it proves to be more convenient. I have no objection to such a change.

<p>With respect to FLOAT>PARTS , I anticipate the following words will be needed to fetch the individual binary fields of a floating point value:

FSIGNBIT (contained in DNW's IEEEE 754 proposal v0.5.5, section 8.7) FEXPONENT FFRACTION

While MAKE-IEEE-DFLOAT assembles a specifc type of IEEE binary float format (double precision), a generic word such as FLOAT>PARTS should work with the default binary format used by the system, i.e. the same format of the values stored on the floating point stack. The above words, FSIGNBIT FEXPONENT FFRACTION should also apply to the default floating point format. I have not been included in this proposal, but they probably should be included.

<p>The considerations above raises the question of whether or not MAKE-IEEE-SFLOAT should also be included. Are there Forth systems with a floating point stack for single precision floats?

Retired

KrishnaMyneniavatar of KrishnaMyneni

Sorry, I accidentally changed the status to Retired. This proposal is not retired.

Informal

KrishnaMyneniavatar of KrishnaMyneni

To answer the question of whether NaNs should return an error code from MAKE-IEEE-DFLOAT, my thinking is that all IEEE 754 special values should be considered valid. This allows the use of MAKE-IEEE-DFLOAT for defining named constants for the special values. If the TC wants the error codes to be reserved throw codes, that's fine.

ruvavatar of ruv

the lower 32-bits of each cell value of udfraction are concatenated to provide the binary fraction bits of the mantissa

What is the rationale that instead of taking udfraction as a number you take and concatenate the lower 32 bits of each its cell?

KrishnaMyneniavatar of KrishnaMyneni

@ruv, that's a good point. Originally, I thought it might make writing the implementation more consistent between 32 and 64 bit Forths. However, from the user point of view it is easier to deal with one double integer rather than two singles. I will rewrite the proposal to specify that the bits of udfraction specify the binary fraction for the floating point datum. Of course the MAKE-IEEE-DFLOAT word will still check for illegal values. The order of the inputs will also be changed.

ruvavatar of ruv

MAKE-IEEE-DFLOAT ( F: -- r ) ( signbit udfraction uexp -- error )

  1. uexp should be n-exp (i.e. a signed number).

  2. Is it any profit to have signbit ud-mantissa instead of d-mantissa ? (i.e. taking the sign from the mantissa).

  3. What is the radix for the exponent? 2 or 10? (it should be mentioned).

  4. Yes, it's better if error is a throw code.

  5. What is the value of r in the case of error? What is better: 0 or NaN?

  6. Is it any sense to use this function in a recognizer for floating point numbers (if the radix of exponent is 2)?

HEX 0 54442D18 921FB 1 MAKE-IEEE-DFLOAT fconstant pi

How can we get 3.14 from these numbers?

KrishnaMyneniavatar of KrishnaMyneni

The arguments to MAKE-IEEE-DFLOAT have the same binary representation as the corresponding fields of the IEEE 754 binary specification for double precision float. Perhaps this wasn't clear from the description.

Only standard number recognition by the Forth system is needed for the arguments to MAKE-IEEE-DFLOAT. The output will go to a memory buffer instead of onto the floating point stack, per our previous discussion on c.l.f. You may write a recognizer for some equivalent representation such as the hexfloat format. MAKE-IEEE-(X)FLOAT can serve as a factor for writing such a recognizer.

AntonErtlavatar of AntonErtl

At the 2023 meeting the committee decided to suggest that you (the proponent) should remove references to the wordset and that you move the specification of MAKE-IEEE-DFLOAT to the proposal section, and then I should promote the proposal to "formal".

However, the proposal seems clear enough, so I am promoting it to "formal" directly.

Formal

AntonErtlavatar of AntonErtl

Looking at what other programming languages do, in the C world I see:

double ldexp(double x, int exp);

which returns the result of multiplying the floating-point number x by 2 raised to the power exp.

Interestingly, C does not provide a function where the mantissa is provided as an integer number.

One problem with the proposed word that I see is that it produces a native FP value of the system, but the name claims that it produces an IEEE-DFLOAT (which I would interpret as IEEE binary64 number). A number of Forth systems use the Intel extended format (which is also a variant of the IEEE format, but it's not binary64), and on those a word similar to ldexp() may be more appropriate.

Reply New Version