LanX has asked for the wisdom of the Perl Monks concerning the following question:
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?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Clean log_10 ?
by pryrt (Abbot) on Nov 28, 2019 at 16:53 UTC | |
by LanX (Saint) on Nov 28, 2019 at 17:04 UTC | |
|
Re: Clean log_10 ?
by Eily (Monsignor) on Nov 28, 2019 at 16:57 UTC | |
by LanX (Saint) on Nov 28, 2019 at 17:15 UTC | |
by dave_the_m (Monsignor) on Nov 28, 2019 at 19:48 UTC | |
by LanX (Saint) on Nov 28, 2019 at 20:17 UTC | |
|
Re: Clean log_10 ?
by davido (Cardinal) on Nov 28, 2019 at 18:22 UTC | |
|
Re: Clean log_10 ?
by haj (Vicar) on Nov 28, 2019 at 19:10 UTC |