summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPerl 5 Porters <perl5-porters@africa.nicoh.com>1997-04-03 10:03:25 +1200
committerChip Salzenberg <chip@atlantic.net>1997-04-03 10:03:25 +1200
commit5aabfad66ac77650f584e2f07af91645e19fe296 (patch)
treeac96571984ba780e9ae7736cfe85dd17f6cfd865 /lib
parent4a6725af9146bd7faaa10aa5429ff009d393fd6d (diff)
downloadperl-5aabfad66ac77650f584e2f07af91645e19fe296.tar.gz
[inseparable changes from match from perl-5.003_97 to perl-5.003_97a]
CORE PORTABILITY Subject: Add support for Cygwin32 (GNU-Win32) -- very low impact Date: Thu, 3 Apr 1997 09:21:17 +0100 From: John Cerney <j-cerney1@ti.com> Files: MANIFEST README.cygwin32 cygwin32/cw32imp.h cygwin32/gcc2 cygwin32/ld2 cygwin32/perlgcc cygwin32/perlld ext/DynaLoader/dl_cygwin32.xs hints/cygwin32.sh perl.h pp_sys.c Msg-ID: 199704030821.JAA08762@pluto.tiuk.ti.com (applied based on p5p patch as commit 2a079e0090406b1b2e50643540f149206c9e9de8) Subject: Win32 update (six patches) From: Gurusamy Sarathy <gsar@engin.umich.edu> Files: MANIFEST README.win32 dosish.h t/io/fs.t t/io/tell.t t/lib/io_tell.t t/op/magic.t t/op/mkdir.t t/op/runlevel.t t/op/stat.t t/op/taint.t win32/Makefile win32/VC-2.0/pod.mak win32/makedef.pl win32/pod.mak win32/win32.c win32/win32.h win32/win32io.c win32/win32io.h win32/win32iop.h LIBRARY AND EXTENSIONS Subject: Math::Trig, based on (and from an author of) Math::Complex From: Chip Salzenberg <chip@perl.com> Files: MANIFEST lib/Math/Complex.pm lib/Math/Trig.pm pod/perldelta.pod t/lib/complex.t t/lib/trig.t OTHER CORE CHANGES Subject: Fix const-sub-related panic on C<sub foo { my $x; 0 } foo> From: Chip Salzenberg <chip@perl.com> Files: op.c Subject: Fix warning for useless C<1..2> From: Chip Salzenberg <chip@perl.com> Files: op.c Subject: Minor cleanups Date: Thu, 03 Apr 1997 19:56:57 -0500 From: Gurusamy Sarathy <gsar@engin.umich.edu> Files: mg.c mg.h perl.c Msg-ID: 199704040056.TAA22253@aatma.engin.umich.edu (applied based on p5p patch as commit 609794497049cf42bdd2396c04cbb7728e10374d) Subject: Eliminate unreliable warning with %SIG and strict refs From: Chip Salzenberg <chip@perl.com> Files: mg.c Subject: Fix impossible test in vivification From: Chip Salzenberg <chip@perl.com> Files: mg.c
Diffstat (limited to 'lib')
-rw-r--r--lib/Benchmark.pm3
-rw-r--r--lib/I18N/Collate.pm4
-rw-r--r--lib/Math/Complex.pm90
-rw-r--r--lib/Math/Trig.pm242
4 files changed, 311 insertions, 28 deletions
diff --git a/lib/Benchmark.pm b/lib/Benchmark.pm
index fa5c9e81d4..13acf869bc 100644
--- a/lib/Benchmark.pm
+++ b/lib/Benchmark.pm
@@ -195,8 +195,7 @@ code and therefore the difference might end up being E<lt> 0.
=head1 AUTHORS
-Jarkko Hietaniemi E<lt>F<Jarkko.Hietaniemi@hut.fi>E<gt>,
-Tim Bunce E<lt>F<Tim.Bunce@ig.co.uk>E<gt>
+Jarkko Hietaniemi <F<jhi@iki.fi>>, Tim Bunce <F<Tim.Bunce@ig.co.uk>>
=head1 MODIFICATION HISTORY
diff --git a/lib/I18N/Collate.pm b/lib/I18N/Collate.pm
index 343cb02205..6961dc2f1c 100644
--- a/lib/I18N/Collate.pm
+++ b/lib/I18N/Collate.pm
@@ -47,10 +47,10 @@ European character set.
# I18N::Collate.pm
#
-# Author: Jarkko Hietaniemi <Jarkko.Hietaniemi@hut.fi>
+# Author: Jarkko Hietaniemi <F<jhi@iki.fi>>
# Helsinki University of Technology, Finland
#
-# Acks: Guy Decoux <decoux@moulon.inra.fr> understood
+# Acks: Guy Decoux <F<decoux@moulon.inra.fr>> understood
# overloading magic much deeper than I and told
# how to cut the size of this code by more than half.
# (my first version did overload all of lt gt eq le ge cmp)
diff --git a/lib/Math/Complex.pm b/lib/Math/Complex.pm
index 30194eb9a7..9000543438 100644
--- a/lib/Math/Complex.pm
+++ b/lib/Math/Complex.pm
@@ -5,26 +5,41 @@
# -- Jarkko Hietaniemi, March 1997
require Exporter;
-package Math::Complex; @ISA = qw(Exporter);
+package Math::Complex;
use strict;
-use vars qw(@EXPORT $package $display
+use vars qw($VERSION @ISA
+ @EXPORT %EXPORT_TAGS
+ $package $display
$pi $i $ilog10 $logn %logn);
-@EXPORT = qw(
- pi i Re Im arg
- sqrt exp log ln
- log10 logn cbrt root
- tan
- cosec csc sec cotan cot
- asin acos atan
- acosec acsc asec acotan acot
- sinh cosh tanh
- cosech csch sech cotanh coth
- asinh acosh atanh
- acosech acsch asech acotanh acoth
- cplx cplxe
+@ISA = qw(Exporter);
+
+$VERSION = 1.01;
+
+my @trig = qw(
+ pi
+ tan
+ csc cosec sec cot cotan
+ asin acos atan
+ acsc acosec asec acot acotan
+ sinh cosh tanh
+ csch cosech sech coth cotanh
+ asinh acosh atanh
+ acsch acosech asech acoth acotanh
+ );
+
+@EXPORT = (qw(
+ i Re Im arg
+ sqrt exp log ln
+ log10 logn cbrt root
+ cplx cplxe
+ ),
+ @trig);
+
+%EXPORT_TAGS = (
+ 'trig' => [@trig],
);
use overload
@@ -236,7 +251,7 @@ sub multiply {
# Die on division by zero.
#
sub divbyzero {
- warn $package . '::' . "$_[0]: Division by zero.\n";
+ warn "$_[0]: Division by zero.\n";
warn "(Because in the definition of $_[0], $_[1] is 0)\n"
if (defined $_[1]);
my @up = caller(1);
@@ -1002,6 +1017,7 @@ Math::Complex - complex numbers and associated mathematical functions
=head1 SYNOPSIS
use Math::Complex;
+
$z = Math::Complex->make(5, 6);
$t = 4 - 3*i + $z;
$j = cplxe(1, 2*pi/3);
@@ -1195,32 +1211,32 @@ numbers:
tan(z) = sin(z) / cos(z)
- csc(z) = 1 / sin(z)
- sec(z) = 1 / cos(z)
+ csc(z) = 1 / sin(z)
+ sec(z) = 1 / cos(z)
cot(z) = 1 / tan(z)
asin(z) = -i * log(i*z + sqrt(1-z*z))
acos(z) = -i * log(z + sqrt(z*z-1))
atan(z) = i/2 * log((i+z) / (i-z))
- acsc(z) = asin(1 / z)
- asec(z) = acos(1 / z)
+ acsc(z) = asin(1 / z)
+ asec(z) = acos(1 / z)
acot(z) = -i/2 * log((i+z) / (z-i))
sinh(z) = 1/2 (exp(z) - exp(-z))
cosh(z) = 1/2 (exp(z) + exp(-z))
tanh(z) = sinh(z) / cosh(z) = (exp(z) - exp(-z)) / (exp(z) + exp(-z))
- csch(z) = 1 / sinh(z)
- sech(z) = 1 / cosh(z)
+ csch(z) = 1 / sinh(z)
+ sech(z) = 1 / cosh(z)
coth(z) = 1 / tanh(z)
asinh(z) = log(z + sqrt(z*z+1))
acosh(z) = log(z + sqrt(z*z-1))
atanh(z) = 1/2 * log((1+z) / (1-z))
- acsch(z) = asinh(1 / z)
- asech(z) = acosh(1 / z)
+ acsch(z) = asinh(1 / z)
+ asech(z) = acosh(1 / z)
acoth(z) = atanh(1 / z) = 1/2 * log((1+z) / (z-1))
I<log>, I<csc>, I<cot>, I<acsc>, I<acot>, I<csch>, I<coth>,
@@ -1325,6 +1341,32 @@ Here are some examples:
$k = exp(i * 2*pi/3);
print "$j - $k = ", $j - $k, "\n";
+=head1 CAVEATS
+
+The division (/) and the following functions
+
+ tan
+ sec
+ csc
+ cot
+ atan
+ acot
+ tanh
+ sech
+ csch
+ coth
+ atanh
+ asech
+ acsch
+ acoth
+
+cannot be computed for all arguments because that would mean dividing
+by zero. These situations cause fatal runtime errors looking like this
+
+ cot(0): Division by zero.
+ (Because in the definition of cot(0), sin(0) is 0)
+ Died at ...
+
=head1 BUGS
Saying C<use Math::Complex;> exports many mathematical routines in the caller
diff --git a/lib/Math/Trig.pm b/lib/Math/Trig.pm
new file mode 100644
index 0000000000..7c3570c840
--- /dev/null
+++ b/lib/Math/Trig.pm
@@ -0,0 +1,242 @@
+#
+# Trigonometric functions, mostly inherited from Math::Complex.
+# -- Jarkko Hietaniemi, April 1997
+#
+
+require Exporter;
+package Math::Trig;
+
+use strict;
+
+use Math::Complex qw(:trig);
+
+use vars qw($VERSION $PACKAGE
+ @ISA
+ @EXPORT
+ $pi2 $DR $RD $DG $GD $RG $GR);
+
+@ISA = qw(Exporter);
+
+$VERSION = 1.00;
+
+my @angcnv = qw(rad_to_deg rad_to_grad
+ deg_to_rad deg_to_grad
+ grad_to_rad grad_to_dec);
+
+@EXPORT = (@{$Math::Complex::EXPORT_TAGS{'trig'}},
+ @angcnv);
+
+sub pi2 () {
+ $pi2 = 2 * pi unless ($pi2);
+ $pi2;
+}
+
+sub DR () {
+ $DR = pi2/360 unless ($DR);
+ $DR;
+}
+
+sub RD () {
+ $RD = 360/pi2 unless ($RD);
+ $RD;
+}
+
+sub DG () {
+ $DG = 400/360 unless ($DG);
+ $DG;
+}
+
+sub GD () {
+ $GD = 360/400 unless ($GD);
+ $GD;
+}
+
+sub RG () {
+ $RG = 400/pi2 unless ($RG);
+ $RG;
+}
+
+sub GR () {
+ $GR = pi2/400 unless ($GR);
+ $GR;
+}
+
+#
+# Truncating remainder.
+#
+
+sub remt ($$) {
+ # Oh yes, POSIX::fmod() would be faster. Possibly. If it is available.
+ $_[0] - $_[1] * int($_[0] / $_[1]);
+}
+
+#
+# Angle conversions.
+#
+
+sub rad_to_deg ($) {
+ remt(RD * $_[0], 360);
+}
+
+sub deg_to_rad ($) {
+ remt(DR * $_[0], pi2);
+}
+
+sub grad_to_deg ($) {
+ remt(GD * $_[0], 360);
+}
+
+sub deg_to_grad ($) {
+ remt(DG * $_[0], 400);
+}
+
+sub rad_to_grad ($) {
+ remt(RG * $_[0], 400);
+}
+
+sub grad_to_rad ($) {
+ remt(GR * $_[0], pi2);
+}
+
+=head1 NAME
+
+Math::Trig - trigonometric functions
+
+=head1 SYNOPSIS
+
+ use Math::Trig;
+
+ $x = tan(0.9);
+ $y = acos(3.7);
+ $z = asin(2.4);
+
+ $halfpi = pi/2;
+
+ $rad = deg_to_rad(120);
+
+=head1 DESCRIPTION
+
+C<Math::Trig> defines many trigonometric functions not defined by the
+core Perl (which defines only the C<sin()> and C<cos()>. The constant
+B<pi> is also defined as are a few convenience functions for angle
+conversions.
+
+=head1 TRIGONOMETRIC FUNCTIONS
+
+The tangent
+
+ tan
+
+The cofunctions of the sine, cosine, and tangent (cosec/csc and cotan/cot
+are aliases)
+
+ csc cosec sec cot cotan
+
+The arcus (also known as the inverse) functions of the sine, cosine,
+and tangent
+
+ asin acos atan
+
+The principal value of the arc tangent of y/x
+
+ atan2(y, x)
+
+The arcus cofunctions of the sine, cosine, and tangent (acosec/acsc
+and acotan/acot are aliases)
+
+ acsc acosec asec acot acotan
+
+The hyperbolic sine, cosine, and tangent
+
+ sinh cosh tanh
+
+The cofunctions of the hyperbolic sine, cosine, and tangent (cosech/csch
+and cotanh/coth are aliases)
+
+ csch cosech sech coth cotanh
+
+The arcus (also known as the inverse) functions of the hyperbolic
+sine, cosine, and tangent
+
+ asinh acosh atanh
+
+The arcus cofunctions of the hyperbolic sine, cosine, and tangent
+(acsch/acosech and acoth/acotanh are aliases)
+
+ acsch acosech asech acoth acotanh
+
+The trigonometric constant B<pi> is also defined.
+
+ $pi2 = 2 * pi;
+
+=head2 SIMPLE ARGUMENTS, COMPLEX RESULTS
+
+Please note that some of the trigonometric functions can break out
+from the B<real axis> into the B<complex plane>. For example
+C<asin(2)> has no definition for plain real numbers but it has
+definition for complex numbers.
+
+In Perl terms this means that supplying the usual Perl numbers (also
+known as scalars, please see L<perldata>) as input for the
+trigonometric functions might produce as output results that no more
+are simple real numbers: instead they are complex numbers.
+
+The C<Math::Trig> handles this by using the C<Math::Complex> package
+which knows how to handle complex numbers, please see L<Math::Complex>
+for more information. In practice you need not to worry about getting
+complex numbers as results because the C<Math::Complex> takes care of
+details like for example how to display complex numbers. For example:
+
+ print asin(2), "\n";
+
+should produce something like this (take or leave few last decimals):
+
+ 1.5707963267949-1.31695789692482i
+
+That is, a complex number with the real part of approximately E<1.571>
+and the imaginary part of approximately E<-1.317>.
+
+=head1 ANGLE CONVERSIONS
+
+(Plane, 2-dimensional) angles may be converted with the following functions.
+
+ $radians = deg_to_rad($degrees);
+ $radians = grad_to_rad($gradians);
+
+ $degrees = rad_to_deg($radians);
+ $degrees = grad_to_deg($gradians);
+
+ $gradians = deg_to_grad($degrees);
+ $gradians = rad_to_grad($radians);
+
+The full circle is 2 B<pi> radians or E<360> degrees or E<400> gradians.
+
+=head1
+
+The following functions
+
+ tan
+ sec
+ csc
+ cot
+ atan
+ acot
+ tanh
+ sech
+ csch
+ coth
+ atanh
+ asech
+ acsch
+ acoth
+
+cannot be computed for all arguments because that would mean dividing
+by zero. These situations cause fatal runtime errors looking like this
+
+ cot(0): Division by zero.
+ (Because in the definition of cot(0), sin(0) is 0)
+ Died at ...
+
+=cut
+
+# eof