Skip Menu |
 

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

Report information
The Basics
Id: 34459
Status: resolved
Worked: 25 min
Priority: 0/
Queue: Math-BigInt

People
Owner: TELS [...] cpan.org
Requestors: ntyni [...] iki.fi
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 1.87
  • 1.88
Fixed in: 1.88



Subject: bsqrt() breaks on floats with enough digits
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Charset: utf8
X-RT-Original-Encoding: utf-8
Content-Type: multipart/mixed; boundary="----------=_1206568507-8319-4"
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
Content-Length: 905
Download (untitled) / with headers
text/plain 905b
Hi, there's a problem with bsqrt() on floats with more than 88 digits (2*div_scale+4). I'm attaching a failing testcase and a proposed fix: the result here with Math-BigInt 1.87 before the fix is ok 708 not ok 709 # Test 709 got: "3.16227766016837933199889354443271853372" (t/mbimbf.t at line 107 fail #2) # Expected: "1" Illegal division by zero at ../lib/Math/BigInt/Calc.pm line 922, <DATA> line 77. dubious Test returned status 255 (wstat 65280, 0xff00) DIED. FAILED tests 709-710 FWIW, this was originally reported as Debian bug #417528, <http://bugs.debian.org/417528>, and the original scenario was # perl -le 'use bignum; print sqrt(sqrt(2)**3)' which gives the wrong answer of about 5.318 with 1.87 and another wrong answer of about 9.102 with some earlier versions. Please let me know if you need more information. Thanks for your work on Math-BigInt, -- Niko Tyni ntyni@debian.org
Subject: 417528.patch
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----------=_1206568507-8319-3"
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Charset: utf8
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: iso-8859-1
Content-Length: 0
Content-Type: text/x-patch; name="417528.patch"
Content-Disposition: inline; filename="417528.patch"
Content-Transfer-Encoding: binary
Content-Length: 1098
Download 417528.patch
text/x-diff 1k
diff --git a/lib/Math/BigFloat.pm b/lib/Math/BigFloat.pm index f2eb0a4..9f986be 100644 --- a/lib/Math/BigFloat.pm +++ b/lib/Math/BigFloat.pm @@ -2142,8 +2142,9 @@ sub bsqrt # But we need at least $scale digits, so calculate how many are missing my $shift = $scale - $digits; - # That should never happen (we take care of integer guesses above) - # $shift = 0 if $shift < 0; + # This happens if the input had enough digits + # (we take care of integer guesses above) + $shift = 0 if $shift < 0; # Multiply in steps of 100, by shifting left two times the "missing" digits my $s2 = $shift * 2; diff --git a/t/mbimbf.t b/t/mbimbf.t index fae3c8c..88201e1 100755 --- a/t/mbimbf.t +++ b/t/mbimbf.t @@ -32,7 +32,7 @@ BEGIN print "# INC = @INC\n"; plan tests => 684 - + 23; # own tests + + 26; # own tests } use Math::BigInt 1.70; @@ -100,3 +100,9 @@ $x = Math::BigFloat->new(100); $x = $x->blog(Math::BigInt->new(10)); ok ($x,2); + +for my $i (80,88,100) { + $x = Math::BigFloat->new("1." . ("0" x $i) . "1"); + $x = $x->bsqrt; + ok ($x, 1); +}
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Disposition: inline
Charset: utf8
Message-Id: <rt-3.6.HEAD-8339-1206741245-898.34459-0-0 [...] rt.cpan.org>
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Original-Encoding: utf-8
Content-Length: 384
Download (untitled) / with headers
text/plain 384b
On Wed Mar 26 17:55:12 2008, ntyni@iki.fi wrote: Show quoted text
> Hi, >
Thanx for the detailed analys and fix! My current plan is to (finally) releasev 1.88 of BigInt, then your fix can be applied and be released into v1.89. (The reason that v1.88 would not contain is because 5.10.0 contains already a version v1.88 and I want to release it verbatim) Thanx again and sorry for the delay, Tels
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Disposition: inline
Charset: utf8
Message-Id: <rt-3.6.HEAD-24881-1207409167-788.34459-0-0 [...] rt.cpan.org>
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Original-Encoding: utf-8
Content-Length: 139
Download (untitled) / with headers
text/plain 139b
Applied the patch to my local version. I'll probably wait a day or two to see what CPAN-TESTERS say to v1.88 ;) Thank you for your report!
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Disposition: inline
Charset: utf8
Message-Id: <rt-3.6.HEAD-10211-1208084628-80.34459-0-0 [...] rt.cpan.org>
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Original-Encoding: utf-8
Content-Length: 54
Fixed in the v1.88 release. Thank you for your report!
MIME-Version: 1.0
In-Reply-To: <rt-3.6.HEAD-10211-1208084628-80.34459-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Disposition: inline
Charset: utf8
References: <rt-3.6.HEAD-10211-1208084628-80.34459-0-0 [...] rt.cpan.org>
Message-Id: <rt-3.6.HEAD-18308-1208681415-196.34459-0-0 [...] rt.cpan.org>
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Original-Encoding: utf-8
Content-Length: 177
Download (untitled) / with headers
text/plain 177b
On Sun Apr 13 07:03:48 2008, TELS wrote: Show quoted text
> Fixed in the v1.88 release. Thank you for your report!
Oopps, it will actually be resolved in the v1.89 release. Sorry for the noise.
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Disposition: inline
Charset: utf8
Message-Id: <rt-3.6.HEAD-9083-1208805977-1562.34459-0-0 [...] rt.cpan.org>
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Original-Encoding: utf-8
Content-Length: 63
Resolved with the release of v1.89 - thank you for your report!


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.