Added convenience method for rounding a number up to a power of two.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@876 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ListUtil.java,v 1.9 2002/09/20 21:27:54 mdb Exp $
|
// $Id: ListUtil.java,v 1.10 2002/10/23 23:31:32 mdb Exp $
|
||||||
|
|
||||||
package com.samskivert.util;
|
package com.samskivert.util;
|
||||||
|
|
||||||
@@ -47,6 +47,14 @@ package com.samskivert.util;
|
|||||||
*/
|
*/
|
||||||
public class ListUtil
|
public class ListUtil
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Rounds the specified value up to the next nearest power of two.
|
||||||
|
*/
|
||||||
|
public static int nextPowerOfTwo (int value)
|
||||||
|
{
|
||||||
|
return (int)Math.pow(2, Math.ceil(Math.log(value) / Math.log(2)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the specified element to the first empty slot in the specified
|
* Adds the specified element to the first empty slot in the specified
|
||||||
* list. Begins searching for empty slots at zeroth index.
|
* list. Begins searching for empty slots at zeroth index.
|
||||||
|
|||||||
Reference in New Issue
Block a user