Below is preliminary test code for floating point comparisons for
systems with expected IEEE 754 behavior.
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
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<>
...
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.
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 sign is merely an artefact of the preceding calculation and has no inherent significance. Even in applications that use NaN-boxing, the
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.
possible range of values does not include the bit position of the sign.
Am 04.05.2026 um 14:29 schrieb Krishna Myneni:
...The sign is merely an artefact of the preceding calculation and has no inherent significance. Even in applications that use NaN-boxing, the
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.
possible range of values does not include the bit position of the sign.
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>
a good reason to include it in his IEEE proposal. It may be useful inThis Fortran program shows an (artifical) use.
some numerical computation cases. I will look into this further.
On 5/4/2026 2:29 PM, Krishna Myneni wrote:
[..]> 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.This Fortran program shows an (artifical) use.
Sorry for not properly rewrapping.
-marcel
So things such as this can't be expected to work with NANs ;-)
: F>= F< NOT ;
dxf <dxforth@gmail.com> writes:
So things such as this can't be expected to work with NANs ;-)
: F>= F< NOT ;
It certainly behaves differently from the F>= in Gforth:
Gforth's F>=:
\ the usual comparisons with NaNs always yield 0 (unordered), except for F<> NaN 0e f>= . \ 0 ok
0e NaN f>= . \ 0 ok
After
: f>= f< 0= ;
NaN 0e f>= . \ -1 ok
0e NaN f>= . \ -1 ok
There is another set of comparison operators with somewhat unusual
names (that I forgot) that yield true on comparison with NaNs or false
in the case of the one corresponding to F<>. You can synthesize them
in Gforth using F< 0=, F<= 0=, ...
One thing that is also relevant is that when you do something like
( r1 r2 ) f< if \ both operands are numbers and r1<r2
code1
else \ r1>=r2 or at least one of them is a NaN
code2
then
you may actually not be prepared for all the possible variants in the
else case, and may prefer to write that instead:
( r1 r2 ) fover fover f< if
fdrop fdrop code1
else f>= if
code2
else \ r1 or r2 (or both) is a NaN
code3
then then
If such things happen regularly, a multi-branch FP-comparison-and-deal-with-different cases construct may be the way
to go.
AFAICS the presence of a NAN usually means something has gone awry in which >case it may be neither here nor there what branch an application takes.
On 5/4/2026 2:29 PM, Krishna Myneni wrote:
[..]> 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 inThis Fortran program shows an (artifical) use.
some numerical computation cases. I will look into this further.
Sorry for not properly rewrapping.
-marcel
For an operation like the sign function, if you do not think about
NaNs, then, depending on you you implement it, NaN FSGN will result in
-1, 0, or 1, while the caller probably want the result to be NaN.
Defining the missing comparisons as
: F0<= FDUP F0= F0< OR ;
: F0>= FDUP F0= F0> OR ;
: F0<> FDUP F0> F0< OR ;
made LXF64 pass all tests!
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
For an operation like the sign function, if you do not think about
NaNs, then, depending on you you implement it, NaN FSGN will result in
-1, 0, or 1, while the caller probably want the result to be NaN.
The following satisfies the requirements above:
: fsgn ( r1 -- r2 )
case
fdup f0< ?of fdrop -1e endof
fdup f0> ?of fdrop 1e endof
0 endcase ;
-5e fsgn f. \ -1. ok
3e fsgn f. \ 1. ok
0e fsgn f. \ 0. ok
NaN fsgn f. \ NaN ok
- anton
On 7/4/2026 10:55 AM, Anton Ertl wrote:...
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
For an operation like the sign function, if you do not think about
NaNs, then, depending on you you implement it, NaN FSGN will result in
-1, 0, or 1, while the caller probably want the result to be NaN.
David Williams' idea/proposal:
FORTH> words: FSIGN
FSIGNBIT FSIGNALING?
ok
FORTH> +NAN FSIGNBIT ok
[1]FORTH> . 0 ok
FORTH> -NAN FSIGNBIT . -1 ok
-5e fsgn f. \ -1. ok
3e fsgn f. \ 1. ok
0e fsgn f. \ 0. ok
NaN fsgn f. \ NaN ok
On 5/4/2026 2:29 PM, Krishna Myneni wrote:
[..]> 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 inThis Fortran program shows an (artifical) use.
some numerical computation cases. I will look into this further.
Sorry for not properly rewrapping.
-marcel
ANEW -testnans
DOC
(*
comp.lang.fortran #73510 (1 more)
Reply-To: "Matthew C Roberts" <iday_amspayDELETETHESELETTERS@hotmail.com>
From: "Matthew C Roberts" <therobertsDELETETHESELETTERS@sprintmail.com>
Subject: IEEE compliance of NaNs
Lines: 98
Date: Fri Sep 15 20:11:53 CEST 2000
O those more learned than I,
I had a meeting with a professor today who knows WAY more about most things
than I. I had some questions about some Fortran packages he'd written.
During the discussion, he asked what compiler I used & I said CVF. He
bemoaned it, as well as, in his words, every other F90/95 compiler he'd
tested (which he admitted was far from conclusive) for not being IEEE
compliant. He uses g77 and said that he's found other FORTRAN77 compilers
that are acceptable, but not '90/95. I'm not taking sides on this, 'cause I
don't know enough to, but I wanted to solicit opinions. He has written a
little bit of code that demonstrates this... here it is (only very slightly
modified to fit in my DOS window :) ) FWIW, my platform (NT4 SP5, CVF6.1a)
fails the 6th & 12th tests.
Thoughts?
--
Matthew C Roberts
Graduate Student
Department of Economics
NC State University
iday_amspay@DIESPAMDIEhotmail.com
% TO REPLY TO THIS MESSAGE
% REMOVE ALL CAPITAL LETTERS
% FROM THE EMAIL ADDRESS
implicit none
real*8 x,y,z,v,r,s,ignore
v = 1.d0
y = 0.d0
r = 1.d0
s = 1.d0
z = DSQRT(r) - DSQRT(s)
z = DABS(z)
x=y/z
write(*,*) ' '
write(*,'(a)') 'COMPUTED VALUE CORRECT VALUE'
write(*,*) ' '
write(*,'(a,f9.6,a)') ' x = ', x, ' x = NaN'
write(*,'(a,f9.6,a)') ' v = ', v, ' v = 1.00000'
write(*,*) ' '
write(*,*) ' (x.eq.v) =', (x.eq.v), ' (x.eq.v) = F'
write(*,*) ' (x.lt.v) =', (x.lt.v), ' (x.lt.v) = F'
write(*,*) ' (x.le.v) =', (x.le.v), ' (x.le.v) = F'
write(*,*) ' (x.gt.v) =', (x.gt.v), ' (x.gt.v) = F'
write(*,*) ' (x.ge.v) =', (x.ge.v), ' (x.ge.v) = F'
write(*,*) ' (x.ne.v) =', (x.ne.v), ' (x.ne.v) = T'
write(*,*) ' '
write(*,*) ' (x.eq.x) =', (x.eq.x), ' (x.eq.x) = F'
write(*,*) ' (x.lt.x) =', (x.lt.x), ' (x.lt.x) = F'
write(*,*) ' (x.le.x) =', (x.le.x), ' (x.le.x) = F'
write(*,*) ' (x.gt.x) =', (x.gt.x), ' (x.gt.x) = F'
write(*,*) ' (x.ge.x) =', (x.ge.x), ' (x.ge.x) = F'
write(*,*) ' (x.ne.x) =', (x.ne.x), ' (x.ne.x) = T'
write(*,*) ' '
write(*,*) 'Press ENTER to continue tests'
read(*,'(a)') ignore
x=-x
write(*,*) ' '
write(*,'(a,f9.6,a)') ' x = ', x, ' x = -NaN'
write(*,'(a,f9.6,a)') ' v = ', v, ' v = 1.00000'
write(*,*) ' '
write(*,*) ' (x.eq.v) =', (x.eq.v), ' (x.eq.v) = F'
write(*,*) ' (x.lt.v) =', (x.lt.v), ' (x.lt.v) = F'
write(*,*) ' (x.le.v) =', (x.le.v), ' (x.le.v) = F'
write(*,*) ' (x.gt.v) =', (x.gt.v), ' (x.gt.v) = F'
write(*,*) ' (x.ge.v) =', (x.ge.v), ' (x.ge.v) = F'
write(*,*) ' (x.ne.v) =', (x.ne.v), ' (x.ne.v) = T'
write(*,*) ' '
write(*,*) ' (x.eq.x) =', (x.eq.x), ' (x.eq.x) = F'
write(*,*) ' (x.lt.x) =', (x.lt.x), ' (x.lt.x) = F'
write(*,*) ' (x.le.x) =', (x.le.x), ' (x.le.x) = F'
write(*,*) ' (x.gt.x) =', (x.gt.x), ' (x.gt.x) = F'
write(*,*) ' (x.ge.x) =', (x.ge.x), ' (x.ge.x) = F'
write(*,*) ' (x.ne.x) =', (x.ne.x), ' (x.ne.x) = T'
write(*,*) ' '
end
*)
ENDDOC
It seems like the same effect can be achieved by ignoring the sign bit
in comparisons of NaN values.
Krishna Myneni <krishna.myneni@ccreweb.org> writes:
It seems like the same effect can be achieved by ignoring the sign bit
in comparisons of NaN values.
Indeed. The sign bit of a NaN has no significance for the arithmetic
and comparison operations of IEEE-754, only for the signbit and
copysign operations, which work on bits of the FP value without
inspecting the FP value any further (e.g., to see if it is a number).
- anton
I wonder. Is it not more appropriate to raise an exception whenever
A float is compares to a NAN?
Is that against the IEEE standard?
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,126 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 51:57:56 |
| Calls: | 14,414 |
| Calls today: | 2 |
| Files: | 186,401 |
| D/L today: |
11,529 files (3,173M bytes) |
| Messages: | 2,548,956 |
| Posted today: | 1 |