Subject: | possible as_hex() bug? |
## as_hex() bug? $x is divided by 16 (shifted by a hex digit) and copied
## to $y. $y->floor()->$as_hex() should show remaining hex digits but
## doesn't. $y appears to be correct BigFloat value, so error seems
## to be in as_hex() ...
##
## Script returns:
## x = 18441921395236213128, 0xffeeddccaabb1188
## y = 1152620087202263320, as_hex=0xffeeddccaaba420,
## should be=0xffeeddccaabb118
use bignum;
$x = 0xffeeddccaabb1188;
printf( "x = %s, %s\n",$x, $x->as_hex() );
$x = $x/16;
$y = $x->copy()->bfloor();
printf( "y = %s ,as_hex=%s, should be=%s\n",$y,$y->as_hex(), my_hex($y) );
exit;
sub my_hex {
my($num) = @_;
my $blog = $num->copy()->blog(16)->bfloor();
my $ret = "0x";
for (my $j = $blog; $j >= 0; $j--){
my $mypow = 16**$j;
for (my $i = 15; $i >=0 ; $i--){
$mytry = $mypow*$i;
next if ( $mytry > $num );
$num = $num - $mytry;
$ret .= sprintf("%x",$i);
last;
}
}
return $ret;
}
__END__
C:> perl -v
This is perl, v5.8.4 built for MSWin32-x86-multi-thread
(with 3 registered patches, see perl -V for more detail)
Copyright 1987-2004, Larry Wall
Binary build 810 provided by ActiveState Corp. http://www.ActiveState.com
ActiveState is a division of Sophos.
Built Jun 1 2004 11:52:21