Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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

by eyepopslikeamosquito (Chancellor)
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.

Replies are listed 'Best First'.
Re^4: log() and int() problem
by LanX (Bishop) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1010290]
[erix]: heh, really? yeah, I suppose it may be so
[ambrus]: We're not really sure. There are some other contenders like libjpeg, and it's not easy to tell how you even measure this.
[ambrus]: But we figured it's close.
[Corion]: If you take Android as the baseline, that makes all three a likely contender

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2017-09-25 14:21 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (280 votes). Check out past polls.