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:
Peter Prymmer
Date:
January 11, 2001 11:12
Subject:
Re: [PATCH: perl@8342] lib/bigfloat.t FAILED at test 351
Message ID:
Pine.OSF.4.10.10101111111520.405058-100000@aspara.forte.com


On Wed, 10 Jan 2001, Roca, Ignasi wrote:

> Here an example:
> 
> #include <math.h>
> 
> main()
> {
> double r,s,t;
> 
> printf ("\n<<< r = 800000.0 * 1e-5 >>>\n");
> r = 800000.0 * 1e-5;
> t = modf (r,&s);
> printf("r=%e, s=%e, t=%e\n",r,s,t);
> 
> printf ("\n<<< r = 800000.0 / 1e+5 >>>\n");
> r = 800000.0 / 1e+5;
> t = modf (r,&s);
> printf("r=%e, s=%e, t=%e\n",r,s,t);
> }
> 
> 
> The result in POSIX-BC as unexpected is the following:
> <<< r = 800000.0 * 1e-5 >>>
> r=8.000000e+00, s=7.000000e+00, t=1.000000e+00
> 
> <<< r = 800000.0 / 1e+5 >>>
> r=8.000000e+00, s=8.000000e+00, t=0.000000e+00

The result using c89 on OS/390 V2.5 is the equally unexpected:

<<< r = 800000.0 * 1e-5 >>>
r=8.000000e+00, s=7.000000e+00, t=1.000000e+00

<<< r = 800000.0 / 1e+5 >>>
r=8.000000e+00, s=8.000000e+00, t=0.000000e+00


> Perl's sqrt() function fails due to this Arithmetic-Floating-Point problem.
> As I'm not able to use another floating-point implementation which was ieee
> compliant, I found a way to solve the problem of sqrt(), following there is
> a patch that corrects the sqrt problem:
> 
> =========================================================
> --- bigint.pl.orig      Tue Dec 12 04:30:51 2000
> +++ bigint.pl   Wed Jan 10 14:54:27 2001
> @@ -213,7 +213,7 @@
>             for $y (@y) {
>                 $prod = $x * $y + $prod[$cty] + $car;
>                 $prod[$cty++] =
> -                   $prod - ($car = int($prod * 1e-5)) * 1e5;
> +                   $prod - ($car = int($prod / 1e5)) * 1e5;

I find that with this patch installed on a 8375 kit all 246 lib/bigint.t
tests pass and all 278 lib/bigintpm.t pass.  Many thanks for spotting this
problem.

Peter Prymmer



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