summaryrefslogtreecommitdiff
path: root/cpan/Math-Complex
diff options
context:
space:
mode:
authorZefram <zefram@fysh.org>2011-05-18 21:54:55 +0100
committerZefram <zefram@fysh.org>2011-05-18 22:31:50 +0100
commit3194a40a2b5938cb9768640166e46dd3bc670e0b (patch)
tree106a0d0fb0d36835222a8942b0770b9526fa2f4f /cpan/Math-Complex
parent91a2e9f615c98c7be7adf43d6a8a7482eb59811f (diff)
downloadperl-3194a40a2b5938cb9768640166e46dd3bc670e0b.tar.gz
update Math-Complex to CPAN version 1.57
* Add copy constructor and arrange for it to be called appropriately, problem found by David Madore and Alexandr Ciornii. * Correctly format polarwise when a numeric format specifier is given, problem found by TomC. * More stable great_circle_direction algorithm, problem found by Daniel Burr.
Diffstat (limited to 'cpan/Math-Complex')
-rw-r--r--cpan/Math-Complex/lib/Math/Complex.pm30
-rw-r--r--cpan/Math-Complex/lib/Math/Trig.pm23
-rw-r--r--cpan/Math-Complex/t/Complex.t19
3 files changed, 53 insertions, 19 deletions
diff --git a/cpan/Math-Complex/lib/Math/Complex.pm b/cpan/Math-Complex/lib/Math/Complex.pm
index 8475a2b5d0..a46f66e7ba 100644
--- a/cpan/Math-Complex/lib/Math/Complex.pm
+++ b/cpan/Math-Complex/lib/Math/Complex.pm
@@ -11,7 +11,7 @@ use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $Inf $ExpInf);
-$VERSION = 1.56;
+$VERSION = 1.57;
use Config;
@@ -129,10 +129,16 @@ my @pi = qw(pi pi2 pi4 pip2 pip4 Inf);
);
use overload
+ '=' => \&_copy,
+ '+=' => \&_plus,
'+' => \&_plus,
+ '-=' => \&_minus,
'-' => \&_minus,
+ '*=' => \&_multiply,
'*' => \&_multiply,
+ '/=' => \&_divide,
'/' => \&_divide,
+ '**=' => \&_power,
'**' => \&_power,
'==' => \&_numeq,
'<=>' => \&_spaceship,
@@ -217,6 +223,19 @@ sub _emake {
return ($p, $q);
}
+sub _copy {
+ my $self = shift;
+ my $clone = {%$self};
+ if ($self->{'cartesian'}) {
+ $clone->{'cartesian'} = [@{$self->{'cartesian'}}];
+ }
+ if ($self->{'polar'}) {
+ $clone->{'polar'} = [@{$self->{'polar'}}];
+ }
+ bless $clone,__PACKAGE__;
+ return $clone;
+}
+
#
# ->make
#
@@ -1539,7 +1558,7 @@ sub _stringify_polar {
if (defined $format) {
$r = sprintf($format, $r);
- $theta = sprintf($format, $theta) unless defined $theta;
+ $theta = sprintf($format, $t) unless defined $theta;
} else {
$theta = $t unless defined $theta;
}
@@ -2077,9 +2096,10 @@ L<Math::Trig>
=head1 AUTHORS
-Daniel S. Lewart <F<lewart!at!uiuc.edu>>
-Jarkko Hietaniemi <F<jhi!at!iki.fi>>
-Raphael Manfredi <F<Raphael_Manfredi!at!pobox.com>>
+Daniel S. Lewart <F<lewart!at!uiuc.edu>>,
+Jarkko Hietaniemi <F<jhi!at!iki.fi>>,
+Raphael Manfredi <F<Raphael_Manfredi!at!pobox.com>>,
+Zefram <zefram@fysh.org>
=head1 LICENSE
diff --git a/cpan/Math-Complex/lib/Math/Trig.pm b/cpan/Math-Complex/lib/Math/Trig.pm
index b7767bebcc..f428ad26c9 100644
--- a/cpan/Math-Complex/lib/Math/Trig.pm
+++ b/cpan/Math-Complex/lib/Math/Trig.pm
@@ -10,14 +10,14 @@ package Math::Trig;
use 5.005;
use strict;
-use Math::Complex 1.56;
+use Math::Complex 1.57;
use Math::Complex qw(:trig :pi);
use vars qw($VERSION $PACKAGE @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@ISA = qw(Exporter);
-$VERSION = 1.20;
+$VERSION = 1.21;
my @angcnv = qw(rad2deg rad2grad
deg2rad deg2grad
@@ -166,19 +166,13 @@ sub great_circle_distance {
sub great_circle_direction {
my ( $theta0, $phi0, $theta1, $phi1 ) = @_;
- my $distance = great_circle_distance($theta0, $phi0, $theta1, $phi1);
-
my $lat0 = pip2 - $phi0;
my $lat1 = pip2 - $phi1;
- my $direction =
- acos_real((sin($lat1) - sin($lat0) * cos($distance)) /
- (cos($lat0) * sin($distance)));
-
- $direction = pi2 - $direction
- if sin($theta1 - $theta0) < 0;
-
- return rad2rad($direction);
+ return rad2rad(pi2 -
+ atan2(sin($theta0-$theta1) * cos($lat1),
+ cos($lat0) * sin($lat1) -
+ sin($lat0) * cos($lat1) * cos($theta0-$theta1)));
}
*great_circle_bearing = \&great_circle_direction;
@@ -755,8 +749,9 @@ L<Math::Complex>
=head1 AUTHORS
-Jarkko Hietaniemi <F<jhi!at!iki.fi>> and
-Raphael Manfredi <F<Raphael_Manfredi!at!pobox.com>>.
+Jarkko Hietaniemi <F<jhi!at!iki.fi>>,
+Raphael Manfredi <F<Raphael_Manfredi!at!pobox.com>>,
+Zefram <zefram@fysh.org>
=head1 LICENSE
diff --git a/cpan/Math-Complex/t/Complex.t b/cpan/Math-Complex/t/Complex.t
index 687d6220df..d0d83d3441 100644
--- a/cpan/Math-Complex/t/Complex.t
+++ b/cpan/Math-Complex/t/Complex.t
@@ -34,6 +34,15 @@ if ($^O eq 'unicos') { # For some reason root() produces very inaccurate
} # cos(), sin(), cosh(), sinh(). The division
# of doubles is the current suspect.
+$test++;
+push @script, "{ my \$t=$test; ".q{
+ my $a = Math::Complex->new(1);
+ my $b = $a;
+ $a += 2;
+ print "not " unless "$a" eq "3" && "$b" eq "1";
+ print "ok $t\n";
+}."}";
+
while (<DATA>) {
s/^\s+//;
next if $_ eq '' || /^\#/;
@@ -287,6 +296,15 @@ EOS
print "not " unless "\$j" =~ /^\\[1,2\\.09439510\\d+\\]\$/;
print "ok $test\n";
+ \$j->display_format('style' => 'polar', 'format' => "%.4g");
+EOS
+
+ $test++;
+ push @script, <<EOS;
+ print "# j = \$j\n";
+ print "not " unless "\$j" =~ /^\\[1,2\\.094\\]\$/;
+ print "ok $test\n";
+
\$j->display_format('style' => 'cartesian', 'format' => '(%.5g)');
EOS
@@ -698,6 +716,7 @@ __END__
[1, pi/3]:"[1,pi/3]"
[6, -2*pi/3]:"[6,-2pi/3]"
[0.5, -9*pi/11]:"[0.5,-9pi/11]"
+[1, 0.5]:"[1, 0.5]"
{ (4,3); [3,2]; (-3,4); (0,2); [2,1] }