Re: Floor & Ceiling (no walls yet)
Re: Floor & Ceiling (no walls yet)
- Subject: Re: Floor & Ceiling (no walls yet)
- From: Graff <email@hidden>
- Date: Tue, 03 Feb 2004 01:19:35 -0500
There's a round command in StandardAdditions that pretty much does what
you want already. It's found the StandardAdditions dictionary under
Miscellaneous Commands. Here's the dictionary entry for it:
round: Round number to integer
round real -- the number to round
[rounding up/down/toward zero/to nearest/as taught in
school]
-- the rounding direction; if omitted, rounds to
nearest. to nearest
rounds .5 cases to the nearest even integer in order to
decrease
cumulative errors. To always round .5 away from zero,
use as
taught in school.
Result: integer -- the rounded value
So a ceiling function would be:
round -5.5 rounding up
A floor function would be:
round -5.5 rounding down
- Ken
On Feb 2, 2004, at 6:10 PM, ehsan saffari wrote:
Hi
Here is my attempt at defining Floor & Ceiling functions in
AppleScript:
Anything wrong there? Can they be improved?
----Get Ceiling of a number----
on getceil(x)
if x > 0 then
set y to (x div 1) + 1
else if x < 0 then
set y to (x div 1)
end if
return y
end getceil
----
----Get Floor of a number----
on getfloor(x)
if x > 0 then
set y to x div 1
else if x < 0 then
set y to -(1 - x) div 1
end if
return y
end getfloor
----
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.