Skip Menu |

This queue is for tickets about the Math-BigInt CPAN distribution.

Report information
The Basics
Id: 21413
Status: resolved
Priority: 0/
Queue: Math-BigInt

People
Owner: TELS [...] cpan.org
Requestors: peter.john.acklam [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.77
Fixed in: 1.78



Subject: blsft() and brsft() totally screwy
I categorized this as a critical bug since a math module is unreliable, and thus for many purposes useless, if the results are so erroneous as those below: Math::BigInt::VERSION is 1.77 Math::BigFloat::VERSION is 1.51 perl is v5.8.7 built for cygwin-thread-multi-64int The following works as expected: $ perl -MMath::BigFloat -wle \ 'print Math::BigFloat->new(shift)->blsft(0, 10)' -- '31.4159365' 31.4159365 The following also works as expected: $ perl -MMath::BigFloat -wle \ 'print Math::BigFloat->new(shift)->blsft(1, 10)' -- '31.4159365' 314.159365 The following should print '3.14159365': $ perl -MMath::BigFloat -wle \ 'print Math::BigFloat->new(shift)->blsft(-1, 10)' -- '31.4159365' 3 The following works fine, sort of, but appends a trailing zero: $ perl -MMath::BigFloat -wle \ 'print Math::BigFloat->new(shift)->brsft(0, 10)' -- '31.4159365' 31.41593650 The following should print '3.14159365', but is really screwy (note the TWO decimal separators): $ perl -MMath::BigFloat -wle \ 'print Math::BigFloat->new(shift)->brsft(1, 10)' -- '31.4159365' 3.141593651.4159365 The following should print '314.159365', but is also screwy: $ perl -MMath::BigFloat -wle \ 'print Math::BigFloat->new(shift)->brsft(-1, 10)' -- '31.4159365' 3000.02
Subject: Re: [rt.cpan.org #21413] blsft() and brsft() totally screwy
Date: Sun, 10 Sep 2006 15:45:58 +0200
To: bug-Math-BigInt [...] rt.cpan.org
From: Tels <nospam-abuse [...] bloodgate.com>
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 - -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Moin, On Sunday 10 September 2006 14:54, Peter John Acklam via RT wrote: Show quoted text
> Sun Sep 10 08:54:57 2006: Request 21413 was acted upon.
[snip] Show quoted text
> I categorized this as a critical bug since a math module is unreliable, > and thus for many purposes useless, if the results are so erroneous as > those below: > > Math::BigInt::VERSION is 1.77 > Math::BigFloat::VERSION is 1.51 > > perl is v5.8.7 built for cygwin-thread-multi-64int > > The following works as expected: > > $ perl -MMath::BigFloat -wle \ > 'print Math::BigFloat->new(shift)->blsft(0, 10)' -- '31.4159365' > 31.4159365 > > The following also works as expected: > > $ perl -MMath::BigFloat -wle \ > 'print Math::BigFloat->new(shift)->blsft(1, 10)' -- '31.4159365' > 314.159365 > > The following should print '3.14159365': > > $ perl -MMath::BigFloat -wle \ > 'print Math::BigFloat->new(shift)->blsft(-1, 10)' -- '31.4159365' > 3
I do not get why you think that shifting by a "negative" amount is supported :-D It clearly is not documented to be that way. (I can understand that you would expect the result, tho) Show quoted text
> The following works fine, sort of, but appends a trailing zero: > > $ perl -MMath::BigFloat -wle \ > 'print Math::BigFloat->new(shift)->brsft(0, 10)' -- '31.4159365' > 31.41593650
Actually, it doesn't. perl -MMath::BigFloat -wle 'print scalar \ Math::BigFloat->new(shift)->brsft(0, 10)' -- '31.4159365' The reason is that print calls brsft() in list context, and brsft() does seem to call bdiv() in list context, too: sub brsft { ... $x->bdiv($n->bpow($y),$a,$p,$r,$y); } There probably should be a "scalar" before that call to bdiv. The "0" is appended due to (from the POD): =item bdiv The following will probably not do what you expect: print $c->bdiv(123.456),"\n"; It prints both quotient and reminder since print works in list context. Also, bdiv() will modify $c, so be carefull. You probably want to use print $c / 123.456,"\n"; print scalar $c->bdiv(123.456),"\n"; # or if you want to modify $c instead. :) Show quoted text
> The following should print '3.14159365', but is really screwy > (note the TWO decimal separators): > > $ perl -MMath::BigFloat -wle \ > 'print Math::BigFloat->new(shift)->brsft(1, 10)' -- '31.4159365' > 3.141593651.4159365
Same "bug" again. Show quoted text
> The following should print '314.159365', but is also screwy: > > $ perl -MMath::BigFloat -wle \ > 'print Math::BigFloat->new(shift)->brsft(-1, 10)' -- '31.4159365' > 3000.02
Same "bug". It returns "300", tho, so shifting by negative amounts could use some correction. Negative amounts of shifting should probably either be supported, or disallowed. They certainly werent expected when I wrote the code. I do not have much time right now, holidy coming up etc. It might be that I will not be able to look into these issues before 2006-10-10 :/ (I fixed the scalar issue in my local copy of v1.78, see http://Bloodgate.com/perl/packages/devel/Math-BigInt-1.78.tar.gz for a snapshot) Thank you for your report! All the best, Tels - - -- Signed on Sun Sep 10 15:25:35 2006 with key 0x93B84C15. Visit my photo gallery at http://bloodgate.com/photos/ PGP key on http://bloodgate.com/tels.asc or per email. "Given enough time, all legal battles in the tech industry will invoke the DMCA. This generally means that all constructive arguments have ended." NialScorva's law - - -- Signed on Sun Sep 10 15:37:28 2006 with key 0x93B84C15. Visit my photo gallery at http://bloodgate.com/photos/ PGP key on http://bloodgate.com/tels.asc or per email. "Retsina?" - "Ja, Papa?" - "Warp 3." - "Is gut, Papa." - -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iQEVAwUBRQQVlncLPEOTuEwVAQI0Kwf+IOhUoTnI4NZRXovuPo1Hn60KkO/rfKk+ 8H9voiVYR3Fpw3f3pLGcoEwzRKh9g/OJoFyh9F/eOJ8iEAcE9YSDOZOlgCyp8SOW con6+EK2Gw6NqqBpGHGYcb5o06nC3cZ5FyO5zFsqp+nGQvDnNaVYBDaqgZDxscWo bErcod7D9qBraAniHDsimH1Y0DMJ1o+EapqXP/LgP33T8AVNCkqsKuFHiYYGYwXi tktoEl6wnkO8RpqT2iWrkD31Ox98Vx/jWbrNA3GoBKvgFntBr0D7gBVlDs8Y2Tkw 4xJ1/5a9EVbEO3wWUYonV4f6gxS39gybTTCSOv4iyUYvbOOG4gOJHg== =sWrR - -----END PGP SIGNATURE----- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iQEVAwUBRQQXFncLPEOTuEwVAQLHcAf+MFNYqnf3+JOWNxGfVzEIP4y0CJYOfYYv m6CT2ZIW7iqkiDSULjercA5xb113yYMdOWGcx3e5nmUu/uLMxyzvTJWB+XMXE+Op 5tb6twPOwW7sc0+xOf7fkR1IRIAx08ESNEKKto/euv8LVkeh/UZXcXTcKRfbNIrr 2+UxUmFB1zaPJ3wVvRSEgDpWHBPhmOE4RFJMzpRvrVQHrCF2hPxyFjthd4F0xv8R xMBgXKLgKrzvQzt2LWXBYNEts3W05HPCf6kLathJPf+KrQTBbqsIezkdAy8BMNIC 8ORLyuDz3jWJEYSWDid9GmM1ZiwsZ0z/oBajBoxfq2kEc5NV8Q979A== =9rFL -----END PGP SIGNATURE-----
Subject: Re: [rt.cpan.org #21413] blsft() and brsft() totally screwy
Date: Sun, 10 Sep 2006 16:13:24 +0200
To: bug-Math-BigInt [...] rt.cpan.org
From: Tels <nospam-abuse [...] bloodgate.com>
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Moin, On Sunday 10 September 2006 15:44, nospam-abuse@bloodgate.com via RT wrote: Show quoted text
> Queue: Math-BigInt > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=21413 >
> > The following works fine, sort of, but appends a trailing zero: > > > > $ perl -MMath::BigFloat -wle \ > > 'print Math::BigFloat->new(shift)->brsft(0, 10)' -- '31.4159365' > > 31.41593650
> > Actually, it doesn't. > > perl -MMath::BigFloat -wle 'print scalar \ > Math::BigFloat->new(shift)->brsft(0, 10)' -- '31.4159365' > > The reason is that print calls brsft() in list context, and brsft() does > seem to call bdiv() in list context, too: > > sub brsft > { > ... > $x->bdiv($n->bpow($y),$a,$p,$r,$y); > } > > There probably should be a "scalar" before that call to bdiv.
Actually, there shouldn't because the doc say (in the synopsis): $x->brsft($y); # right shift # return (quo,rem) or quo if scalar I took the "scalar " out again. (It remains in bpow() since that isn't supposed to return the reminder only in one case) Thank you for your report! Best wishes, Tels - -- Signed on Sun Sep 10 16:12:02 2006 with key 0x93B84C15. Visit my photo gallery at http://bloodgate.com/photos/ PGP key on http://bloodgate.com/tels.asc or per email. "We're confident that DNF will be one of the greatest, if not the greatest, game of 1998. And this confidence is not misplaced." -Scott Miller, 1997 (http://tinyurl.com/6m8nh) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iQEVAwUBRQQdhHcLPEOTuEwVAQL7GAf+P0LedRs6ztqBrthQIDc5BRS2p585f32+ Rq3BdU75Ic+F3Q8SDro10MFjJ/Hog9Cr+KQx/0LevGjQxvKn2F2TJ9ubyUj2LElV cVbVihliBeB7vycBbNsUaem7tB9BAJkHCTlm57jEGTEprU/tdYRIUwk8ypYyEpAd 7/2RsFuCuOwHGSvP452Lz85BZk93p+6D7zlfZh/iN9BjoIrPqBvvM8oTHBMmfAtC Dtox7CgmLHJH1EX3PQCyV+oVhpRaHjoYBTpJ5bCJmqLW0WahMEwR/Hr6wa4Dwvlq fvceX9FkamYugQU3aqfENFinLoiy/PBCtNgEkBpVr9CG91HGASd41Q== =+VLc -----END PGP SIGNATURE-----
Subject: Re: [rt.cpan.org #21413] blsft() and brsft() totally screwy
Date: Sun, 10 Sep 2006 16:28:09 +0200
To: bug-Math-BigInt [...] rt.cpan.org
From: Tels <nospam-abuse [...] bloodgate.com>
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Moin, I updated the documentation under CAVEATS to avoid the gotcha! with the "appended 0" and the similiar issues you reported. I also made brsft() and blsft() call the other one on negative amounts. perl -MMath::BigFloat -wle \ 'print Math::BigFloat->new(shift)->brsft(-1, 10)' -- '31.4159365' prints now: 314.159365 Can you please try the updated snapshot and see if that fixes all your issues? http://bloodgate.com/perl/packages/devel/Math-BigInt-1.78.tar.gz All the best, Tels - -- Signed on Sun Sep 10 16:26:31 2006 with key 0x93B84C15. Visit my photo gallery at http://bloodgate.com/photos/ PGP key on http://bloodgate.com/tels.asc or per email. Q: "Dr. Fisher, how did you begin your great career in Contact Dermatology?" Dr. Alexander Fisher: "I started from Scratch!" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iQEVAwUBRQQg+XcLPEOTuEwVAQKlmgf9HY15/BcwB3p/7qWesb++VwVlByXUYick 6tD/oRaCjzh/rI0LzynMeyny+wQSLT44XTRX1HfuTqyyYdiemvOTiaDGPI1BsT5q /hhIH16VvRn/Rth6Xs1OenpD2qVkTFNzVP43H6BAhqbvQ9nrQF5HGvgolj0pKWoi kK25EP6ysFNfuF2/2g67X24KhQ064VgM76TDgRuXpaE+IgtByT7u/OfacPA61Mx3 1JE0bd9tDHpoh4QM68yDSxDaHYrjciXYTTRHlLM2duelkQIgI2GByPQKdt5yzsgV yAdbJxDTtOaXxUHJ8yj75r0csDniOlFPHvarqOHGkW6a+XFFDHWxRw== =YeGZ -----END PGP SIGNATURE-----
From: pjacklam [...] online.no
nospam-abuse@bloodgate.com wrote: Show quoted text
> I do not get why you think that shifting by a "negative" amount is > supported :-D It clearly is not documented to be that way. (I can > understand that you would expect the result, tho)
It's not documented not to be that way either, and no error is given, so I assumed it would work. The documentation says $x->blsft($y); # left shift $x->blsft($y,$n); # left shift, in base $n (like 10) with no restriction on $y. It's quite obvious that $y must be an integer, but nowhere does it say $y must be non-negative. Show quoted text
> Negative amounts of shifting should probably either be supported, or > disallowed. They certainly werent expected when I wrote the code.
OK. Then disallow them. At least for now. I guess that requires less work than adding support for it. :-)
Subject: Re: [rt.cpan.org #21413] blsft() and brsft() totally screwy
Date: Sun, 10 Sep 2006 17:27:09 +0200
To: bug-Math-BigInt [...] rt.cpan.org
From: Tels <nospam-abuse [...] bloodgate.com>
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Moin, On Sunday 10 September 2006 16:57, Peter John Acklam via RT wrote: Show quoted text
> Queue: Math-BigInt > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=21413 > > > nospam-abuse@bloodgate.com wrote:
> > I do not get why you think that shifting by a "negative" amount is > > supported :-D It clearly is not documented to be that way. (I can > > understand that you would expect the result, tho)
> > It's not documented not to be that way either, and no error is given, so > I assumed it would work. The documentation says > > $x->blsft($y); # left shift > $x->blsft($y,$n); # left shift, in base $n (like 10) > > with no restriction on $y. It's quite obvious that $y must be an > integer, but nowhere does it say $y must be non-negative.
You are right, but then in my mind, "left" implies it moves left, not "the other left" :-) I guess as a non-native speaker I am not actually qualified to write documentation. Problem is, as always, when the documentation write, programmer, tester, implementor, specificator and designer are all the same person :) Show quoted text
> > Negative amounts of shifting should probably either be supported, or > > disallowed. They certainly werent expected when I wrote the code.
> > OK. Then disallow them. At least for now. I guess that requires less > work than adding support for it. :-)
Should work now, please see my other email :D testcases are still missing, tho, as my bathroom cleaning duty had priority. Best wishes, Tels - -- Signed on Sun Sep 10 17:25:15 2006 with key 0x93B84C15. Visit my photo gallery at http://bloodgate.com/photos/ PGP key on http://bloodgate.com/tels.asc or per email. "I'm not a vegetarian, but I eat animals who are" -- Groucho Marx -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iQEVAwUBRQQuzncLPEOTuEwVAQL0CQf9Gd/QlOtH4HaGvwioSnid/W6VN5Z/Qku4 bY+hcsQkDojSkMssj9+pednbt3kWlfSz/ioiamTH6px5VPqyO51acEHqQXKDuP5h P8ThFqVjqD+quwjsdI/TbJobhA7qxJsViPZclDuvmcr6/7lIJ92GaRcpTpJPsSjZ o7BDlWOv+XyIeDkkCD5dn6KPDFd6xGEIxMiMbyF027wOpiF1322MxZqgu1UpnU3a bOgO3Klx30f2byZ+12GKQC9wGdsH9BBUWdRMCXdc9e8sXK+OM20CmzkG2znrFII3 srBupbWRE3NX2g3je0o3tR4opcCXE5oiHAM8brYwv6Fo2fj6D0xGAg== =O2hU -----END PGP SIGNATURE-----
From: pjacklam [...] online.no
I'm sorry I missed the context issue. It didn't occur to me that blsft() and brsft() behaved differently in list context. I have tested the new version and it works nicely. Thanks.
Subject: Re: [rt.cpan.org #21413] blsft() and brsft() totally screwy
Date: Sun, 10 Sep 2006 21:43:31 +0200
To: bug-Math-BigInt [...] rt.cpan.org
From: Tels <nospam-abuse [...] bloodgate.com>
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Moin, On Sunday 10 September 2006 20:16, Peter John Acklam via RT wrote: Show quoted text
> Queue: Math-BigInt > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=21413 > > > I'm sorry I missed the context issue. It didn't occur to me that blsft() > and brsft() behaved differently in list context. I have tested the new > version and it works nicely. Thanks.
No problem, it should have been documented better (and it is still a bit wierd that only brsft() works differently in list context). best wishes, tels - -- Signed on Sun Sep 10 21:42:58 2006 with key 0x93B84C15. Visit my photo gallery at http://bloodgate.com/photos/ PGP key on http://bloodgate.com/tels.asc or per email. "If you want to travel around the world and be invited to speak at a lot of different places, just write a Unix operating system." -- Linus Torvalds -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iQEVAwUBRQRq63cLPEOTuEwVAQKr9gf/Tc25IEmydDehAg+U3a63Wb59uITxPtng R2EnUZF5zWd7Yl/ZMRpYUmcue4K5BjncEQuZq18oEyV/cFBKv+rqB0x4I15Ch6MQ 3onL/iaFA545tprS24BC00HFd1XHswJEJBnguX7uhHQMM47B03wYm8h/8+taBeTU UxzPy0rgbsGvEI9J9eixiDL+REKl6FV5ZIoHBIt1JdO0f2YgECkaC9zioA84+Ul6 l8tG/g/gT5yJgIFmyklIJvJfx6Ipgu/lpvUqa8AD6pnvt0oIhmqzeLtmZeYLiF+H icsPIVRAeFxIidAbnhXxGo7EvbBv/KB+7t0n6GbYgzr65V8bSdfwHQ== =yWVx -----END PGP SIGNATURE-----
This issue has been fixed in the released v1.78. Thank you for your report, Tels