On Nov 13, James Edward Gray II said:

>On Nov 13, 2003, at 9:50 AM, Bob Showalter wrote:
>
>> Mike Blezien wrote:
>>> Hi,
>>>
>>> Ran accross a function called "ceil" and from the information I got
>>> on this:
>>>
>>> "ceil() [Stands for ceiling], it just rounds a float value up.. so
>>> ceil(4.7) == ceil(4.1342) == 5"
>>>
>>> would this be the same as using "int" function in perl
>>
>> No. int() simply drops the fractional part.
>
>ceil() is often presented with a sister function called floor().  That
>would be the same as Perl's int().

No, int() is neither exactly like ceil() or floor().  All int() does is
truncate the number to an integer.  If you have 2.3, you get 2.  If you
have 2.9, you get 2.  If you have -2.3, you get -2.  If you have -2.9, you
get -2.  If you were to write int() as a function of ceil() and/or
floor(), you'd have to say:

  sub int { my $x = shift; $x > 0 ? floor($x) : ceil($x); }

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to