i trying to figure out what's wrong as well so i do the following: $j = -9223372036854775808; foreach my $i (10,100,1000,10000){ $j-=$i; printf "still equal after subtracting $i: %f",$j if ($j = -9223372036854775807); print "\nbits of \$j is: ",bit_p($j),"\n"; }
print bit_p($a),"\n"; sub bit_p{ my $number = shift; my @buffer; while(1){ last unless($number); if($number & 1){ unshift(@buffer,"1"); }else{ unshift(@buffer,"0"); } $number >>= 1; } return join('',@buffer); } __END__ prints: still equal after subtracting 10: -9223372036854775800.000000 bits of $j is: 10000000000000000000000000000000 still equal after subtracting 100: -9223372036854775800.000000 bits of $j is: 10000000000000000000000000000000 still equal after subtracting 1000: -9223372036854775800.000000 bits of $j is: 10000000000000000000000000000000 bits of $j is: 10000000000000000000000000000000 as you can see even after subtracting 1000, it's still the same. if you count the number of bits in $j, it has 32. Perl is using a 32 bit address (in my OS) to store $j. the max for a 32 big integer is 2 ^ 32 which is 4294967296. after that, it overflows. if you look at the bit pattern of $j, it's a '-0' conceptually. and when you test it in the 'if' statment, it will always be ture because: if(-0 == -0){ print "equal\n"; } always prints equal. this should explain why after you subtract one from it, it's still prints ok. the overflow thingy that i mention doesn't seem to affect the following though: $i = '9'x99; #-- that's 99 digits! definitly overflow print $i+1,"\n"; #-- prints 1e+099 which is correct! i am still puzzle and searching for the right answer. david "Geeta Kathpalia" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Thanks for the reply Janek. > > If the number is converted to float, then as the result shows, the > number is truncated a bit, > from -9223372036854775808 to -9.22337203685478e+18. > If yes, then how come > printf "ok %f", $a; > still gives the correct number(without truncation). > The output is : ok -9223372036854775808.000000 > > Thanks & Regards > Geeta -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]