in reply to log() and int() problem
when using Data::Dumper you will see that $l is seen as a string not an integer
print "LOG == ",$l,Dumper \$l,"\n";
prints
LOG == 3$VAR1 = \'3';
As others pointed out log only returns floats up to certain precision, which IIRC also depends on the current implementation of Perl (that is compiling options). And internally floats are stored in the string-slot of a variable.
That means the slight calculation error might be too small to be shown by a print but is still sufficient to let == fail. Even if print would show the discrepancy, your approach wouldn't always work.
So better go the other way round and check if 125 == 5**$x with $x=int($l+$tolerance)
EDIT: The approach Moritz updated into his post is even better.
Cheers Rolf
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: log() and int() problem
by dave_the_m (Monsignor) on Dec 25, 2012 at 18:34 UTC | |
by LanX (Saint) on Dec 25, 2012 at 18:49 UTC | |
Re^2: log() and int() problem
by Anonymous Monk on Dec 25, 2012 at 21:03 UTC | |
by eyepopslikeamosquito (Archbishop) on Dec 25, 2012 at 22:40 UTC | |
by LanX (Saint) on Dec 25, 2012 at 23:19 UTC | |
by LanX (Saint) on Dec 25, 2012 at 21:11 UTC |
In Section
Seekers of Perl Wisdom