From 1f45ae4a6ff0f2644f5065847597623b443d5e93 Mon Sep 17 00:00:00 2001 From: Peter Prymmer Date: Fri, 12 Jan 2001 08:27:36 -0800 Subject: Re: [PATCH: perl@8342] lib/bigfloat.t FAILED at test 351 Message-ID: Add a BEGIN guard for sloppy floating point division. p4raw-id: //depot/perl@8428 --- lib/bigint.pl | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'lib/bigint.pl') 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) { -- cgit v1.2.1