Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: ceil without ceil

by why_bird (Pilgrim)
on Mar 13, 2008 at 14:48 UTC ( [id://673983]=note: print w/replies, xml ) Need Help??


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
.......

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://673983]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 04:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found