Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #135061 > unrolled thread

IEEE floating point comparisons

Started byKrishna Myneni <krishna.myneni@ccreweb.org>
First post2026-05-03 22:00 -0500
Last post2026-05-06 08:23 -0500
Articles 8 — 4 participants

Back to article view | Back to comp.lang.forth


Contents

  IEEE floating point comparisons Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-05-03 22:00 -0500
    Re: IEEE floating point comparisons Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-05-03 22:18 -0500
    Re: IEEE floating point comparisons peter <peter.noreply@tin.it> - 2026-05-04 09:43 +0200
      Re: IEEE floating point comparisons Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-05-04 07:29 -0500
        Re: IEEE floating point comparisons minforth <minforth@gmx.net> - 2026-05-04 21:53 +0200
          Re: IEEE floating point comparisons Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-05-04 17:20 -0500
          Re: IEEE floating point comparisons dxf <dxforth@gmail.com> - 2026-05-05 11:32 +1000
    Re: IEEE floating point comparisons Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-05-06 08:23 -0500

#135061 — IEEE floating point comparisons

FromKrishna Myneni <krishna.myneni@ccreweb.org>
Date2026-05-03 22:00 -0500
SubjectIEEE floating point comparisons
Message-ID<10t9259$3c72d$1@dont-email.me>
Below is preliminary test code for floating point comparisons for 
systems with expected IEEE 754 behavior.

Relevant floating point exceptions should be masked.

Please let me know if you find any errors in the tests.

The tests pass on recent kForth-32/64 development versions (v2.8.0 and 
v0.8.0, respectively):
TESTING F=
TESTING F<>
TESTING F<
TESTING F>
TESTING F<=
TESTING F>=
TESTING F0=
TESTING F0<
TESTING F0>

The auxiliary code, ieee-754.4th, which defines special values is also 
attached below.

--
Krishna Myneni

2 attachments:

ieee-comparisons-test.4th
ieee-754.4th

\ ===== begin ieee-comparisons-test.4th =====
\ ieee-comparisons-test.4th
\
\ Comparison of IEEE 754 special values
\ Floating point exceptions should be masked.
\
\ include ans-words.4th (needed for kForth only)
include ttester.4th
include ieee-754.4th

TESTING F=
\ F= sanity tests
t{ -1e  -1e  F= -> true  }t
t{ -1e   1e  F= -> false }t
t{  1e  -1e  F= -> false }t
t{  1e   1e  F= -> true  }t

\ F= NAN tests
t{ +NAN +NAN F= -> false }t
t{ +NAN -NAN F= -> false }t
t{ +NAN +INF F= -> false }t
t{ -NAN +INF F= -> false }t
t{ +NAN -INF F= -> false }t
t{ -NAN -INF F= -> false }t
t{ +NAN  0e  F= -> false }t
t{ -NAN  0e  F= -> false }t
t{ +NAN -0e  F= -> false }t
t{ -NAN -0e  F= -> false }t

\ F= +/-0 and +/-INF tests
t{ -0e  -0e  F= -> true  }t
t{ -0e   0e  F= -> true  }t
t{  0e  -0e  F= -> true  }t
t{  0e   0e  F= -> true  }t
t{ -INF -0e  F= -> false }t
t{ -INF  0e  F= -> false }t
t{ +INF -0e  F= -> false }t
t{ +INF  0e  F= -> false }t
t{ +INF -INF F= -> false }t
t{ +INF +INF F= -> true  }t
t{ -INF -INF F= -> true  }t
t{ -INF +INF F= -> false }t


TESTING F<>
\ F<> sanity tests
t{ -1e  -1e  F<> -> false }t
t{ -1e   1e  F<> -> true  }t
t{  1e  -1e  F<> -> true  }t
t{  1e   1e  F<> -> false }t

\ F<> NAN tests
t{ +NAN +NAN F<> -> true }t
t{ +NAN -NAN F<> -> true }t
t{ +NAN +INF F<> -> true }t
t{ -NAN +INF F<> -> true }t
t{ +NAN -INF F<> -> true }t
t{ -NAN -INF F<> -> true }t
t{ +NAN  0e  F<> -> true }t
t{ -NAN  0e  F<> -> true }t
t{ +NAN -0e  F<> -> true }t
t{ -NAN -0e  F<> -> true }t

\ F<> +/-0 and +/-INF tests
t{ -0e  -0e  F<> -> false }t
t{ -0e   0e  F<> -> false }t
t{  0e  -0e  F<> -> false }t
t{  0e   0e  F<> -> false }t
t{ -INF -0e  F<> -> true  }t
t{ -INF  0e  F<> -> true  }t
t{ +INF -0e  F<> -> true  }t
t{ +INF  0e  F<> -> true  }t
t{ +INF -INF F<> -> true  }t
t{ +INF +INF F<> -> false }t
t{ -INF -INF F<> -> false }t
t{ -INF +INF F<> -> true  }t


TESTING F<
\ F< sanity tests
t{ -1e  -1e  F< -> false }t
t{ -1e   1e  F< -> true  }t
t{  1e  -1e  F< -> false }t
t{  1e   1e  F< -> false }t

\ F< NAN tests
t{ +NAN +NAN F< -> false }t
t{ +NAN -NAN F< -> false }t
t{ +NAN +INF F< -> false }t
t{ -NAN +INF F< -> false }t
t{ +NAN -INF F< -> false }t
t{ -NAN -INF F< -> false }t
t{ +NAN  0e  F< -> false }t
t{ -NAN  0e  F< -> false }t
t{ +NAN -0e  F< -> false }t
t{ -NAN -0e  F< -> false }t

\ F< +/-0 and +/-INF tests
t{ -0e  -0e  F< -> false }t
t{ -0e   0e  F< -> false }t
t{  0e  -0e  F< -> false }t
t{  0e   0e  F< -> false }t
t{ -INF -0e  F< -> true  }t
t{ -INF  0e  F< -> true  }t
t{ +INF -0e  F< -> false }t
t{ +INF  0e  F< -> false }t
t{ +INF -INF F< -> false }t
t{ +INF +INF F< -> false }t
t{ -INF -INF F< -> false }t
t{ -INF +INF F< -> true  }t


TESTING F>
\ F> sanity tests
t{ -1e  -1e  F> -> false }t
t{ -1e   1e  F> -> false }t
t{  1e  -1e  F> -> true  }t
t{  1e   1e  F> -> false }t

\ F> NAN tests
t{ +NAN +NAN F> -> false }t
t{ +NAN -NAN F> -> false }t
t{ +NAN +INF F> -> false }t
t{ -NAN +INF F> -> false }t
t{ +NAN -INF F> -> false }t
t{ -NAN -INF F> -> false }t
t{ +NAN  0e  F> -> false }t
t{ -NAN  0e  F> -> false }t
t{ +NAN -0e  F> -> false }t
t{ -NAN -0e  F> -> false }t

\ F> +/-0 and +/-INF tests
t{ -0e  -0e  F> -> false }t
t{ -0e   0e  F> -> false }t
t{  0e  -0e  F> -> false }t
t{  0e   0e  F> -> false }t
t{ -INF -0e  F> -> false }t
t{ -INF  0e  F> -> false }t
t{ +INF -0e  F> -> true  }t
t{ +INF  0e  F> -> true  }t
t{ +INF -INF F> -> true  }t
t{ +INF +INF F> -> false }t
t{ -INF -INF F> -> false }t
t{ -INF +INF F> -> false }t


TESTING F<=
\ F<= sanity tests
t{ -1e  -1e  F<= -> true }t
t{ -1e   1e  F<= -> true }t
t{  1e  -1e  F<= -> false }t
t{  1e   1e  F<= -> true }t

\ F<= NAN tests
t{ +NAN +NAN F<= -> false }t
t{ +NAN -NAN F<= -> false }t
t{ +NAN +INF F<= -> false }t
t{ -NAN +INF F<= -> false }t
t{ +NAN -INF F<= -> false }t
t{ -NAN -INF F<= -> false }t
t{ +NAN  0e  F<= -> false }t
t{ -NAN  0e  F<= -> false }t
t{ +NAN -0e  F<= -> false }t
t{ -NAN -0e  F<= -> false }t

\ F<= +/-0 and +/-INF tests
t{ -0e  -0e  F<= -> true }t
t{ -0e   0e  F<= -> true }t
t{  0e  -0e  F<= -> true }t
t{  0e   0e  F<= -> true }t
t{ -INF -0e  F<= -> true }t
t{ -INF  0e  F<= -> true }t
t{ +INF -0e  F<= -> false }t
t{ +INF  0e  F<= -> false }t
t{ +INF -INF F<= -> false }t
t{ +INF +INF F<= -> true }t
t{ -INF -INF F<= -> true }t
t{ -INF +INF F<= -> true }t


TESTING F>=
\ F>= sanity tests
t{ -1e  -1e  F>= -> true }t
t{ -1e   1e  F>= -> false }t
t{  1e  -1e  F>= -> true }t
t{  1e   1e  F>= -> true }t

\ F>= NAN tests
t{ +NAN +NAN F>= -> false }t
t{ +NAN -NAN F>= -> false }t
t{ +NAN +INF F>= -> false }t
t{ -NAN +INF F>= -> false }t
t{ +NAN -INF F>= -> false }t
t{ -NAN -INF F>= -> false }t
t{ +NAN  0e  F>= -> false }t
t{ -NAN  0e  F>= -> false }t
t{ +NAN -0e  F>= -> false }t
t{ -NAN -0e  F>= -> false }t

\ F>= +/-0 and +/-INF tests
t{ -0e  -0e  F>= -> true }t
t{ -0e   0e  F>= -> true }t
t{  0e  -0e  F>= -> true }t
t{  0e   0e  F>= -> true }t
t{ -INF -0e  F>= -> false }t
t{ -INF  0e  F>= -> false }t
t{ +INF -0e  F>= -> true }t
t{ +INF  0e  F>= -> true }t
t{ +INF -INF F>= -> true }t
t{ +INF +INF F>= -> true }t
t{ -INF -INF F>= -> true }t
t{ -INF +INF F>= -> false }t


TESTING F0=
\ F0= NAN tests
t{ +NAN F0= -> false }t
t{ -NAN F0= -> false }t

TESTING F0<
\ F0< NAN tests
t{ +NAN F0< -> false }t
t{ -NAN F0< -> false }t

TESTING F0>
\ F0> NAN tests
t{ +NAN F0> -> false }t
t{ -NAN F0> -> false }t

\ ===== end ieee-comparisons-test.4th =====


\ ===== begin ieee-754.4th =====
\ ieee-754.4th
\
\ Provides additional definitions for IEEE 754 double-precision
\ floating point arithmetic on x87 FPU.
\
\ GLOSSARY:
\
\ Generic construction of a double-precision float from its
\ binary fields:
\
\   MAKE-IEEE-DFLOAT ( signbit udfraction uexp -- r nerror )
\                    ( signbit udfraction uexp -- nerror ) ( F: -- r)
\
\ Binary fields of IEEE 754 floating point values
\
\   FSIGNBIT    ( F: r -- ) ( -- minus? )
\   FEXPONENT   ( F: r -- ) ( -- uexp )
\   FFRACTION   ( F: r -- ) ( -- udfraction )
\
\   FINITE?     ( F: r -- ) ( -- flag )
\   FNORMAL?    ( F: r -- ) ( -- flag )
\   FSUBNORMAL? ( F: r -- ) ( -- flag )
\   FINFINITE?  ( F: r -- ) ( -- flag )
\   FNAN?       ( F: r -- ) ( -- flag )
\
\ Exception flag words
\
\   GET-FFLAGS  ( excpts -- flags )
\   CLEAR-ALL-FFLAGS  ( -- )
\
\ IEEE 754 special values:
\
\   +INF        ( F: -- r )
\   -INF        ( F: -- r )
\   +NAN        ( F: -- r )
\   -NAN        ( F: -- r )
\
\ To be implemented:
\
\   FCOPYSIGN     ( F: r1 r2 -- r3 )
\   FNEARBYINT    ( F: r1 -- r2 )
\   FNEXTUP       ( F: r1 -- r2 )
\   FNEXTDOWN     ( F: r1 -- r2 )
\   FSCALBN       ( n -- ) ( F: r -- r*2^n )
\   FLOGB         ( F: r -- e )
\   FREMAINDER    ( F: x y -- r q )
\   CLEAR-FFLAGS  ( excepts -- )
\   SET-FFLAGS    ( excepts -- )
\   FENABLE       ( excepts -- )
\   FDISABLE      ( excepts -- )
\
\
\ These words are based on the Optional IEEE 754 Binary Floating
\ Point word set(s) proposed by David N. Williams [1]. A few of
\ the words provided here are additional convenience words which
\ are not part of the proposals in Ref. 1.
\
\ K. Myneni, 2020-08-20
\ Revs. 2020-08-27, 2022-08-02, 2026-02-08
\
\ References:
\ 1. David N. Williams, Proposal Drafts for Optional IEEE 754
\    Binary Floating Point Word Set, 27 August 2020.
\    http://www-personal.umich.edu/~williams/archive/forth/ieeefp-drafts/
\
BASE @
DECIMAL
0e fconstant F=ZERO
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 4 + ] literal L! temp L!
     drop temp df@ 0 ;

: FSIGNBIT ( F: r -- ) ( -- minus? )
     temp df! [ temp 4 + ] literal UL@ 80000000 and 0<> ;

: FEXPONENT ( F: r -- ) ( -- u )
     temp df! [ temp 4 + ] literal UL@ 14 rshift 7FF and ;

: FFRACTION ( F: r -- ) ( -- ud )
     temp df! temp UL@  [ temp 4 + ] literal UL@ 000FFFFF and ;

: FINITE?  ( F: r -- ) ( -- [normal|subnormal]? ) fexponent 7FF <> ;

: FNORMAL? ( F: r -- ) ( -- normal? )  fexponent 0<> ;

: FSUBNORMAL? ( F: r -- ) ( -- subnormal? )  fexponent 0= ;

: FINFINITE? ( F: r -- ) ( -- [+/-]Inf? )
    finite? invert ;

: FNAN? ( F: r -- ) ( -- nan? )
    fdup FEXPONENT 7FF = >r FFRACTION D0= invert r> and ;


\ Exception bits in fpu status word

  1  constant  FINVALID
  4  constant  FDIVBYZERO
  8  constant  FOVERFLOW
10  constant  FUNDERFLOW
20  constant  FINEXACT

FINVALID FDIVBYZERO or FOVERFLOW or FUNDERFLOW or FINEXACT or
constant ALL-FEXCEPTS

1 cells 4 = [IF]

[DEFINED] getFPUstatusX86 [IF]

: GET-FFLAGS ( excepts -- flags )
     getFPUstatusX86 fpu-status @ and ;

: CLEAR-ALL-FFLAGS ( -- ) clearFPUexceptionsX86 ;

: CLEAR-FFLAGS ( excepts -- )
;

: SET-FFLAGS ( excepts -- )
;

: FENABLE ( excepts -- )
;

: FDISABLE ( excepts -- )
;

: FCOPYSIGN ( F: r1 r2 -- r3 )
;

: FNEARBYINT ( F: r1 -- r2 )
;

: FNEXTUP ( F: r1 -- r2 )
;

: FNEXTDOWN ( F: r1 -- r2 )
;

: FSCALBN ( r n -- r*2^n )
;

: FLOGB ( F: r -- e )
;

: FREMAINDER ( F: x y -- r q )

;
[ELSE]
cr .( Some functions are not available.) cr
[THEN]
[ELSE]
cr .( Some functions are for 32-bit system only!) cr
[THEN]

\ Constants representing  -INF  +INF  -NAN  +NAN
true  0 0 7FF make-ieee-dfloat 0= [IF] fconstant -INF [ELSE] fdrop [THEN]
[DEFINED] -INF [IF] -INF fnegate fconstant +INF [THEN]
true  1 0 7FF make-ieee-dfloat 0= [IF] fconstant -NAN [ELSE] fdrop [THEN]
[DEFINED] -NAN [IF] -NAN fnegate fconstant +NAN [THEN]


BASE !
\ ===== end ieee-754.4th =====

[toc] | [next] | [standalone]


#135062

FromKrishna Myneni <krishna.myneni@ccreweb.org>
Date2026-05-03 22:18 -0500
Message-ID<10t9365$3c72d$2@dont-email.me>
In reply to#135061
On 5/3/26 10:00 PM, Krishna Myneni wrote:
> Below is preliminary test code for floating point comparisons for 
> systems with expected IEEE 754 behavior.
> 
...

Looking back through David N Williams' archive from his personal page at 
umich.edu, I found test code for his reference implementation of IEEE fp 
words from ieee-ref-test.fs, version 0.5.0 from December 24, 2020:

(   Title:  Tests for IEEE 754-2008 reference representation
      File:  ieeefp-ref-test.fs
    Author:  David N. Williams
   Version:  0.5.0
   License:  Public Domain
   Revised:  December 24, 2020
...

The above code is much more comprehensive and complex than the tests I 
post here. I did not use them as a reference for writing my 
ieee-comparisons-test.4th, which is much more limited in scope.

If anyone has a later version of David's reference implementation and 
tests, I would appreciate you sending those to me.

--
KM

[toc] | [prev] | [next] | [standalone]


#135063

Frompeter <peter.noreply@tin.it>
Date2026-05-04 09:43 +0200
Message-ID<20260504094359.00003976@tin.it>
In reply to#135061
On Sun, 3 May 2026 22:00:56 -0500
Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

> Below is preliminary test code for floating point comparisons for 
> systems with expected IEEE 754 behavior.
> 
> Relevant floating point exceptions should be masked.
> 
> Please let me know if you find any errors in the tests.
> 
> The tests pass on recent kForth-32/64 development versions (v2.8.0 and 
> v0.8.0, respectively):
> TESTING F=
> TESTING F<>
> TESTING F<
> TESTING F>
> TESTING F<=
> TESTING F>=
> TESTING F0=
> TESTING F0<
> TESTING F0>
> 
> The auxiliary code, ieee-754.4th, which defines special values is also 
> attached below.
> 
> --
> Krishna Myneni
> 
> 2 attachments:
> 
> ieee-comparisons-test.4th
> ieee-754.4th
> 
> \ ===== begin ieee-comparisons-test.4th =====
> \ ieee-comparisons-test.4th
> \
> \ Comparison of IEEE 754 special values
> \ Floating point exceptions should be masked.
> \
> \ include ans-words.4th (needed for kForth only)
> include ttester.4th
> include ieee-754.4th
> 

Tested it on lxf64. No errors reported!

I needed to define +NAN and +INF, I had them as NAN and INF.
But I print them out as +INF etc! It makes more sense with the +

I did not include the ieee-754.4th as that did not add anything.

on lxf there is a problem with f<> and NANs. I need to correct f<>

BR
Peter

[toc] | [prev] | [next] | [standalone]


#135067

FromKrishna Myneni <krishna.myneni@ccreweb.org>
Date2026-05-04 07:29 -0500
Message-ID<10ta3eo$3l84s$1@dont-email.me>
In reply to#135063
On 5/4/26 02:43, peter wrote:
> On Sun, 3 May 2026 22:00:56 -0500
> Krishna Myneni <krishna.myneni@ccreweb.org> wrote:
> 
>> Below is preliminary test code for floating point comparisons for
>> systems with expected IEEE 754 behavior.
>>
>> Relevant floating point exceptions should be masked.
>>
>> Please let me know if you find any errors in the tests.
>>
>> The tests pass on recent kForth-32/64 development versions (v2.8.0 and
>> v0.8.0, respectively):
>> TESTING F=
>> TESTING F<>
>> TESTING F<
>> TESTING F>
>> TESTING F<=
>> TESTING F>=
>> TESTING F0=
>> TESTING F0<
>> TESTING F0>
>>
>> The auxiliary code, ieee-754.4th, which defines special values is also
>> attached below.
>>
>> --
>> Krishna Myneni
>>
>> 2 attachments:
>>
>> ieee-comparisons-test.4th
>> ieee-754.4th
>>
>> \ ===== begin ieee-comparisons-test.4th =====
>> \ ieee-comparisons-test.4th
>> \
>> \ Comparison of IEEE 754 special values
>> \ Floating point exceptions should be masked.
>> \
>> \ include ans-words.4th (needed for kForth only)
>> include ttester.4th
>> include ieee-754.4th
>>
> 
> Tested it on lxf64. No errors reported!
> 
> I needed to define +NAN and +INF, I had them as NAN and INF.
> But I print them out as +INF etc! It makes more sense with the +
> 
> I did not include the ieee-754.4th as that did not add anything.
> 
> on lxf there is a problem with f<> and NANs. I need to correct f<>
> ...

Good to hear.

I included ieee-754.4th for Forth systems which did not have +/-INF and 
+/-NAN defined. It also provides the extremely useful words FINFINITE? 
and FNAN? to check for infinities and NANs resulting from calculations, 
as well as FSUBNORMAL? when the results are represented with less 
precision than standard double precision. These words are all part of 
David Williams' IEEE proposal.

The rationale for the signed NAN is unclear to me, but I think David had 
a good reason to include it in his IEEE proposal. It may be useful in 
some numerical computation cases. I will look into this further.

--
Krishna

[toc] | [prev] | [next] | [standalone]


#135069

Fromminforth <minforth@gmx.net>
Date2026-05-04 21:53 +0200
Message-ID<n5sboiFm58sU1@mid.individual.net>
In reply to#135067
Am 04.05.2026 um 14:29 schrieb Krishna Myneni:
> On 5/4/26 02:43, peter wrote:
>> On Sun, 3 May 2026 22:00:56 -0500
>> Krishna Myneni <krishna.myneni@ccreweb.org> wrote:
>>
>>> Below is preliminary test code for floating point comparisons for
>>> systems with expected IEEE 754 behavior.
>>>
>>> Relevant floating point exceptions should be masked.
>>>
>>> Please let me know if you find any errors in the tests.
>>>
>>> The tests pass on recent kForth-32/64 development versions (v2.8.0 and
>>> v0.8.0, respectively):
>>> TESTING F=
>>> TESTING F<>
>>> TESTING F<
>>> TESTING F>
>>> TESTING F<=
>>> TESTING F>=
>>> TESTING F0=
>>> TESTING F0<
>>> TESTING F0>
>>>
>>> The auxiliary code, ieee-754.4th, which defines special values is also
>>> attached below.
>>>
>>> -- 
>>> Krishna Myneni
>>>
>>> 2 attachments:
>>>
>>> ieee-comparisons-test.4th
>>> ieee-754.4th
>>>
>>> \ ===== begin ieee-comparisons-test.4th =====
>>> \ ieee-comparisons-test.4th
>>> \
>>> \ Comparison of IEEE 754 special values
>>> \ Floating point exceptions should be masked.
>>> \
>>> \ include ans-words.4th (needed for kForth only)
>>> include ttester.4th
>>> include ieee-754.4th
>>>
>>
>> Tested it on lxf64. No errors reported!
>>
>> I needed to define +NAN and +INF, I had them as NAN and INF.
>> But I print them out as +INF etc! It makes more sense with the +
>>
>> I did not include the ieee-754.4th as that did not add anything.
>>
>> on lxf there is a problem with f<> and NANs. I need to correct f<>
>> ...
> 
> Good to hear.
> 
> I included ieee-754.4th for Forth systems which did not have +/-INF and 
> +/-NAN defined. It also provides the extremely useful words FINFINITE? 
> and FNAN? to check for infinities and NANs resulting from calculations, 
> as well as FSUBNORMAL? when the results are represented with less 
> precision than standard double precision. These words are all part of 
> David Williams' IEEE proposal.
> 
> The rationale for the signed NAN is unclear to me, but I think David had 
> a good reason to include it in his IEEE proposal. It may be useful in 
> some numerical computation cases. I will look into this further.
> 
The sign is merely an artefact of the preceding calculation and has no
inherent significance. Even in applications that use NaN-boxing, the
possible range of values does not include the bit position of the sign.

[toc] | [prev] | [next] | [standalone]


#135070

FromKrishna Myneni <krishna.myneni@ccreweb.org>
Date2026-05-04 17:20 -0500
Message-ID<10tb63r$se6$1@dont-email.me>
In reply to#135069
On 5/4/26 14:53, minforth wrote:
> Am 04.05.2026 um 14:29 schrieb Krishna Myneni:
>> On 5/4/26 02:43, peter wrote:
>>> On Sun, 3 May 2026 22:00:56 -0500
>>> Krishna Myneni <krishna.myneni@ccreweb.org> wrote:
>>>
>>>> Below is preliminary test code for floating point comparisons for
>>>> systems with expected IEEE 754 behavior.
>>>>
>>>> Relevant floating point exceptions should be masked.
>>>>
>>>> Please let me know if you find any errors in the tests.
>>>>
...
>>
>> I included ieee-754.4th for Forth systems which did not have +/-INF 
>> and +/-NAN defined. It also provides the extremely useful words 
>> FINFINITE? and FNAN? to check for infinities and NANs resulting from 
>> calculations, as well as FSUBNORMAL? when the results are represented 
>> with less precision than standard double precision. These words are 
>> all part of David Williams' IEEE proposal.
>>
>> The rationale for the signed NAN is unclear to me, but I think David 
>> had a good reason to include it in his IEEE proposal. It may be useful 
>> in some numerical computation cases. I will look into this further.
>>
> The sign is merely an artefact of the preceding calculation and has no
> inherent significance. Even in applications that use NaN-boxing, the
> possible range of values does not include the bit position of the sign.


The Wikipedia page on IEEE 754 (link below) discusses a type of 
comparison called "total-ordering predicate" in which,

"NaN is treated as if it had a larger absolute value than Infinity (or 
any other floating-point numbers). (−NaN < −Infinity; +Infinity < +NaN.)"

Ordinary comparisons with +/-NAN are considered unordered. I don't know 
of any computational uses for this sort of comparison, but I expect it 
wouldn't be discussed if it did not have some uses.

--
Krishna


[toc] | [prev] | [next] | [standalone]


#135071

Fromdxf <dxforth@gmail.com>
Date2026-05-05 11:32 +1000
Message-ID<69f948bb$1@news.ausics.net>
In reply to#135069
On 5/05/2026 5:53 am, minforth wrote:
> Am 04.05.2026 um 14:29 schrieb Krishna Myneni:
>> ...
>> I included ieee-754.4th for Forth systems which did not have +/-INF and +/-NAN defined. It also provides the extremely useful words FINFINITE? and FNAN? to check for infinities and NANs resulting from calculations, as well as FSUBNORMAL? when the results are represented with less precision than standard double precision. These words are all part of David Williams' IEEE proposal.
>>
>> The rationale for the signed NAN is unclear to me, but I think David had a good reason to include it in his IEEE proposal. It may be useful in some numerical computation cases. I will look into this further.
>>
> The sign is merely an artefact of the preceding calculation and has no
> inherent significance. Even in applications that use NaN-boxing, the
> possible range of values does not include the bit position of the sign.

When creating constants that represent NAN the sign bit will necessarily
be there.  That's enough to include it in the identifier IMO.  Similarly
when displaying fp datum that happen to be NAN.  I would rather see more
information than less.  When I'm told something occurred "last year" it
only begs the question "exactly when?".


 

[toc] | [prev] | [next] | [standalone]


#135074

FromKrishna Myneni <krishna.myneni@ccreweb.org>
Date2026-05-06 08:23 -0500
Message-ID<10tffd5$177l1$1@dont-email.me>
In reply to#135061
On 5/3/26 22:00, Krishna Myneni wrote:
> Below is preliminary test code for floating point comparisons for 
> systems with expected IEEE 754 behavior.
> 
> Relevant floating point exceptions should be masked.
> 
> Please let me know if you find any errors in the tests.
> 
> The tests pass on recent kForth-32/64 development versions (v2.8.0 and 
> v0.8.0, respectively):
> TESTING F=
> TESTING F<>
> TESTING F<
> TESTING F>
> TESTING F<=
> TESTING F>=
> TESTING F0=
> TESTING F0<
> TESTING F0>
> 
...

My test code ieee-comparisons-test.4th for testing the following 
comparisons with IEEE special values is now part of the system test code 
for kForth-32/64. The comparisons tested are

F=  F<>  F<  F>  F<=  F>=  F0=  F0<  F0>

It does not contain tests for the comparison word F~ for which there is 
already existing system test code called ieee-fprox-test.4th in the 
kForth packages. The test code for F~ was written by David Williams.

The tests performed by ieee-comparisons-test.4th and ieee-fprox-test.4th 
rely on the definition of the following floating point constants:

+INF -INF  +NAN  -NAN


David Williams' last draft of his IEEE fp proposal, v0.5.5,

"Proposal for an optional IEEE 754, Binary Floating-Point Word Set,"

contained in the text file, dated 12 Aug 2020,

ieee-fp-0.5.5.txt

(the internal date in the document is given as 31 Aug 2009, but I know 
he was working on it in 2020 so I believe the file date over the date 
contained in the document). This file proposes to standardize the 
following comparison words, Section 8.3, "Comparison",

F<  F=  F>  F>=  F0<  F0=  F0<=  F0>=  F~

The proposal does not standardize the name of the inequality comparison 
F<> -- indeed the proposal nowhere references F<> though it is common 
use in Forth systems.

The proposal standardizes the following floating point constants,
Section 7.1, "Constants",

+INF  -INF  +NAN  -NAN

Another set of words which David's proposal standardizes, and are 
relevant to recent discussions, are the floating-point value 
classification words, Section 8.4, "Classification",

FINITE?
FNORMAL?
FSUBNORMAL?
FINFINITE?
FNAN?

corresponding to functions provided by C99.

In kForth, the proposed standard constants and the classification words 
are provided by ieee-754.4th.

I downloaded an archive of David's personal webpages at umich.edu, so I 
have access to these files. They appear to have been taken down now, and 
I will make his draft proposal, reference implementation, and test code 
for the reference implementation available on ccreweb.org (link to be 
posted in a separate thread).


Status of Forth-20xx

The current downloadable Forth-2012 standard document from

https://forth-standard.org

dated 10 Nov 2014, specifies only the following floating point comparisons:

12.6.1.1440  F0<
12.6.1.1450  F0=
12.6.1.1460  F<
12.6.2.1640  F~

much sparser than what I imagined to be part of the standard, though the 
other comparisons may be defined in terms of these.

--
Krishna Myneni

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web