develooper Front page | perl.perl5.porters | Postings from October 2003

Re: [perl #24091] Not OK: perl v5.8.1 on sgi6-irix-ld 6.5

From:
Ed Allen Smith
Date:
October 8, 2003 19:10
Subject:
Re: [perl #24091] Not OK: perl v5.8.1 on sgi6-irix-ld 6.5
Message ID:
mid+200310090209.h9929UDV1456773@dogberry.rutgers.edu
In message <20031009011103.GA3456@efn.org> (on 8 October 2003 18:11:03
-0700), sthoenna@efn.org (Yitzchak Scott-Thoennes) wrote:

>How about this:
>
>--- lib/Math/BigInt/Calc.pm.orig	2003-10-08 15:31:26.583782400 -0700
>+++ lib/Math/BigInt/Calc.pm	2003-10-08 15:43:00.251227200 -0700
>@@ -1423,7 +1423,10 @@
>     else
>       {
>       # fit's into one Perl scalar, so result can be computed directly
>-      $x->[0] = int( $x->[0] ** (1 / $n->[0]) );
>+      my $result = int( $x->[0] ** (1 / $n->[0]) + .5);
>+      # see if we rounded up inappropriately
>+      --$result if $result ** $n->[0] > $x->[0];
>+      $x->[0] = $result;
>       }
>     return $x;
>     } 
>End of Patch.

I like it overall, except that I'm wondering given rounding wierdnesses
whether it might be best to check specifically what the result is without
the +.5. That way, if something goes wrong with the $result**$n->[0] check
(say it's 0.000000001 greater than $x->[0]), it'll just revert to the
behavior without the +0.5.

	 -Allen

-- 
Allen Smith                       http://cesario.rutgers.edu/easmith/
February 1, 2003                               Space Shuttle Columbia
Ad Astra Per Aspera                     To The Stars Through Asperity



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