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


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