/
fatan2.txt
86 lines (63 loc) · 2.94 KB
/
fatan2.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
From: "C. G. Montgomery" <cgm@physics.utoledo.edu>
Newsgroups: comp.lang.forth
Subject: RfD: Ambiguity in FATAN2 version 1.2
Date: Sat, 02 May 2009 21:42:38 -0400
Message-ID: <gtisqj$l60$1@pyrite.mv.net>
RfD: Ambiguity in FATAN2 version 1.2
Problem
The ANS definition is:
12.6.2.1489 FATAN2
f-a-tan-two FLOATING EXT ( F: r1 r2 -- r3 ) or ( r1 r2 -- r3 )
r3 is the radian angle whose tangent is r1/r2. An ambiguous condition
exists if r1 and r2 are zero.
This is incomplete, since it does not specify which of the countably
infinite set of angles satisfying this specification will be returned as
r3.
Other computer languages which provide this function commonly specify the
"principal angle", the one between -pi and pi.
Proposal
The first sentence of the definition should be expanded to:
r3 is the principal radian angle (between -pi and pi)
whose tangent is r1/r2.
Another sentence should be added:
A system which returns FALSE for -0E 0E 0E F~ shall return a value
(approximating) -pi when r1=-0E and r2 is negative.
Remarks
This rewording follows the suggestion by Peter Knaggs that the language
follow the pattern used in the definition of FACOS, FASIN, and FATAN (but
with an added clarification of the term "principal").
Discussions in comp.lang.forth have included general agreement that the
present definition is ambiguous, probably unintentionally, and that
specifying the principal angle would be the favored correction.
The second sentence calls for behavior similar to other languages, such as
C and Fortran, is consistent with much modern hardware, and its omission
would impose an unnecessary burden on system providers, since most
systems supporting negative zero follow IEEE floating point behavior
which behaves this way.
The wording of the second sentence has been chosen to be unambiguous
without the need for any new environmental query (even if F~ does not
behave properly).
It has been suggested that additional Forth200x extensions be added to
cover support for negative zeros or perhaps general IEEE floating point
behavior. If such extensions become accepted and provide an
environmental query that would be useful for specifying the behavior of
FATAN2, it would be very easy to make (yet another) modification to the
specification of FATAN2, to make use of them.
Experience
A summary quoted from a posting by David N. Williams in comp.lang.forth:
FATAN2 CONVENTIONS
implementation -pi to pi 0 to 2pi
--------------------------------------
pfe 0.33.70 yes no
gforth 0.7.0 yes no
kforth 1.4.0 yes no
iForth 3.0.3 yes no
4tH 3.5c yes no
SwiftForth 3 no yes
VFX Forth 4 yes no
Win32Forth 6.13.00 yes no
Testing
A set of tests is available at
http://www-personal.umich.edu/~williams/archive/forth/utilities/fatan2-test.fs
\ end of RfD
regards to all cgm