Re: Rfd: floating point truncation V1
- From: anton@xxxxxxxxxxxxxxxxxxxxxxxxxx (Anton Ertl)
- Date: Sat, 18 Apr 2009 16:13:49 GMT
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/
.
- Follow-Ups:
- Re: Rfd: floating point truncation V1
- From: Krishna Myneni
- Re: Rfd: floating point truncation V1
- From: Krishna Myneni
- Re: Rfd: floating point truncation V1
- References:
- Rfd: floating point truncation V1
- From: Krishna Myneni
- Rfd: floating point truncation V1
- Prev by Date: Re: Negative Zero
- Next by Date: Re: What's Forth like?
- Previous by thread: Re: Rfd: floating point truncation V1
- Next by thread: Re: Rfd: floating point truncation V1
- Index(es):
Relevant Pages
|