Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: log() and int() problem

by eyepopslikeamosquito (Canon)
on Dec 25, 2012 at 22:40 UTC ( #1010290=note: print w/ replies, xml ) Need Help??


in reply to Re^2: log() and int() problem
in thread log() and int() problem

I solved my issue with adding and subtracting 1 from the returned value
Sorry, but that's a terrible "solution". Your example floating point inaccuracy happens to be slightly greater than three. Since the int function truncates, consider what happens if the inaccuracy happens to be slightly less than three. Though a crude fix would be to add 0.5 (i.e. int($l+0.5) instead of int($l)), the perl documentation advises against using int for rounding and suggests sprintf and the POSIX floor and ceil functions as sounder alternatives.

Still don't understand why you don't go with moritz's solution.


Comment on Re^3: log() and int() problem
Select or Download Code
Re^4: log() and int() problem
by LanX (Canon) on Dec 25, 2012 at 23:19 UTC
    > Though a crude fix would be to add 0.5 (i.e. int($l+0.5)

    I think you rather meant something like $ll=int($l+5e-15) =)

    (15 digits accuracy is just a guess)

    Cheers Rolf

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (13)
As of 2014-10-30 16:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (208 votes), past polls