develooper Front page | perl.perl5.porters | Postings from January 2001

Re: [PATCH: perl@8342] lib/bigfloat.t FAILED at test 351

Thread Previous | Thread Next
From:
Jarkko Hietaniemi
Date:
January 12, 2001 16:27
Subject:
Re: [PATCH: perl@8342] lib/bigfloat.t FAILED at test 351
Message ID:
20010112182703.Y12002@chaos.wustl.edu
On Fri, Jan 12, 2001 at 04:27:36PM -0800, Peter Prymmer wrote:
> 
> 
> On Fri, 12 Jan 2001, Jarkko Hietaniemi wrote:
> 
> > > OK the variable alluded to above would have been better name
> > > fp_multiply_broken, but in order to be both terse and explicit how about
> > > fp_snm_broken?  As in this snippet that could fit into Configure after the
> > > value of $i_math is determined (the eval and rm lines have been #commented
> > > out so that I could play with this script standalone, the echo >&4 line
> > > is commented too since I have not done the approriate exec in my login
> > > shell):
> > 
> > I feel that this is too specific an error with too specific parameters
> > to warrant a separate Configure test.  How about a BEGIN test in the
> > library files?
> 
> OK so we back away from doing the test in C and revert to perl.  Do you

If we were worrying about speed here we wouldn't be implementing
bigint/float routines in Perl.

> want for the BEGIN{} block to be a test done as part of a:
> 
>     lib/bigint_pl.PL -> lib/bigint.pl
>     lib/Math/BigInt_pm.PL -> lib/Math/BigInt.pm
> 
> file extraction?  Or would this do (it tests lib/big*.t tests ok with the
> 8375 kit on os/390 and with the 8404 kit on Tru 64 4.0D)?

This looks great, thanks.

> diff -ru perl.8404.orig/lib/Math/BigInt.pm perl.8404/lib/Math/BigInt.pm
> --- perl.8404.orig/lib/Math/BigInt.pm	Sat Jan  6 21:32:28 2001
> +++ perl.8404/lib/Math/BigInt.pm	Fri Jan 12 15:55:25 2001
> @@ -52,6 +52,11 @@
>  
>  $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 @@
>        ($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 @@
>      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 @@
>  	    ($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) {
> diff -ru perl.8404.orig/lib/bigint.pl perl.8404/lib/bigint.pl
> --- perl.8404.orig/lib/bigint.pl	Sat Jan  6 21:32:33 2001
> +++ perl.8404/lib/bigint.pl	Fri Jan 12 15:55:13 2001
> @@ -42,6 +42,12 @@
>  #   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 @@
>  	    ($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 @@
>      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 @@
>  	    ($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) {
> End of Patch.
> 
> Peter Prymmer
> 
> 

-- 
$jhi++; # http://www.iki.fi/jhi/
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About