[olug] Perl Mongers Mtg: Bug Hunt: Jay's IP subnet calculator

Jay Hannah jay at jays.net
Thu Dec 11 05:47:20 UTC 2003


On Thursday, December 4, 2003, at 12:56 PM, Miller, Scott L (Omaha 
Networks) wrote:
> It works fine on my box, running 5.6.1.  I'd first question the 
> accuracy of the log functions especially with the division thrown in.  
> Floating point math likes to return things like 13.99999 or 14.00001.  
> If that function returns 13.999999, then the integer would become 13 
> instead of 14.  If this is the problem, you might want to add a 
> significantly small enough number before taking the int to take care 
> of the problem. (like 0.001 or so, figuring out what is significantly 
> small enough left as an excersize to the reader).

Ya. On line 88 I changed

    my $exp = int(log_base2($r));

to

    my $exp = sprintf("%.0f", log_base2($r));

and the problem went away.

What killed me in the debug was this:

    perl -le 'my $j = (log 16384) / (log 2); print "$j " . int($j)'

On my system that prints "14 13". Everyone else gets "14 14".

I spent an hour on EFNet #perl learning that print rounds scalars. I 
didn't know that. I thought if you calculated 13.9999999999 in a scalar 
a print statement would always print 13.999999999999. It doesn't 
(always). On my system it prints "14".... I've got a huge EFNet log of 
discussion if anybody wants it.

Should be an interesting meeting Tuesday!

Cheers,

j



More information about the OLUG mailing list