From: Steve Hay Date: Thu, 12 Feb 2009 14:50:16 +0000 (+0000) Subject: Upgrade to Math-Complex-1.56 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e7deb4af6a1bddab29db10b779d229aec81737e3;p=p5sagit%2Fp5-mst-13.2.git Upgrade to Math-Complex-1.56 --- diff --git a/MANIFEST b/MANIFEST index 14e9e76..67fddb6 100644 --- a/MANIFEST +++ b/MANIFEST @@ -2366,6 +2366,7 @@ lib/Math/Complex.pm A Complex package lib/Math/Complex.t See if Math::Complex works lib/Math/Trig.pm A simple interface to complex trigonometry lib/Math/Trig.t See if Math::Trig works +lib/Math/underbar.t See if Math::Complex works lib/Memoize/AnyDBM_File.pm Memoize glue layer for AnyDBM_File lib/Memoize/ExpireFile.pm Memoize expiry manager test scaffold lib/Memoize/Expire.pm Memoize expiry manager example diff --git a/Porting/Maintainers.pl b/Porting/Maintainers.pl index 69ef256..c060e1c 100644 --- a/Porting/Maintainers.pl +++ b/Porting/Maintainers.pl @@ -651,7 +651,8 @@ package Maintainers; { 'MAINTAINER' => 'zefram', 'FILES' => q[lib/Math/Complex.pm lib/Math/Complex.t - lib/Math/Trig.pm lib/Math/Trig.t], + lib/Math/Trig.pm lib/Math/Trig.t + lib/Math/underbar.t], 'CPAN' => 1, 'UPSTREAM' => 'cpan', }, diff --git a/lib/Math/Complex.pm b/lib/Math/Complex.pm index 7d05a44..8475a2b 100644 --- a/lib/Math/Complex.pm +++ b/lib/Math/Complex.pm @@ -7,9 +7,11 @@ package Math::Complex; +use strict; + use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $Inf $ExpInf); -$VERSION = 1.55; +$VERSION = 1.56; use Config; @@ -66,7 +68,24 @@ BEGIN { # print "# On this machine, Inf = '$Inf'\n"; } -use strict; +use Scalar::Util qw(set_prototype); + +use warnings; +no warnings 'syntax'; # To avoid the (_) warnings. + +BEGIN { + # For certain functions that we override, in 5.10 or better + # we can set a smarter prototype that will handle the lexical $_ + # (also a 5.10+ feature). + if ($] >= 5.010000) { + set_prototype \&abs, '_'; + set_prototype \&cos, '_'; + set_prototype \&exp, '_'; + set_prototype \&log, '_'; + set_prototype \&sin, '_'; + set_prototype \&sqrt, '_'; + } +} my $i; my %LOGN; @@ -611,7 +630,7 @@ sub _conjugate { # Compute or set complex's norm (rho). # sub abs { - my ($z, $rho) = @_; + my ($z, $rho) = @_ ? @_ : $_; unless (ref $z) { if (@_ == 2) { $_[0] = $_[1]; @@ -672,7 +691,7 @@ sub arg { # Therefore if you want the two solutions use the root(). # sub sqrt { - my ($z) = @_; + my ($z) = @_ ? $_[0] : $_; my ($re, $im) = ref $z ? @{$z->_cartesian} : ($z, 0); return $re < 0 ? cplx(0, CORE::sqrt(-$re)) : CORE::sqrt($re) if $im == 0; @@ -805,9 +824,10 @@ sub theta { # Computes exp(z). # sub exp { - my ($z) = @_; - my ($x, $y) = @{$z->_cartesian}; - return (ref $z)->emake(CORE::exp($x), $y); + my ($z) = @_ ? @_ : $_; + return CORE::exp($z) unless ref $z; + my ($x, $y) = @{$z->_cartesian}; + return (ref $z)->emake(CORE::exp($x), $y); } # @@ -837,7 +857,7 @@ sub _logofzero { # Compute log(z). # sub log { - my ($z) = @_; + my ($z) = @_ ? @_ : $_; unless (ref $z) { _logofzero("log") if $z == 0; return $z > 0 ? CORE::log($z) : cplx(CORE::log(-$z), pi); @@ -885,7 +905,7 @@ sub logn { # Compute cos(z) = (exp(iz) + exp(-iz))/2. # sub cos { - my ($z) = @_; + my ($z) = @_ ? @_ : $_; return CORE::cos($z) unless ref $z; my ($x, $y) = @{$z->_cartesian}; my $ey = CORE::exp($y); @@ -902,7 +922,7 @@ sub cos { # Compute sin(z) = (exp(iz) - exp(-iz))/2. # sub sin { - my ($z) = @_; + my ($z) = @_ ? @_ : $_; return CORE::sin($z) unless ref $z; my ($x, $y) = @{$z->_cartesian}; my $ey = CORE::exp($y); diff --git a/lib/Math/Trig.pm b/lib/Math/Trig.pm index 30e8433..b7767be 100644 --- a/lib/Math/Trig.pm +++ b/lib/Math/Trig.pm @@ -10,14 +10,14 @@ package Math::Trig; use 5.005; use strict; -use Math::Complex 1.55; +use Math::Complex 1.56; use Math::Complex qw(:trig :pi); use vars qw($VERSION $PACKAGE @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @ISA = qw(Exporter); -$VERSION = 1.19; +$VERSION = 1.20; my @angcnv = qw(rad2deg rad2grad deg2rad deg2grad diff --git a/lib/Math/underbar.t b/lib/Math/underbar.t new file mode 100644 index 0000000..643e866 --- /dev/null +++ b/lib/Math/underbar.t @@ -0,0 +1,27 @@ +# +# Tests that the standard Perl 5 functions that we override +# that operate on the $_ will work correctly [perl #62412] +# + +use Test::More; + +my @f = qw(abs cos exp log sin sqrt); + +plan tests => scalar @f; + +use strict; + +use Math::Complex; + +my %CORE; + +for my $f (@f) { + local $_ = 0.5; + $CORE{$f} = eval "CORE::$f"; +} + +for my $f (@f) { + local $_ = 0.5; + is(eval "Math::Complex::$f", $CORE{$f}, $f); +} +