summaryrefslogtreecommitdiffstats
path: root/contrib/perl5/lib/Math
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>1999-05-02 14:33:17 +0000
committermarkm <markm@FreeBSD.org>1999-05-02 14:33:17 +0000
commit77644ee620b6a79cf8c538abaf7cd301a875528d (patch)
treeb4adabf341898a4378f4b7f8c7fb65f3f7c77769 /contrib/perl5/lib/Math
parent4fcbc3669aa997848e15198cc9fb856287a6788c (diff)
downloadFreeBSD-src-77644ee620b6a79cf8c538abaf7cd301a875528d.zip
FreeBSD-src-77644ee620b6a79cf8c538abaf7cd301a875528d.tar.gz
Maintenance releace 3 of perl5.005. Includes support for threads.
Diffstat (limited to 'contrib/perl5/lib/Math')
-rw-r--r--contrib/perl5/lib/Math/BigFloat.pm2
-rw-r--r--contrib/perl5/lib/Math/BigInt.pm8
-rw-r--r--contrib/perl5/lib/Math/Complex.pm37
-rw-r--r--contrib/perl5/lib/Math/Trig.pm24
4 files changed, 34 insertions, 37 deletions
diff --git a/contrib/perl5/lib/Math/BigFloat.pm b/contrib/perl5/lib/Math/BigFloat.pm
index 576f341..03bc2f4 100644
--- a/contrib/perl5/lib/Math/BigFloat.pm
+++ b/contrib/perl5/lib/Math/BigFloat.pm
@@ -301,7 +301,7 @@ floats as
=item number format
canonical strings have the form /[+-]\d+E[+-]\d+/ . Input values can
-have inbedded whitespace.
+have imbedded whitespace.
=item Error returns 'NaN'
diff --git a/contrib/perl5/lib/Math/BigInt.pm b/contrib/perl5/lib/Math/BigInt.pm
index ef4af61..b61b884 100644
--- a/contrib/perl5/lib/Math/BigInt.pm
+++ b/contrib/perl5/lib/Math/BigInt.pm
@@ -258,9 +258,9 @@ sub bdiv { #(dividend: num_str, divisor: num_str) return num_str
else {
push(@x, 0);
}
- @q = (); ($v2,$v1) = @y[-2,-1];
+ @q = (); ($v2,$v1) = ($y[-2] || 0, $y[-1]);
while ($#x > $#y) {
- ($u2,$u1,$u0) = @x[-3..-1];
+ ($u2,$u1,$u0) = ($x[-3] || 0, $x[-2] || 0, $x[-1]);
$q = (($u0 == $v1) ? 99999 : int(($u0*1e5+$u1)/$v1));
--$q while ($v2*$q > ($u0*1e5+$u1-$q*$v1)*1e5+$u2);
if ($q) {
@@ -400,8 +400,8 @@ In particular
perl -MMath::BigInt=:constant -e 'print 2**100'
-print the integer value of C<2**100>. Note that without convertion of
-constants the expression 2**100 will be calculatted as floating point number.
+print the integer value of C<2**100>. Note that without conversion of
+constants the expression 2**100 will be calculated as floating point number.
=head1 BUGS
diff --git a/contrib/perl5/lib/Math/Complex.pm b/contrib/perl5/lib/Math/Complex.pm
index e711c14..5b69039 100644
--- a/contrib/perl5/lib/Math/Complex.pm
+++ b/contrib/perl5/lib/Math/Complex.pm
@@ -14,7 +14,7 @@ use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS);
my ( $i, $ip2, %logn );
-$VERSION = sprintf("%s", q$Id: Complex.pm,v 1.25 1998/02/05 16:07:37 jhi Exp $ =~ /(\d+\.\d+)/);
+$VERSION = sprintf("%s", q$Id: Complex.pm,v 1.26 1998/11/01 00:00:00 dsl Exp $ =~ /(\d+\.\d+)/);
@ISA = qw(Exporter);
@@ -401,38 +401,21 @@ sub divide {
}
#
-# _zerotozero
-#
-# Die on zero raised to the zeroth.
-#
-sub _zerotozero {
- my $mess = "The zero raised to the zeroth power is not defined.\n";
-
- my @up = caller(1);
-
- $mess .= "Died at $up[1] line $up[2].\n";
-
- die $mess;
-}
-
-#
# (power)
#
# Computes z1**z2 = exp(z2 * log z1)).
#
sub power {
my ($z1, $z2, $inverted) = @_;
- 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);
+ return 1 if $z1 == 0 || $z2 == 1;
+ return 0 if $z2 == 0 && Re($z1) > 0;
} else {
- return 0 if ($z1z);
- return 1 if ($z2z or $z1 == 1);
+ return 1 if $z2 == 0 || $z1 == 1;
+ return 0 if $z1 == 0 && Re($z2) > 0;
}
- my $w = $inverted ? CORE::exp($z1 * CORE::log($z2)) : CORE::exp($z2 * CORE::log($z1));
+ my $w = $inverted ? CORE::exp($z1 * CORE::log($z2))
+ : CORE::exp($z2 * CORE::log($z1));
# If both arguments cartesian, return cartesian, else polar.
return $z1->{c_dirty} == 0 &&
(not ref $z2 or $z2->{c_dirty} == 0) ?
@@ -443,7 +426,7 @@ sub power {
# (spaceship)
#
# Computes z1 <=> z2.
-# Sorts on the real part first, then on the imaginary part. Thus 2-4i > 3+8i.
+# Sorts on the real part first, then on the imaginary part. Thus 2-4i < 3+8i.
#
sub spaceship {
my ($z1, $z2, $inverted) = @_;
@@ -1273,7 +1256,7 @@ sub gcd {
my ($a, $b) = @_;
my $id = "$a $b";
-
+
unless (exists $gcd{$id}) {
$gcd{$id} = _gcd($a, $b);
$gcd{"$b $a"} = $gcd{$id};
@@ -1702,7 +1685,7 @@ Here are some examples:
The division (/) and the following functions
log ln log10 logn
- tan sec csc cot
+ tan sec csc cot
atan asec acsc acot
tanh sech csch coth
atanh asech acsch acoth
diff --git a/contrib/perl5/lib/Math/Trig.pm b/contrib/perl5/lib/Math/Trig.pm
index b7b5d5d..924286d 100644
--- a/contrib/perl5/lib/Math/Trig.pm
+++ b/contrib/perl5/lib/Math/Trig.pm
@@ -314,9 +314,11 @@ known as the I<radial> coordinate. The angle in the I<xy>-plane
coordinate. The angle from the I<z>-axis is B<phi>, also known as the
I<polar> coordinate. The `North Pole' is therefore I<0, 0, rho>, and
the `Bay of Guinea' (think of the missing big chunk of Africa) I<0,
-pi/2, rho>.
+pi/2, rho>. In geographical terms I<phi> is latitude (northward
+positive, southward negative) and I<theta> is longitude (eastward
+positive, westward negative).
-B<Beware>: some texts define I<theta> and I<phi> the other way round,
+B<BEWARE>: some texts define I<theta> and I<phi> the other way round,
some texts define the I<phi> to start from the horizontal plane, some
texts use I<r> in place of I<rho>.
@@ -374,13 +376,25 @@ by importing the C<great_circle_distance> function:
use Math::Trig 'great_circle_distance'
- $distance = great_circle_distance($theta0, $phi0, $theta1, $phi, [, $rho]);
+ $distance = great_circle_distance($theta0, $phi0, $theta1, $phi1, [, $rho]);
The I<great circle distance> is the shortest distance between two
points on a sphere. The distance is in C<$rho> units. The C<$rho> is
optional, it defaults to 1 (the unit sphere), therefore the distance
defaults to radians.
+If you think geographically the I<theta> are longitudes: zero at the
+Greenwhich meridian, eastward positive, westward negative--and the
+I<phi> are latitudes: zero at the North Pole, northward positive,
+southward negative. B<NOTE>: this formula thinks in mathematics, not
+geographically: the I<phi> zero is at the North Pole, not at the
+Equator on the west coast of Africa (Bay of Guinea). You need to
+subtract your geographical coordinates from I<pi/2> (also known as 90
+degrees).
+
+ $distance = great_circle_distance($lon0, pi/2 - $lat0,
+ $lon1, pi/2 - $lat1, $rho);
+
=head1 EXAMPLES
To calculate the distance between London (51.3N 0.5W) and Tokyo (35.7N
@@ -394,8 +408,8 @@ To calculate the distance between London (51.3N 0.5W) and Tokyo (35.7N
$km = great_circle_distance(@L, @T, 6378);
-The answer may be off by up to 0.3% because of the irregular (slightly
-aspherical) form of the Earth.
+The answer may be off by few percentages because of the irregular
+(slightly aspherical) form of the Earth.
=head1 BUGS
OpenPOWER on IntegriCloud