diff options
author | Peter Prymmer <PPrymmer@factset.com> | 2001-01-12 08:27:36 -0800 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-01-13 02:08:50 +0000 |
commit | 1f45ae4a6ff0f2644f5065847597623b443d5e93 (patch) | |
tree | 483f73f60add23d045ee980ec09b1362c503c141 /lib/Math | |
parent | ad4997d384fb6e1eb82bda01bb2b68d4b15b637d (diff) | |
download | perl-1f45ae4a6ff0f2644f5065847597623b443d5e93.tar.gz |
Re: [PATCH: perl@8342] lib/bigfloat.t FAILED at test 351
Message-ID: <Pine.OSF.4.10.10101121623130.478096-100000@aspara.forte.com>
Add a BEGIN guard for sloppy floating point division.
p4raw-id: //depot/perl@8428
Diffstat (limited to 'lib/Math')
-rw-r--r-- | lib/Math/BigInt.pm | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Math/BigInt.pm b/lib/Math/BigInt.pm index 808e5522b9..066577d4cc 100644 --- a/lib/Math/BigInt.pm +++ b/lib/Math/BigInt.pm @@ -52,6 +52,11 @@ sub import { $zero = 0; +# overcome a floating point problem on certain osnames (posix-bc, os390) +BEGIN { + my $x = 100000.0; + my $use_mult = int($x*1e-5)*1e5 == $x ? 1 : 0; +} # normalize string form of number. Strip leading zeros. Strip any # white space and add a sign, if missing. @@ -228,8 +233,14 @@ sub mul { #(*int_num_array, *int_num_array) return int_num_array ($car, $cty) = (0, $[); for $y (@y) { $prod = $x * $y + ($prod[$cty] || 0) + $car; + if ($use_mult) { $prod[$cty++] = $prod - ($car = int($prod * 1e-5)) * 1e5; + } + else { + $prod[$cty++] = + $prod - ($car = int($prod / 1e5)) * 1e5; + } } $prod[$cty] += $car if $car; $x = shift @prod; @@ -254,12 +265,22 @@ sub bdiv { #(dividend: num_str, divisor: num_str) return num_str if (($dd = int(1e5/($y[$#y]+1))) != 1) { for $x (@x) { $x = $x * $dd + $car; + if ($use_mult) { $x -= ($car = int($x * 1e-5)) * 1e5; + } + else { + $x -= ($car = int($x / 1e5)) * 1e5; + } } push(@x, $car); $car = 0; for $y (@y) { $y = $y * $dd + $car; + if ($use_mult) { $y -= ($car = int($y * 1e-5)) * 1e5; + } + else { + $y -= ($car = int($y / 1e5)) * 1e5; + } } } else { @@ -276,7 +297,12 @@ sub bdiv { #(dividend: num_str, divisor: num_str) return num_str ($car, $bar) = (0,0); for ($y = $[, $x = $#x-$#y+$[-1; $y <= $#y; ++$y,++$x) { $prd = $q * $y[$y] + $car; + if ($use_mult) { $prd -= ($car = int($prd * 1e-5)) * 1e5; + } + else { + $prd -= ($car = int($prd / 1e5)) * 1e5; + } $x[$x] += 1e5 if ($bar = (($x[$x] -= $prd + $bar) < 0)); } if ($x[$#x] < $car + $bar) { |