Change 31330 by [EMAIL PROTECTED] on 2007/06/03 16:23:03

        Subject: [PATCH] Math::BigInt v1.87 take 6
        From: Tels <[EMAIL PROTECTED]>
        Date: Sat, 2 Jun 2007 13:40:45 +0000
        Message-Id: <[EMAIL PROTECTED]>

Affected files ...

... //depot/perl/lib/Math/BigFloat.pm#72 edit
... //depot/perl/lib/Math/BigInt.pm#80 edit

Differences ...

==== //depot/perl/lib/Math/BigFloat.pm#72 (text) ====
Index: perl/lib/Math/BigFloat.pm
--- perl/lib/Math/BigFloat.pm#71~31285~ 2007-05-28 03:17:22.000000000 -0700
+++ perl/lib/Math/BigFloat.pm   2007-06-03 09:23:03.000000000 -0700
@@ -241,27 +241,30 @@
 
 sub copy
   {
-  my ($c,$x);
+  # if two arguments, the first one is the class to "swallow" subclasses
   if (@_ > 1)
     {
-    # if two arguments, the first one is the class to "swallow" subclasses
-    ($c,$x) = @_;
-    }
-  else
-    {
-    $x = shift;
-    $c = ref($x);
-    }
-  return unless ref($x); # only for objects
-
-  my $self = {}; bless $self,$c;
+    my  $self = bless {
+       sign => $_[1]->{sign}, 
+       _es => $_[1]->{_es}, 
+       _m => $MBI->_copy($_[1]->{_m}),
+       _e => $MBI->_copy($_[1]->{_e}),
+    }, $_[0] if @_ > 1;
+
+    $self->{_a} = $_[1]->{_a} if defined $_[1]->{_a};
+    $self->{_p} = $_[1]->{_p} if defined $_[1]->{_p};
+    return $self;
+    }
+
+  my $self = bless {
+       sign => $_[0]->{sign}, 
+       _es => $_[0]->{_es}, 
+       _m => $MBI->_copy($_[0]->{_m}),
+       _e => $MBI->_copy($_[0]->{_e}),
+       }, ref($_[0]);
 
-  $self->{sign} = $x->{sign};
-  $self->{_es} = $x->{_es};
-  $self->{_m} = $MBI->_copy($x->{_m});
-  $self->{_e} = $MBI->_copy($x->{_e});
-  $self->{_a} = $x->{_a} if defined $x->{_a};
-  $self->{_p} = $x->{_p} if defined $x->{_p};
+  $self->{_a} = $_[0]->{_a} if defined $_[0]->{_a};
+  $self->{_p} = $_[0]->{_p} if defined $_[0]->{_p};
   $self;
   }
 
@@ -3279,6 +3282,15 @@
 
        use Math::BigFloat lib => 'GMP';
 
+Note: The keyword 'lib' will warn when the requested library could not be
+loaded. To suppress the warning use 'try' instead:
+
+       use Math::BigFloat try => 'GMP';
+
+To turn the warning into a die(), use 'only' instead:
+
+       use Math::BigFloat only => 'GMP';
+
 The following would first try to find Math::BigInt::Foo, then
 Math::BigInt::Bar, and when this also fails, revert to Math::BigInt::Calc:
 
@@ -3329,7 +3341,7 @@
        require Math::BigFloat;
        my $matter = Math::BigFloat->bone() + 4;        # load BigInt and Calc
        Math::BigFloat->import( lib => 'Pari' );        # load Pari, too
-       my $anti-matter = Math::BigFloat->bone()+4;     # now use Pari
+       my $anti_matter = Math::BigFloat->bone()+4;     # now use Pari
 
 This will create objects with numbers stored in two different backend 
libraries,
 and B<VERY BAD THINGS> will happen when you use these together:

==== //depot/perl/lib/Math/BigInt.pm#80 (text) ====
Index: perl/lib/Math/BigInt.pm
--- perl/lib/Math/BigInt.pm#79~31285~   2007-05-28 03:17:22.000000000 -0700
+++ perl/lib/Math/BigInt.pm     2007-06-03 09:23:03.000000000 -0700
@@ -475,25 +475,26 @@
 
 sub copy
   {
-  my ($c,$x);
+  # if two arguments, the first one is the class to "swallow" subclasses
   if (@_ > 1)
     {
-    # if two arguments, the first one is the class to "swallow" subclasses
-    ($c,$x) = @_;
-    }
-  else
-    {
-    $x = shift;
-    $c = ref($x);
+    my  $self = bless {
+       sign => $_[1]->{sign}, 
+       value => $CALC->_copy($_[1]->{value}),
+    }, $_[0] if @_ > 1;
+
+    $self->{_a} = $_[1]->{_a} if defined $_[1]->{_a};
+    $self->{_p} = $_[1]->{_p} if defined $_[1]->{_p};
+    return $self;
     }
-  return unless ref($x); # only for objects
 
-  my $self = bless {}, $c;
+  my $self = bless {
+       sign => $_[0]->{sign}, 
+       value => $CALC->_copy($_[0]->{value}),
+       }, ref($_[0]);
 
-  $self->{sign} = $x->{sign};
-  $self->{value} = $CALC->_copy($x->{value});
-  $self->{_a} = $x->{_a} if defined $x->{_a};
-  $self->{_p} = $x->{_p} if defined $x->{_p};
+  $self->{_a} = $_[0]->{_a} if defined $_[0]->{_a};
+  $self->{_p} = $_[0]->{_p} if defined $_[0]->{_p};
   $self;
   }
 
@@ -866,8 +867,8 @@
   no strict 'refs';
 
   # convert to normal scalar for speed and correctness in inner parts
-  $a = $a->numify() if defined $a && ref($a);
-  $p = $p->numify() if defined $a && ref($p);
+  $a = $a->can('numify') ? $a->numify() : "$a" if defined $a && ref($a);
+  $p = $p->can('numify') ? $p->numify() : "$p" if defined $p && ref($p);
 
   # now pick $a or $p, but only if we have got "arguments"
   if (!defined $a)
End of Patch.

Reply via email to