Why don't you use Lisp "ratios" instead of "floating point" numbers? You
would then have exact arithmetic and the rounding problem would not exist.
Maybe "ratios" are too slow?
Mike Gardner
Symbionics Instruments Ltd
----------
From: Peter <tip.nl] at Schotman[SMTP:schotman>
Sent: 09 December 1996 08:15
To: <cs.berkeley.edu at allegro-cl>
Subject: rounding question
Hi,
I developped some functions to carry out interval arithmetic in common
lisp (Franz inc.'s Allegro CL 3.0 for Windows95).
E.g. [a,b] + [c,d] = [a+c, b+d], etc.
However I would like to calculate safe bounds (outward rounding), that
is rounding a+c downward and b+d upward. In C you can use some
(assambler) functions to change the last bit, which depends of course on
the precision chosen (e.g. doubble) and is also machine dependant. How
can I do something like this in lisp?
The four functions (ROUND, TRUNCATE, FLOOR, CEILING) do not provide
what I would like. To explain a little further, consider the following
example it interval arithmetic:
[5.0, 7.0] / [3.0, 3.0] = [1.666666666666... , 2.3333333333333....]
Safe rouding requires that I round the above result to:
[1.666...66 , 2.333...34]
That is: the lower element in the interval downward and the higher
element upward, at some precision (e.g. 16 digits). A cannot substract
respectivily add a simple constant (e.g. 0.0000000000000005) or use the
rouding functions because I don't know what the order/size (e.g. 1.66En,
where n is an integer) of the number will be. First one must determine a
correct divisor (here lies the trouble), before one is able to use the
standard rounding functions, in this case the divisor varies.
Additionally, rounding it must be VERY fast, since it must be carried
out after every computation.
Any ideas?
Thanks in advance,
Peter Schotman
PS Some of you may have read the first part of this question in
comp.lang.clos