summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Math/Complex.pm17
-rw-r--r--lib/Math/Trig.pm36
-rwxr-xr-xpod/roffitall1
-rwxr-xr-xt/lib/complex.t7
-rwxr-xr-xt/lib/trig.t7
5 files changed, 43 insertions, 25 deletions
diff --git a/lib/Math/Complex.pm b/lib/Math/Complex.pm
index 92504ed111..7a4617c65a 100644
--- a/lib/Math/Complex.pm
+++ b/lib/Math/Complex.pm
@@ -320,9 +320,16 @@ sub _zerotozero {
#
sub power {
my ($z1, $z2, $inverted) = @_;
- _zerotozero if ($z1 == 0 and $z2 == 0);
- return 1 if ($z1 == 1);
- return 0 if ($z2 == 0);
+ my $z1z = $z1 == 0;
+ my $z2z = $z2 == 0;
+ _zerotozero if ($z1z and $z2z);
+ if ($inverted) {
+ return 0 if ($z2z);
+ return 1 if ($z1z or $z2 == 1);
+ } else {
+ return 0 if ($z1z);
+ return 1 if ($z2z or $z1 == 1);
+ }
$z2 = cplx($z2) unless ref $z2;
unless (defined $inverted) {
my $z3 = exp($z2 * log $z1);
@@ -1464,8 +1471,8 @@ operation (for instance) between two overloaded entities.
=head1 AUTHORS
- Raphael Manfredi <F<Raphael_Manfredi@grenoble.hp.com>>
- Jarkko Hietaniemi <F<jhi@iki.fi>>
+Raphael Manfredi <F<Raphael_Manfredi@grenoble.hp.com>> and
+Jarkko Hietaniemi <F<jhi@iki.fi>>.
=cut
diff --git a/lib/Math/Trig.pm b/lib/Math/Trig.pm
index f40576a6cc..c9c045d15d 100644
--- a/lib/Math/Trig.pm
+++ b/lib/Math/Trig.pm
@@ -19,9 +19,9 @@ use vars qw($VERSION $PACKAGE
$VERSION = 1.00;
-my @angcnv = qw(rad_to_deg rad_to_grad
- deg_to_rad deg_to_grad
- grad_to_rad grad_to_deg);
+my @angcnv = qw(rad2deg rad2grad
+ deg2rad deg2grad
+ grad2rad grad2deg);
@EXPORT = (@{$Math::Complex::EXPORT_TAGS{'trig'}},
@angcnv);
@@ -47,17 +47,17 @@ sub remt ($$) {
# Angle conversions.
#
-sub rad_to_deg ($) { remt(RD * $_[0], 360) }
+sub rad2deg ($) { remt(RD * $_[0], 360) }
-sub deg_to_rad ($) { remt(DR * $_[0], pi2) }
+sub deg2rad ($) { remt(DR * $_[0], pi2) }
-sub grad_to_deg ($) { remt(GD * $_[0], 360) }
+sub grad2deg ($) { remt(GD * $_[0], 360) }
-sub deg_to_grad ($) { remt(DG * $_[0], 400) }
+sub deg2grad ($) { remt(DG * $_[0], 400) }
-sub rad_to_grad ($) { remt(RG * $_[0], 400) }
+sub rad2grad ($) { remt(RG * $_[0], 400) }
-sub grad_to_rad ($) { remt(GR * $_[0], pi2) }
+sub grad2rad ($) { remt(GR * $_[0], pi2) }
=head1 NAME
@@ -73,7 +73,7 @@ Math::Trig - trigonometric functions
$halfpi = pi/2;
- $rad = deg_to_rad(120);
+ $rad = deg2rad(120);
=head1 DESCRIPTION
@@ -193,14 +193,14 @@ and the imaginary part of approximately C<-1.317>.
(Plane, 2-dimensional) angles may be converted with the following functions.
- $radians = deg_to_rad($degrees);
- $radians = grad_to_rad($gradians);
+ $radians = deg2rad($degrees);
+ $radians = grad2rad($gradians);
- $degrees = rad_to_deg($radians);
- $degrees = grad_to_deg($gradians);
+ $degrees = rad2deg($radians);
+ $degrees = grad2deg($gradians);
- $gradians = deg_to_grad($degrees);
- $gradians = rad_to_grad($radians);
+ $gradians = deg2grad($degrees);
+ $gradians = rad2grad($radians);
The full circle is 2 I<pi> radians or I<360> degrees or I<400> gradians.
@@ -218,8 +218,8 @@ an answer instead of giving a fatal runtime error.
=head1 AUTHORS
- Jarkko Hietaniemi <F<jhi@iki.fi>>
- Raphael Manfredi <F<Raphael_Manfredi@grenoble.hp.com>>
+Jarkko Hietaniemi <F<jhi@iki.fi>> and
+Raphael Manfredi <F<Raphael_Manfredi@grenoble.hp.com>>.
=cut
diff --git a/pod/roffitall b/pod/roffitall
index 817a8cfe3b..952eada713 100755
--- a/pod/roffitall
+++ b/pod/roffitall
@@ -132,6 +132,7 @@ toroff=`
$libdir/Math::BigFloat.3 \
$libdir/Math::BigInt.3 \
$libdir/Math::Complex.3 \
+ $libdir/Math::Trig.3 \
$libdir/Net::Ping.3 \
$libdir/Net::hostent.3 \
$libdir/Net::netent.3 \
diff --git a/t/lib/complex.t b/t/lib/complex.t
index 4eb08c3cba..80a56254ba 100755
--- a/t/lib/complex.t
+++ b/t/lib/complex.t
@@ -273,6 +273,13 @@ __END__
(2,0):(3,0):(8,0)
(3,0):(2,0):(9,0)
(2,3):(4,0):(-119,-120)
+(0,0):(1,0):(0,0)
+(0,0):(2,3):(0,0)
+(1,0):(0,0):(1,0)
+(1,0):(1,0):(1,0)
+(1,0):(2,3):(1,0)
+(2,3):(0,0):(1,0)
+(2,3):(1,0):(2,3)
&Re
(3,4):3
diff --git a/t/lib/trig.t b/t/lib/trig.t
index 57746fdcd4..c2bc2a8b5b 100755
--- a/t/lib/trig.t
+++ b/t/lib/trig.t
@@ -25,7 +25,7 @@ sub near ($$;$) {
abs($_[0] - $_[1]) < (defined $_[2] ? $_[2] : $eps);
}
-print "1..6\n";
+print "1..7\n";
$x = 0.9;
print 'not ' unless (near(tan($x), sin($x) / cos($x)));
@@ -48,7 +48,10 @@ print 'not ' unless (near($y, 1.5707963267949) and
near($z, -1.31695789692482));
print "ok 5\n";
-print 'not ' unless (near(deg_to_rad(90), pi/2));
+print 'not ' unless (near(deg2rad(90), pi/2));
print "ok 6\n";
+print 'not ' unless (near(rad2deg(pi), 180));
+print "ok 7\n";
+
# eof