From fb3be71567e36951bb773c7652132dfb00cd4329 Mon Sep 17 00:00:00 2001 From: mdb Date: Wed, 23 Oct 2002 23:31:32 +0000 Subject: [PATCH] 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 --- .../src/java/com/samskivert/util/ListUtil.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/ListUtil.java b/projects/samskivert/src/java/com/samskivert/util/ListUtil.java index 606e122f..31e2456c 100644 --- a/projects/samskivert/src/java/com/samskivert/util/ListUtil.java +++ b/projects/samskivert/src/java/com/samskivert/util/ListUtil.java @@ -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; @@ -47,6 +47,14 @@ package com.samskivert.util; */ 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 * list. Begins searching for empty slots at zeroth index.