http://www.perlmonks.org?node_id=1010290


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 (Saint) 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