/
fnegate-zero.txt
116 lines (78 loc) · 3.43 KB
/
fnegate-zero.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
From: Krishna Myneni <krishnamyneni@bellsouth.net>
Newsgroups: comp.lang.forth
Subject: Rfd: FNEGATE specification for signed zero
Message-ID: <FNtKl.35748$qa.27195@bignews4.bellsouth.net>
Date: Thu, 30 Apr 2009 22:16:08 -0500
RfD: FNEGATE specification for signed zero
Author: Krishna Myneni
Version 0 -- 30 April 2009
Problem
=======
The ANS Forth standard does not currently specify the behavior of
FNEGATE for floating point zero on systems which support floating
point signed zero. Many modern hardware and software systems which
support floating point arithmetic provide at least partial support of
the IEEE Standard for Floating Point Arithmetic (IEEE 754), which
specifies, among other things, behavior of floating point functions
with respect to signed zero. In order for the Forth standard to
include specifications which are compatible[1] with the IEEE Floating
Point standard, it is necessary for programs to be able to detect
certain features of the floating point implementation. Floating point
signed zero is an important example of such a feature. A simple
modification of the current specification for FNEGATE will allow a
standard program to determine whether or not the Forth system supports
the extension of floating point signed zero.
The current specification of the ANS Forth word, FNEGATE, is
12.6.1.1567 FNEGATE
f-negate FLOATING
( F: r1 -- r2 )
or ( r1 -- r2 )
r2 is the negation of r1.
Proposal
========
Modify the specification of FNEGATE as follows:
FNEGATE
f-negate FLOATING
( F: r1 -- r2 )
r2 is the negation of r1. Systems which support floating point signed
zero must return r2 as negative zero when r1 is zero, and vice-versa.
Reference Implementation
========================
No reference implementation is given, since FNEGATE depends on the
internal details of the floating point representation.
Testing
=======
SET-EXACT
t{ 0E FNEGATE 0E 0E F~ -> FALSE }t
t{ 0E FNEGATE FNEGATE 0E 0E F~ -> TRUE }t
Remarks
=======
-- This proposal will allow a standard Forth program to determine
whether or not the Forth system provides support for floating point
negative zero, via
0E FNEGATE 0E 0E F~ 0= [IF]
\ system supports fp signed zero
[ELSE]
\ system does not have fp signed zero
[THEN]
-- Some Forth systems may have a bug in their implementation of F~ for
exact comparisons. For example, and exact comparison of 0E and -0E
using F~ may return TRUE, even when the system supports fp signed zero.
-- This proposal will allow specifications to be extended for other
floating point words, such as the proposed word FTRUNC, to guarantee
features which are compatible[1] with the IEEE FP standard.
-- The author of this Rfd has no personal experience with the use of
floating point signed zero, other than to venture an educated guess
that it is a potentially useful feature for performing and debugging
floating point calculations. This proposal aims to provide another
tool to Forth programmers developing numerical codes, by guaranteeing
the ability to detect the Forth system support of fp signed zero,
thereby, allowing standard Forth programs to make use of the feature.
Experience
==========
-- Many current hardware and software libraries for floating point
arithmetic partially support the IEEE 754 standard, including floating
point signed zero. The situation with respect to embedded systems is
not know to the author of this Rfd.
[1] "compatible" is not the same as "compliant".
\ end of RfD