http://qs1969.pair.com?node_id=673983


in reply to ceil without ceil

I think this would be better:
sub RoundUp { $float=$_[0]; ... ..check that your input is valid here.. ... my $rounded_number=$float; if($float==int($float)){ }elsif($float>0){ $rounded_number=int($float+1); ################################### ## and optionally, depending how ## ## you want to define ceil() on ## ## a number less than 0.. ## }elsif($float<0){ $rounded_number=int($float-1); } ################################### return rounded_number; }
The code above rounds any number smaller than 9e-9 incorrectly to 0. For a lot of applications I suppose this won't make a difference, but why write a mathematical function that is not correct? It might be copied by someone else who assumes that it will work correctly in every circumstance*.
*Yes it would be a stupid assumption to make, but you can never tell..
waits for someone to point out the error in her method
why_bird
........
Those are my principles. If you don't like them I have others.
-- Groucho Marx
.......