Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Strange log behavior?

by ikegami (Pope)
on Sep 07, 2013 at 16:42 UTC ( #1052826=note: print w/replies, xml ) Need Help??

in reply to Strange log behavior?

>perl -E"say sprintf '%.20g', log (1000) / log (10)" 2.9999999999999996 >perl -E"say int( log (1000) / log (10) )" 2 >perl -E"say log (1000) / log (10) % 3" 2 >perl -E"say 2 % 3" 2

Always use a tolerance when comparing floating point numbers or converting them to integers.

Replies are listed 'Best First'.
Re^2: Strange log behavior?
by Anonymous Monk on Sep 07, 2013 at 17:27 UTC
    What is the correct way to round the floating point number to 3?

      sprintf seems to do the right thing.

      perl -E ' say sprintf q{%.0f}, $_ for 2.99999, 2.49999, 3, -2.99999, -2.49999, 5279.8012;' 3 2 3 -3 -2 5280 $

      I hope this is helpful.



        Thanks, just what I needed.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1052826]
[choroba]: Hi Corion! Where have you been?
[Discipulus]: ah! holidays i hope..
Discipulus without Corion and with choroba in another timezone the monastery was silent.. I was silbing alone in the cloister

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2017-02-22 08:39 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (325 votes). Check out past polls.