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/bigint.pl | |
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/bigint.pl')
-rw-r--r-- | lib/bigint.pl | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/bigint.pl b/lib/bigint.pl index 4044f7f634..9a3d50d365 100644 --- a/lib/bigint.pl +++ b/lib/bigint.pl @@ -42,6 +42,12 @@ package bigint; # bnorm(BINT) return BINT normalization # +# 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; +} + $zero = 0; @@ -212,8 +218,14 @@ sub main'bmul { #(num_str, num_str) return num_str ($car, $cty) = (0, $[); for $y (@y) { $prod = $x * $y + $prod[$cty] + $car; - $prod[$cty++] = - $prod - ($car = int($prod * 1e-5)) * 1e5; + 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; @@ -239,12 +251,22 @@ sub main'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 { @@ -259,7 +281,12 @@ sub main'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) { |