diff options
author | Larry Wall <lwall@netlabs.com> | 1992-06-08 04:52:53 +0000 |
---|---|---|
committer | Larry Wall <lwall@netlabs.com> | 1992-06-08 04:52:53 +0000 |
commit | 68decaef0a08fcd5db3193f825cfdfc539b67ccb (patch) | |
tree | a16d0390e7acc0fcc16eba0be8259a2214efd9fe /lib | |
parent | bf10efe7e35fa48859e575b890018da16608a9d7 (diff) | |
download | perl-68decaef0a08fcd5db3193f825cfdfc539b67ccb.tar.gz |
perl 4.0 patch 22: patch #20, continued
See patch #20.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bigfloat.pl | 25 | ||||
-rw-r--r-- | lib/bigint.pl | 40 | ||||
-rw-r--r-- | lib/chat2.pl | 6 | ||||
-rw-r--r-- | lib/ctime.pl | 3 |
4 files changed, 37 insertions, 37 deletions
diff --git a/lib/bigfloat.pl b/lib/bigfloat.pl index 99a00794bb..52fb7e3880 100644 --- a/lib/bigfloat.pl +++ b/lib/bigfloat.pl @@ -1,8 +1,9 @@ package bigfloat; require "bigint.pl"; - # Arbitrary length float math package # +# by Mark Biggar +# # number format # canonical strings have the form /[+-]\d+E[+-]\d+/ # Input values can have inbedded whitespace @@ -66,14 +67,15 @@ sub norm { #(mantissa, exponent) return fnum_str # negation sub main'fneg { #(fnum_str) return fnum_str local($_) = &'fnorm($_[0]); - substr($_,0,1) =~ tr/+-/-+/ if ($_ ne '+0E+0'); # flip sign + vec($_,0,8) =^ ord('+') ^ ord('-') unless $_ eq '+0E+0'; # flip sign + s/^H/N/; $_; } # absolute value sub main'fabs { #(fnum_str) return fnum_str local($_) = &'fnorm($_[0]); - substr($_,0,1) = '+' unless $_ eq 'NaN'; # mash sign + s/^-/+/; # mash sign $_; } @@ -198,18 +200,13 @@ sub main'fcmp #(fnum_str, fnum_str) return cond_code local($x, $y) = (&'fnorm($_[0]),&'fnorm($_[1])); if ($x eq "NaN" || $y eq "NaN") { undef; - } elsif ($x eq $y) { - 0; - } elsif (ord($x) != ord($y)) { - (ord($y) - ord($x)); # based on signs } else { - local($xm,$xe) = split('E',$x); - local($ym,$ye) = split('E',$y); - if ($xe ne $ye) { - ($xe - $ye) * (substr($x,0,1).'1'); - } else { - &bigint'cmp($xm,$ym); # based on value - } + ord($y) <=> ord($x) + || + ( local($xm,$xe,$ym,$ye) = split('E', $x."E$y"), + (($xe <=> $ye) * (substr($x,0,1).'1') + || &bigint'cmp($xm,$ym)) + ); } } diff --git a/lib/bigint.pl b/lib/bigint.pl index 503c7837c2..9a52fb76fd 100644 --- a/lib/bigint.pl +++ b/lib/bigint.pl @@ -138,19 +138,15 @@ sub main'bsub { #(num_str, num_str) return num_str # GCD -- Euclids algorithm Knuth Vol 2 pg 296 sub main'bgcd { #(num_str, num_str) return num_str local($x,$y) = (&'bnorm($_[0]),&'bnorm($_[1])); - if ($x eq 'NaN') { - 'NaN'; - } - elsif ($y eq 'NaN') { + if ($x eq 'NaN' || $y eq 'NaN') { 'NaN'; - } - else { + } else { ($x, $y) = ($y,&'bmod($x,$y)) while $y ne '+0'; $x; } } -# routine to add two base 100000 numbers +# routine to add two base 1e5 numbers # stolen from Knuth Vol 2 Algorithm A pg 231 # there are separate routines to add and sub as per Kunth pg 233 sub add { #(int_num_array, int_num_array) return int_num_array @@ -158,22 +154,22 @@ sub add { #(int_num_array, int_num_array) return int_num_array $car = 0; for $x (@x) { last unless @y || $car; - $x -= 100000 if $car = (($x += shift @y + $car) >= 100000); + $x -= 1e5 if $car = (($x += shift @y + $car) >= 1e5); } for $y (@y) { last unless $car; - $y -= 100000 if $car = (($y += $car) >= 100000); + $y -= 1e5 if $car = (($y += $car) >= 1e5); } (@x, @y, $car); } -# subtract base 100000 numbers -- stolen from Knuth Vol 2 pg 232, $x > $y +# subtract base 1e5 numbers -- stolen from Knuth Vol 2 pg 232, $x > $y sub sub { #(int_num_array, int_num_array) return int_num_array local(*sx, *sy) = @_; $bar = 0; for $sx (@sx) { last unless @y || $bar; - $sx += 100000 if $bar = (($sx -= shift @sy + $bar) < 0); + $sx += 1e5 if $bar = (($sx -= shift @sy + $bar) < 0); } @sx; } @@ -195,7 +191,7 @@ sub main'bmul { #(num_str, num_str) return num_str for $y (@y) { $prod = $x * $y + $prod[$cty] + $car; $prod[$cty++] = - $prod - ($car = int($prod * (1/100000))) * 100000; + $prod - ($car = int($prod * 1e-5)) * 1e5; } $prod[$cty] += $car if $car; $x = shift @prod; @@ -218,15 +214,15 @@ sub main'bdiv { #(dividend: num_str, divisor: num_str) return num_str $srem = $y[0]; $sr = (shift @x ne shift @y) ? '-' : '+'; $car = $bar = $prd = 0; - if (($dd = int(100000/($y[$#y]+1))) != 1) { + if (($dd = int(1e5/($y[$#y]+1))) != 1) { for $x (@x) { $x = $x * $dd + $car; - $x -= ($car = int($x * (1/100000))) * 100000; + $x -= ($car = int($x * 1e-5)) * 1e5; } push(@x, $car); $car = 0; for $y (@y) { $y = $y * $dd + $car; - $y -= ($car = int($y * (1/100000))) * 100000; + $y -= ($car = int($y * 1e-5)) * 1e5; } } else { @@ -235,20 +231,20 @@ sub main'bdiv { #(dividend: num_str, divisor: num_str) return num_str @q = (); ($v2,$v1) = @y[$#y-1,$#y]; while ($#x > $#y) { ($u2,$u1,$u0) = @x[($#x-2)..$#x]; - $q = (($u0 == $v1) ? 99999 : int(($u0*100000+$u1)/$v1)); - --$q while ($v2*$q > ($u0*100000+$u1-$q*$v1)*100000+$u2); + $q = (($u0 == $v1) ? 99999 : int(($u0*1e5+$u1)/$v1)); + --$q while ($v2*$q > ($u0*1e5+$u1-$q*$v1)*1e5+$u2); if ($q) { ($car, $bar) = (0,0); for ($y = 0, $x = $#x-$#y-1; $y <= $#y; ++$y,++$x) { $prd = $q * $y[$y] + $car; - $prd -= ($car = int($prd * (1/100000))) * 100000; - $x[$x] += 100000 if ($bar = (($x[$x] -= $prd + $bar) < 0)); + $prd -= ($car = int($prd * 1e-5)) * 1e5; + $x[$x] += 1e5 if ($bar = (($x[$x] -= $prd + $bar) < 0)); } if ($x[$#x] < $car + $bar) { $car = 0; --$q; for ($y = 0, $x = $#x-$#y-1; $y <= $#y; ++$y,++$x) { - $x[$x] -= 100000 - if ($car = (($x[$x] += $y[$y] + $car) > 100000)); + $x[$x] -= 1e5 + if ($car = (($x[$x] += $y[$y] + $car) > 1e5)); } } } @@ -259,7 +255,7 @@ sub main'bdiv { #(dividend: num_str, divisor: num_str) return num_str if ($dd != 1) { $car = 0; for $x (reverse @x) { - $prd = $car * 100000 + $x; + $prd = $car * 1e5 + $x; $car = $prd - ($tmp = int($prd / $dd)) * $dd; unshift(@d, $tmp); } diff --git a/lib/chat2.pl b/lib/chat2.pl index 916b9756af..662872c2d3 100644 --- a/lib/chat2.pl +++ b/lib/chat2.pl @@ -108,6 +108,7 @@ sub open_proc { ## public die "Cannot exec @cmd: $!"; } close(TTY); + $PID{$next} = $pid; $next; # return symbol for switcharound } @@ -258,10 +259,15 @@ sub print { ## public ## like close $handle sub close { ## public + local($pid); if ($_[0] =~ /$nextpat/) { + $pid = $PID{$_[0]}; *S = shift; + } else { + $pid = $PID{$next}; } close(S); + waitpid($pid,0); if (defined $S{"needs_close"}) { # is it a listen socket? local(*NS) = $S{"needs_close"}; delete $S{"needs_close"}; diff --git a/lib/ctime.pl b/lib/ctime.pl index 988d05a841..6000d29a19 100644 --- a/lib/ctime.pl +++ b/lib/ctime.pl @@ -3,7 +3,7 @@ ;# Waldemar Kebsch, Federal Republic of Germany, November 1988 ;# kebsch.pad@nixpbe.UUCP ;# Modified March 1990, Feb 1991 to properly handle timezones -;# $Id: ctime.pl,v 1.8 91/02/04 18:28:12 hakanson Exp $ +;# $RCSfile: ctime.pl,v $$Revision: 4.0.1.1 $$Date: 92/06/08 13:38:06 $ ;# Marion Hakanson (hakanson@cse.ogi.edu) ;# Oregon Graduate Institute of Science and Technology ;# @@ -24,6 +24,7 @@ sub ctime { package ctime; local($time) = @_; + local($[) = 0; local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst); # Determine what time zone is in effect. |