| 1 |
Fix Math::BigFloat::sqrt() breaking with too many digits. (Closes: #417528)
|
| 2 |
|
| 3 |
Dual-lived module, fixed on the CPAN side in 1.89.
|
| 4 |
|
| 5 |
Integrated with the other 1.89 changes in blead as change 33715
|
| 6 |
and maint-5.10 as change 33821.
|
| 7 |
|
| 8 |
[rt.cpan.org #34459]
|
| 9 |
diff --git a/lib/Math/BigFloat.pm b/lib/Math/BigFloat.pm
|
| 10 |
index 6e1ecc8..1c1fba8 100644
|
| 11 |
--- a/lib/Math/BigFloat.pm
|
| 12 |
+++ b/lib/Math/BigFloat.pm
|
| 13 |
@@ -2142,8 +2142,9 @@ sub bsqrt
|
| 14 |
# But we need at least $scale digits, so calculate how many are missing
|
| 15 |
my $shift = $scale - $digits;
|
| 16 |
|
| 17 |
- # That should never happen (we take care of integer guesses above)
|
| 18 |
- # $shift = 0 if $shift < 0;
|
| 19 |
+ # This happens if the input had enough digits
|
| 20 |
+ # (we take care of integer guesses above)
|
| 21 |
+ $shift = 0 if $shift < 0;
|
| 22 |
|
| 23 |
# Multiply in steps of 100, by shifting left two times the "missing" digits
|
| 24 |
my $s2 = $shift * 2;
|
| 25 |
diff --git a/lib/Math/BigInt/t/mbimbf.t b/lib/Math/BigInt/t/mbimbf.t
|
| 26 |
index fae3c8c..88201e1 100644
|
| 27 |
--- a/lib/Math/BigInt/t/mbimbf.t
|
| 28 |
+++ b/lib/Math/BigInt/t/mbimbf.t
|
| 29 |
@@ -32,7 +32,7 @@ BEGIN
|
| 30 |
print "# INC = @INC\n";
|
| 31 |
|
| 32 |
plan tests => 684
|
| 33 |
- + 23; # own tests
|
| 34 |
+ + 26; # own tests
|
| 35 |
}
|
| 36 |
|
| 37 |
use Math::BigInt 1.70;
|
| 38 |
@@ -100,3 +100,9 @@ $x = Math::BigFloat->new(100);
|
| 39 |
$x = $x->blog(Math::BigInt->new(10));
|
| 40 |
|
| 41 |
ok ($x,2);
|
| 42 |
+
|
| 43 |
+for my $i (80,88,100) {
|
| 44 |
+ $x = Math::BigFloat->new("1." . ("0" x $i) . "1");
|
| 45 |
+ $x = $x->bsqrt;
|
| 46 |
+ ok ($x, 1);
|
| 47 |
+}
|