JeeBee wrote:
> Dear Perl experts,

Hello,

> The following subroutine contains a while loop that continues to
> multiply $p by 2, until some condition is met.
> (It's for computing a Collatz tree)
> $p turns 0 in this loop, however, and it remains zero for ever, of course.
> 
> My question is, what is exactly its maximum value?

$ perl -le'use POSIX;
print for SHRT_MAX, INT_MAX, LONG_MAX, FLT_MAX, DBL_MAX;
'
32767
2147483647
2147483647
3.40282346638529e+38
1.79769313486232e+308


> As I have been browsing
> the web for a while, but am unable to find this information for Perl data
> types. (I know I could perhaps use BigIntegers, but don't know whether
> that would be really necessary).
> 
> Is there a difference between 'long' and 'int' or something in Perl???

perldoc perlnumber


> sub left_child_of($) {
>   my $p = shift;
>   print "Left of $p\n";
>   die("3 |/| p-1 (p = $p)") if ($p-1) % 3 != 0;
>   $p = ($p-1) / 3;
>   print "L$p\n";
>   # keep multiplying by 2, until 3|p-1 and 2 |/| p-1
>   while((($p-1) % 3 != 0) || (($p-1) % 2 == 0)) {
>     print "L$p: 3 |/| p-1\n" if ($p-1) % 3 != 0;
>     print "L$p: 2 | p-1\n" if ($p-1) % 2 == 0;
>     $p <<= 1;

You are not multiplying $p by 2 like you said which would do what you want:

      $p *= 2;


>   }
>   return $p;
> }


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to