Re: Does "rounding" work in OS 9.2.1
Re: Does "rounding" work in OS 9.2.1
- Subject: Re: Does "rounding" work in OS 9.2.1
- From: email@hidden
- Date: Wed, 31 Oct 2001 22:46:23 -0500
On Wednesday, October 31, 2001 12:12 PM, email@hidden asked,
>
I'm putting together a little script to add selection sizes in the Finder. I
>
just need a rounded integer for the size. I can't get the rounding script
>
addition to work. It is in there that I checked. This compiles fine.
>
>
set theSizeTotal to 0
>
tell application "Finder"
>
activate
>
set theSelections to every item of selection
>
repeat with theItem in theSelections
>
set itemSize to size of theItem
>
set itemSize to (itemSize / 1024 / 1024)
>
set theSizeTotal to (theSizeTotal + itemSize)
>
end repeat
>
round theSizeTotal rounding as taught in school
>
display dialog theSizeTotal - I would like this to end up an integer
>
end tell
The statement "round theSizeTotal rounding as taught in school" doesn't modify
the contents of theSizeTotal. It takes the argument, rounds it, and returns the
rounded value as its result.
Change that statement to read, "round theSizeTotal rounding as taught in school
returning theSizeTotal" to get what you want.
And, as a member of IEEE, I urge you to use the IEEE rounding rules, by calling
just "round theSizeTotal" rather than "rounding as taught in school." Under the
IEEE rules, exact 1/2 values round to make the result even, rather than always
rounding up. (That is, 1.5 rounds up to 2, but 4.5 rounds down to 4. Of
course, if its not exactly 0.5, the rounding goes to the nearest number: 4.51
rounds to 5, 1.49 rounds to 1). The IEEE rules make the average rounding error
zero, while rounding up produces a bias to the average rounding error. This
rounding mode is what is implemented in hardware in the PowerPC chip.
"For most numerical applications the best policy appears
to be the rounding scheme which insists that the least
significant digit should always be made even when an
ambiguous value is rounded. This is not a trivial technicality,
of interest only to nit-pickers; it is an important practical
consideration, since the ambiguous case arises surprisingly
often and a biased rounding rule produces significantly poor
results. "
--Knuth, Semi-Numerical Algorithms, 1981, pp. 221-222.)
And realize that by dividing by 1024 * 1024, you get an answer in units of
"mebibytes." That's the new IEEE "binary metric" prefixes. Despite the usage
of computer people, IEEE, ANSI, NIST, IEC, and CIPM insist that kilo- means 1000
and mega- means 1 000 000.
http://physics.nist.gov/cuu/Units/binary.html
http://www.iec.ch/tclet6.pdf
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden