Re: Floor & Ceiling (no walls yet)
Re: Floor & Ceiling (no walls yet)
- Subject: Re: Floor & Ceiling (no walls yet)
- From: Andrew Oliver <email@hidden>
- Date: Mon, 02 Feb 2004 19:55:56 -0800
You need to check for integer values:
getceil (5) --> 6
getfloor (-5) --> -6
And you need to check for 0:
getceil (0) --> error: the variable y is not defined
I don't know if you're checking prior to calling these functions (in which
case you may be OK), otherwise you need to add that check to the functions.
on getceil(x)
set y to x as integer
if x is not equal to y then
if x > 0 then return y + 1
if x < 0 then return y - 1
end if
return y
end getceil
Andrew
:)
On 2/2/04 3:10 PM, "ehsan saffari" <email@hidden> 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
>
----
>
>
Thanks for any comments
>
>
cheers
>
ehsan
>
_______________________________________________
>
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.
_______________________________________________
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.