On Tue, Oct 07, 2003 at 07:17:12PM -0400, Ed Allen Smith <easmith@beatrice.rutgers.edu> wrote: > In message <20031007225502.GA732@efn.org> (on 7 October 2003 15:55:03 > -0700), sthoenna@efn.org (Yitzchak Scott-Thoennes) wrote: > >On Tue, Oct 07, 2003 at 06:33:33PM -0400, Ed Allen Smith > ><easmith@beatrice.rutgers.edu> wrote: > >> if ($a == $b) { > >> $x->[0] = $a; > >> } elsif (abs(($a**$n->[0]) - $x->[0]) > abs(($b**$n->[0]) - $x->[0])) { > >> $x->[0] = $b; > >> } else { > >> $x->[0] = $a; > >> } > >> return $x; > >> > >> In other words, if adding 0.5 (equivalently, subtracting, if the result > >>is negative) will give a more arithmetically correct result after > >>truncating, do it; otherwise, don't. (It's likely that the same sort of > >>thing would be helpful for the _sqrt function.) > > > >That's basically just a form of rounding, only not based on just > >rounding the result. > > Correct. It's choosing whether to truncate, or to round .5 and up upward. > > >It looks more to me as if the goal here is to > >come up with the greatest result $a such that $a**$n->[0] <= $x->[0] > > I can see that argument; it depends on whether one wishes to stick with > Calc.pm always truncating to int in _root or not. It should be consistent, and the rest of it seems to want to truncate. (This should be documented.) > >(not sure if that "greatest" or "<=" is meant to apply to absolute > >values or not). > > > >But your general method certainly works for that. 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. By the way, just a bit lower down, I see a /0b1(0+)/ that looks as if it should be /0b1(0+)\z/, but I'm not sure exactly what it is doing.