RfD: Ambiguity in FATAN2 version 1.2


    Sponsored Links


  • 1. BETWEEN
    WITHIN was meant to replace BETWEEN but it hasn't always been a comfortable fit. A characteristic of WITHIN is that the upper limit is not included in the range. This can lead to obfuscated code e.g. CHAR a CHAR z 1+ WITHIN Thus the functionality of BETWEEN is still being used, if not the word itself. When defined today, it is usually as: : BETWEEN ( n1|u1 n2|u2 n3|u3 -- flag ) 1+ WITHIN ; But it is not without problem e.g. it fails when u1 = u3 = MAX-U . Perhaps not so significant for 32-bit systems as for 16-bit, it is nevertheless an inconsistency which can catch a programmer unawares. Playing with the algorithm for WITHIN (A.6.2.2440) one gets: : BETWEEN ( n1|u1 n2|u2 n3|u3 -- flag ) OVER - -ROT - U< 0= ; It seems to work. If anyone finds a problem or knows something better, let us know. In the meantime, here are several code versions. code BETWEEN ( n1|u1 n2|u2 n3|u3 -- flag ) sub ebx, 0 [ebp] mov ecx, 4 [ebp] sub ecx, 0 [ebp] cmp ebx, ecx sbb ebx, ebx not ebx lea ebp, 8 [ebp] ret end-code code BETWEEN ( n1|u1 n2|u2 n3|u3 -- flag ) bx pop ax pop cx pop ax bx sub ax cx sub cx bx cmp bx bx sbb bx not bx push next end-code
  • 2. [Doty] The Promise of Forth
    John Doty < XXXX@XXXXX.COM > wrote: > Elizabeth D Rather wrote: >> John Doty wrote: >>> Marc Olschok wrote: >> .... >>>> >>>> As to Forth, we had clarified this also before: the Forth culture >>>> encouraged rewriting instead of reusing. >>> >>> OK, you've identified a weakness. How do we fix it? >> >> By ending this interminable wrangle and publishing some code. That >> means *you* (everyone who's concerned about this). > What would motivate me to do so, with Forth in its present sorry > state? I would have thought the exact same thing that motivates you to spend so much time posting to this newsgroup. > I believe that the dearth of published code demonstrates that Forth > in its present state is not a suitable foundation for published > code. I'd love to be proven wrong, but I'm not going to invest time > in trying (why don't *you*?). I think we need to fix Forth > first. But it is not completely clear to me what is required. That's the whole problem here. You have a feeling that something is wrong, but you don't know what that something is, so you thrash around grasping for ideas -- for example, "the lack of a tree-structured grammar" -- with no idea whether they're relevant or not. Andrew.
  • 3. Forth Testing Tools?
    Are there other Forth testing tools out there? I've tried using the Hayes tester a couple of times. I like the syntax and simplicity, but its failure messages are just useless. If I have to go back and insert debug statements and re-run the tests to figure out what actually went wrong, why bother using it at all? I might as well just write ad-hoc test code and shove it in a file. I want something that (at least) displays the actual and expected stack contents, and preferably something that can be extended to deal with strings or other data. I'd love to be able to do: T{ 1 2 3 => 1 5 }T T{ s" abcdef" 2 /string => s" def" }( string )T And see: T{ 1 2 3 => 1 5 }T Returned: <3> 1 2 3 Expected: <2> 1 5 T{ s" abcdef" 2 /string => s" def" }( string )T Returned: <2> $8070938 4 ("cdef") Expected: <2> $8070948 3 ("def") Anybody have something like that, or should I roll my own? --Josh

RfD: Ambiguity in FATAN2 version 1.2

Postby C. G. Montgomery » Mon, 04 May 2009 10:42:38 GMT

RfD:  Ambiguity in FATAN2  version 1.2


The ANS definition is: 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

Other computer languages which provide this function commonly specify the
"principal angle", the one between -pi and pi.


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.


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.


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


A set of tests is available at

 http://www.**--****.com/ ~williams/archive/forth/utilities/fatan2-test.fs

\ end of RfD

regards to all   cgm

Re: RfD: Ambiguity in FATAN2 version 1.2

Postby Krishna Myneni » Mon, 04 May 2009 17:56:17 GMT

Wow. This is a clever way to specify the behavior of FATAN2 without 
conditionals. The above specification guarantees that the IEEE FP 
compatible result with respect to -0E will be given by FATAN2 when a 
Forth system has all of the following attributes:

1) The Forth system supports floating point signed zero.

2) The number interpreter recognizes "-0E" correctly, and sets the 
appropriate sign in the internal representation of fp zero.

3) F~ behaves correctly for exact matching.

Yet the specification does not require the system to comply with any 
of the three attributes. Beautiful. This spec. side steps the issues 
raised during the development of the FTRUNC Rfd.


Similar Threads:

1.RfD: Ambiguity in FATAN2 version 1.1

2.RfD: Ambiguity in FATAN2

3.RfD: Ambiguity in FATAN2

On Mar 24, 10:41m,  XXXX@XXXXX.COM  (Anton Ertl)
> "C. G. Montgomery" < XXXX@XXXXX.COM > writes:
> >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 radian angle, greater than -pi and less than or equal to pi,
> >whose tangent is r1/r2.
> The C standard specifies "[-pi,pi]", i.e., greater than or equal to
> -pi.
> And on Gforth (which uses C's atan2):
> -1e 0e fatan2 f.
> outputs
> -1.5707963267949
> and I guess that Gforth is not the only one.

W32F gives the same (assuming the precision is set to 14). Since pi
cannot be represented exactly shouldn't it be the closest
approximations of pi and -pi, allowing for rounding).

> So I suggest including -pi in the range.
> - anton

George Hubert

4.Ambiguity in FATAN2

5.CfV: Ambiguity in FATAN2

6. Rich Report version 1.2 with clarion 6

7. ANN: KSpng version 1.2 released

8. RATECRYPT() Version 1.2 included below

Return to forth


Who is online

Users browsing this forum: No registered users and 73 guest