News for hackers. Stuff that matters.
Re:How many Java programmers does it take to round up to a p... by gojomo on Friday November 02, 2007 @04:42AM (#75387)
You could use that approach in Java...

 public int roundUpToPowerOfTwo(int i) {
  return 1 << (int)(Math.ceil(Math.log(i)/Math.log(2)));
 }
...but the first approach that occurred to this Java coder was instead...

 public int roundUpToPowerOfTwo(int i) {
  int rounded = 1;
  while(rounded<i) rounded <<= 1; 
  return rounded;
 }
 

There are no comments on this comment yet.