1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.runtime
.cldc
.util
;
12 import cc
.squirreljme
.runtime
.cldc
.annotation
.SquirrelJMEVendorApi
;
20 public final class MathUtils
33 * Rounds to the nearest power of two.
35 * @param __val The value to round.
36 * @return The resultant rounded value.
39 public static int nearestPowerOfTwo(int __val
)
41 int hi
= Math
.max(1, Integer
.highestOneBit(__val
));
42 int mask
= Math
.max(1, hi
- 1);
43 if ((__val
& mask
) >= (hi
>>> 1))