This is called a Ceiling function.  The opposite, where you want to lop off 
the non-integer part is called a Floor function.

Looking in my Math library of code, I see that my Floor and Ceiling 
functions aren't correct, so let's see....

I just leveraged the working Floor function to create the Ceiling 
function.  This is hopefully a little easier to read that a huge string of 
math operations (I'll leave it to someone else to test which is faster).

--------------------------------------------------------------------------
-- Floor & Ceiling v1.1
-- 020607 [EMAIL PROTECTED]
-- Director 8.5

-- USAGE/DESCRIPTION:
--   Floor (round any non-integer down) and Ceiling (round any non-integer 
up) fn's
--   returns the integer value
-- REQUIRES:
--   nothing
-- CAST CONVENTIONS:
--   none
-- SCORE CONVENTIONS:
--   none
-- USEFUL MESSAGES:
--   Floor(float)
--   Ciling(float)
-- PARAMETERS:
--   none
-- OWNER:  roymeo
-- HISTORY/NOTES:
--  010426-roymeo  v1.0  from [EMAIL PROTECTED]
--  020607-roymeo  v1.1  corrected ceiling function in response to Lingo-L 
question

-- PROPERTIES
--none

-- HANDLERS
on floor x
   return integer(x - .5)
end

on ceiling x
   if x <> integer(x) then
     return (floor(x) + 1)
   else
     return integer(x)
   end if
end
--------------------------------------------------------------------------



At 10:01 AM 6/5/2002 -0700, you wrote:
>if x > integer(x) then x = x+1
>
>Colin Holgate wrote:
> >
> > >put integer(1.9 + 0.5)
> > >-- 2
> > >
> > >Regards,
> > >Pranav Negandhi
> >
> > Unfortunately that would not work out:
> >
> > put integer(1.0 + 0.5)
> > -- 2
> >
> > The goal was to let 1.0 be 1.
> >
> > Here's something that does work, but I feel sure there's something
> > simpler (it can be simpler in two lines, but just for the fun of it
> > I'm trying one line):
> >
> > put n - (n - integer(n-.5)) + 1 * ((n - integer(n-.5))>0)
> >
> > It may take a moment or two to see why it works.
> >
> > [To remove yourself from this list, or to change to digest mode, go to 
> http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
> [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L 
> is for learning and helping with programming Lingo.  Thanks!]
>[To remove yourself from this list, or to change to digest mode, go to 
>http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
>[EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L 
>is for learning and helping with programming Lingo.  Thanks!]

[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to