• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Floor & Ceiling (no walls yet)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Floor & Ceiling (no walls yet) (From: ehsan saffari <email@hidden>)

  • Prev by Date: Re: Floor & Ceiling (no walls yet)
  • Next by Date: Re: Floor & Ceiling (no walls yet)
  • Previous by thread: Re: Floor & Ceiling (no walls yet)
  • Next by thread: Re: Floor & Ceiling (no walls yet)
  • Index(es):
    • Date
    • Thread