From:

Date:

July 23, 2001 13:57Subject:

Re: [ID 20010723.001] perl 5.6.1: BigInt booleans cannot handle negativesMessage ID:

perl.perl5.porters-40816@nntp.perl.org-----BEGIN PGP SIGNED MESSAGE----- Moin Bryce, >And, Or, and Xor on two positive BigInts seem to work ok. However, if you >throw in a negative operand you get some very strange behavior. I'm >assuming that you would like integer math and bigint math to be compatible >here, but even without that assumption BigInt is still buggy. Here is a >testing script which runs on perl 5.6.1. (It uses booleans on a BigInt so >only recent perls will run it at all.) > >use Math::BigInt; >@list = (-65536, -65535, -1, 0, 1, 65535, 65536); >foreach $x (@list) { > foreach $y (@list) { > $a = $x & $y; > $b = (Math::BigInt->new($x)) & (Math::BigInt->new($y)); > if ($a != $b) { > print "MISMATCH:\n"; > print "$x AND $y = $a (integer math)\n"; > print "$x AND $y = $b (BigInt math)\n"; > } > } >} > >The problem seems to be that the BigInt boolean functions do not sign >extend negative numbers when they are breaking them into chunks with bdiv. > >This job would be easy if the numbers were stored in a base that is a >power of 2 instead of a power of 10. (Then you could do left and right >shift without dividing as well...) > >Thank you, >Bryce Denney Thank you for your bug-report. While the problem with negatives should be probably addressed in the latest version (v1.38, and v1.39 imminent), my local v1.39 shows another bug: it loops forever. I will fix this ASAP. Best regards, Tels - -- perl -MMath::String -e 'print \ Math::String->from_number("215960156869840440586892398248"),"\n"' http://bloodgate.com/thief/ Thief - The Dark Project http://bloodgate.com/perl My current Perl projects http://freedomforlinks.de Fight for your right to link. PGP key available on http://bloodgate.com/tels.asc or via email -----BEGIN PGP SIGNATURE----- Version: 2.6.3i Charset: latin1 iQEVAwUBO1xyJ3cLPEOTuEwVAQEZqAf+PdeC+FPEVwtXNEYGzUAtbDgNZ5Pcs95I 6HTxmnrH4wZAIXS3nlc5V4UOm4QF+05178rE2qn+CzHzImu1ArJUv+RrolAMtvhs Dv+GXHancWtCB6EbSt5NaYD1A3b2LtNEPZxoKwk4Eu6Yvemc76TuPuYZIA0PZxdj 62SD8pUjNrF4lUocZGshFQ+KhNUjgZS5x8g+IkuahEwQPYxyQUt11J0CcqSbv0m6 G7lpOVqNh4AOgc7kRd1UoLt0faj/fwz4tsCfk//OtKTSXRVxSsF+jSlal+An+whO hf53W+OOfk5vWPV8WsHSYc6a1B6JbbfSAT4KinixcUkG+5KtY96cZw== =Uf6/ -----END PGP SIGNATURE-----Thread Previous

- [ID 20010723.001] perl 5.6.1: BigInt booleans cannot handle negatives by Bryce Denney
**Re: [ID 20010723.001] perl 5.6.1: BigInt booleans cannot handle negatives**by Tels

nntp.perl.org: Perl Programming lists via nntp and http.

Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About