Loading ...
Sorry, an error occurred while loading the content.

RfD: S>F and F>S First Revision

Expand Messages
  • offnoder
    RfD: S F and F S version 1.1 First Revision 09 April 2012 Charles G. Montgomery Discussions in response to the original version of
    Message 1 of 1 , Apr 10 12:32 PM
    View Source
    • 0 Attachment
      RfD: S>F and F>S
      version 1.1 First Revision 09 April 2012
      Charles G. Montgomery <cgm@...>

      Discussions in response to the original version of this proposal
      have largely concentrated on the issue of whether it is good or bad to
      specify the behavior of the proposed word F>S in terms of the specified
      behavior of other words. I recognize valid points made on both sides
      of this issue; I fail to find either side overwhelmingly persuasive.

      So this revision, in addition to some other minor improvements,
      provides two alternative specifications, labeled A) and B) below,
      I have moved the "Remarks" section for each next to the corresponding
      "Proposal" section.

      I, myself, don't really care which is preferred. As a user, I would
      like to see standardization of these two words. (As a user of floating
      point I know I will always need to check whether peculiarities of an
      implementation need to be corrected for in order to get the right
      answers, but no Standard will relieve me of that burden.)

      I, myself, would oppose any form of specification which adds new
      requirements on what particular implementation of floating-point
      is used by a standard system providing these words.

      Problem

      It is not uncommon in forth programs using floating point to need to
      convert a single-cell value to its floating point representation, or
      the reverse, for further use. While this is possible using the standard
      words S>D D>F F>D and D>S , it can be inconvenient, and may result in
      inefficiency by forcing a conversion to double numbers, particularly
      on systems with a large cell size. Many systems which provide floating
      point support already include CODE definitions to accomplish these
      tasks. It may be useful for the Standard to include specifications
      for words to provide these capabilities.

      Proposal

      Add two words to the Floating Extension wordset:

      S>F "s-to-f" ( n -- ) ( F: -- r ) or ( n -- r )
      r is the floating-point equivalent of the single-cell value n.

      A)
      F>S "f-to-s" ( -- n ) ( F: r -- ) or ( r -- n )
      n is the less significant portion of the double word that would be
      produced by the word F>D applied to the floating-point value r.
      An ambiguous condition exists if applying F>D to r would result in
      an ambiguous condition.

      Specifying F>S in terms of the behavior of F>D should prevent any
      ambiguity that isn't already present in F>D, and inherit its
      freedom from overspecification. It should ease the task of adding
      these words to a system that doesn't already provide them but does
      include the floating-point word set. Of course it's an
      "as if" specification. The value n is what would result from
      executing F>D D>S , although it need not be obtained that way.

      B)
      F>S "f-to-s" ( -- n ) ( F: r -- ) or ( r -- n )
      n is one of the single-cell values that corresponds to the floating-
      point value r. If more than one integer corresponds to r in the
      particular implementation of integer and floating-point values
      provided by the system, it is implementation-dependent which of them
      is returned. A program which relies on a specific choice must
      declare an environmental dependency (or include code to guarantee
      the desired result, for example by using words like FLOOR or FROUND
      before F>S .)
      An ambiguous condition exists if the floating point representation
      in use does not specify an corresponding integer (for example, NAN
      or INF or some such).

      This form of specification is even less precise than the previous,
      since it provides no requirement of consistency in the behavior of
      the two similar words F>D and F>S , which might be considered either
      an advantage or a disadvantage. It seems to be consistent with the
      general disinclination to restrict floating-point implementations,
      as expressed in Section 12.3.1.2.

      Remarks

      In practice, S>F is used much more often than F>S .

      Reference implementation

      ANS versions could be
      : S>F S>D D>F ;
      : F>S F>D D>S ;

      Experience

      The Forth Scientific Library utility files provide high-level
      definitions for these words, so they are available in some form
      in any system that provides the FSL.

      Besides this, systems that already provide the words include
      VFX, Gforth, bigForth, 4tH. I'm sure there are others.

      \ end of RfD
    Your message has been successfully submitted and would be delivered to recipients shortly.