Re: Rfd: floating point truncation V1



Krishna Myneni <krishnamyneni@xxxxxxxxxxxxx> writes:
FTRUNC
f-trunc FLOATING
( F: r1 -- r2 )

Round r1 to an integral value using the "round towards zero" rule, giving r2.

Ok. Some other standard I looked at (C99?) makes "round towards zero"
more explicit, but your approach appears clear enough to me, so its
shortness is a bonus.

Forth systems supporting floating-point signed zero, i.e. systems which provide
an internal representation of floating point negative zero, "-0E", which differs
from the representation of floating point positive zero, "0E", should return r2
as floating point negative zero for r1 in the open interval (-1, 0).

That's quite complex, and mostly useless. Programs cannot test for
this, and therefore cannot rely on this behaviour. Better put this in
a separate negative-zero extension (a better alternative seems to be
to go for an IEEE FP extension). Also, if you define a negative-zero
extension explicitly somewhere, almost three of these four lines can
be replaced with "If the system provides the X:negative-zero
extension" or "If the system provides the X:ieee-fp extension".

BTW, please use ~70-character lines, and don't use comb-style line
wrapping (which occured elsewhere in your posting).

Testing
=======

a) Systems which do NOT provide support for floating point signed zero:
....
b) Systems which support floating point signed zero:
....

This split reflects the fact that the proposal actually tries to
"standardize" two different behaviours (which is not really
standardization). If you proposed one behaviour with a queryable
extension, you could have one set of tests; that set would contain a
query for the extension, and, if present, perform additional stricter
tests. E.g.:

t{ -1E 1E-5 F+ FTRUNC 0e 1e-8 F~ -> true }t
s" X:ieee-fp" environment? [if]
t{ -1E 1E-5 F+ FTRUNC -0e 0e F~ -> true }t
[then]

Or, alternatively, let the query influence the setting of the comparison:

s" X:ieee-fp" environment? [if]
set-exact
[else]
set-near
[then]
t{ -1E 1E-5 F+ FTRUNC 0e 1e-8 F~ -> true }t

However, since this is about some basic functionality with an optional
extension, there is something to be said for doing the test for the
basic functionality even in the optional case (and then the test for
the optional extension).

-4.1E FTRUNC -4E F= . \ -1

F= is not a standard word.

c) Automated tests using ttester.fs

That's the ones we want to have for the document and for the test
collection. However, such test should also be there for the basic
behaviour.

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2009: http://www.euroforth.org/ef09/
.



Relevant Pages

  • Cfv: Floating point truncation
    ... RfD: Floating point truncation ... which, respectively, provide rounding to the nearest integer, and rounding to the nearest integer on the side of the number line towards negative infinity. ... ANS Forth does not provide a word for rounding towards zero, and returning a floating point representation of the resulting integer. ... Include a standard word, named "FTRUNC", to perform "truncation", i.e. rounding of a floating point number towards zero, returning a floating point representation of the resulting integer. ...
    (comp.lang.forth)
  • Re: Need modern version of old technique to show missing values
    ... The above-mentioned R has the symbol "NA" to indicate missing values, ... distinguished from the usual IEEE754 floating point special values ... negative zero. ... seem determined to use an older standard this option is of course not ...
    (comp.lang.fortran)
  • Re: Rfd: FNEGATE specification for signed zero
    ... The ANS Forth standard does not currently specify the behavior of FNEGATE for floating point zero on systems which support floating point signed zero. ...
    (comp.lang.forth)
  • Re: Rfd: FNEGATE specification for signed zero
    ... The ANS Forth standard does not currently specify the behavior of ... FNEGATE for floating point zero on systems which support floating ...
    (comp.lang.forth)
  • u=0 for FILL etc. (was: gforth -- u+do)
    ... unlike zero arguments to MOVE and FILL. ... the right thing in this case, and a proper standard ... some committee members may claim that adding this extension to ...
    (comp.lang.forth)