Date: Tue, 2 Nov 1999 22:41:50 +0000
Reply-To: John Whittington <John.W@MEDISCIENCE.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: John Whittington <John.W@MEDISCIENCE.CO.UK>
Subject: Re: ROUND Fn
In-Reply-To: <3.0.6.32.19991102162801.012d3de0@mail.binghamton.edu>
Content-Type: text/plain; charset="us-ascii"
At 16:28 02/11/99 -0500, Lary Jones wrote:
>Could be! As I said, I only demonstrated rounding of one particular value.
> I will agree that I have never seen "any cases where ROUND() goes wrong
>using a second argument which obeys" Wittington's rule ;-) I will
>stipulate that all such cases seem to work.
Well, if we're going to have a "Whittington's Rule", we might at least
spell it correctly :-) However, before anyone carves it in slabs of stone,
I wish to offer "Amendment No. 1 to Whittington's Rule" .....
" To get 'expected' functionality from the ROUND() function, the second
argument has to EITHER be a positive integer OR else, if less than 1, an
exact factor of an integral (or zero!) power of 10 "
This Amendmend has become necessary since, although second arguments such
as 0.03, 0.07 and 0.09 bring about very 'strange' results, 3, 7, 9 (or 17,
or whatever) work 'fine' - in relation to what I think one might expect of
'rounding to the nearest X'. I'm therefore beginning to wonder whether
what we have been observing relates, in some way, to the problems of
precise binary representation/handling of decimal fractions.
Also consistent with 'my rule' is the fact that, whilst 0.03 does not work,
1/30 (i.e. 0.33333...) does produce the 'expected' functionality.
In an attempt to understand what on earth is going on, I've consider how I
would seek to emulate the ROUND() function if it did not exist. If I
wanted to emulate 'y = round(x, r)', then I would code something like:
y = int(x / r + 0.5) * r ;
.. which produces exactly the same results as the ROUND() function for
those values of r which obey the 'Whittington Rule'. However, if I then
use my emulation code for values of r (like 0.03, 0.07 etc.) which do NOT
obey my 'rule', then it then DOES give me the result which (I suppose!) I
would expect - NOT the bizzare answers we're getting from the ROUND()
function ....
... so whatever algorithm the ROUND() function is using, it certainly ain't
producing as consistent results as my modest little 'emulation' above!
I think this is one of those situations in which the timely appearance of a
little birdy might be very welcome!
Regards,
John
----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Twyford Manor, Twyford, E-mail: John.W@mediscience.co.uk
Buckingham MK18 4EL, UK mediscience@compuserve.com
----------------------------------------------------------------