Thank you, John!
I see the limit is 32 bits now.
I just added 'use bigint', how easy!

Further, I was wondering about why you said I wasn't just multiplying by
2 using $p<<=1. Isn't it exactly equal to $p*=2 ???

This has anything to do with overflow or the representation of a number?
I though using two-s complement it wouldn't make any difference.

Thanks for you help.


>>     $p <<= 1;
> 
> You are not multiplying $p by 2 like you said which would do what you want:
> 
>       $p *= 2;



use strict;
use bigint;

my $max_depth = shift;
$max_depth = 7 unless defined($max_depth);

sub output_tree($$);

sub left_child_of($) {
  my $p = shift;
  die("3 |/| p-1 (p = $p)") if ($p-1) % 3 != 0;
  $p = ($p-1) / 3;
  if($p % 3 == 0) {
    # stop, there is no left tree
    return $p;
  }
  # keep multiplying by 2, until 3|p-1 and 2 |/| p-1
  while((($p-1) % 3 != 0) || (($p-1) % 2 == 0)) {
    $p <<= 1;
  }
  return $p;
}




-- 
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