Hi

I got bitten by the fact that log is producing a float

by definition (see log )

sub log10 { my $n = shift; return log($n)/log(10); }

but

DB<36> $num = 1e12 DB<37> $log10 = log($num)/log(10) DB<38> p $log10 12 # Looks good, right? DB<39> p $log10 % 3 2 # surprise! DB<40> p int($log10) 11 # Oh one of Perl's DWIM show Float as +Integer DB<41>

instead of resorting to tricks like secretly rounding up the hidden float, is there a recommended library?

Probably POSIX something?

update

clarification, I'm interested to get the log10 of a whole number.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice


In reply to Clean log_10 ? by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.