com.brackeen.javagamebook.util
Class MoreMath

java.lang.Object
  extended bycom.brackeen.javagamebook.util.MoreMath

public class MoreMath
extends java.lang.Object

The MoreMath class provides functions not contained in the java.lang.Math or java.lang.StrictMath classes.


Constructor Summary
MoreMath()
           
 
Method Summary
static int ceil(float f)
          Faster ceil function to convert a float to an int.
static boolean chance(float p)
          Returns true if a random "event" occurs.
static int floor(float f)
          Faster floor function to convert a float to an int.
static int getBitCount(int n)
          Gets the number of "on" bits in an integer.
static boolean isPowerOfTwo(int n)
          Returns true if the specified number is a power of 2.
static float random(float max)
          Returns a random float from 0 to max (inclusive).
static float random(float min, float max)
          Returns a random float from min to max (inclusive).
static int random(int max)
          Returns a random integer from 0 to max (inclusive).
static int random(int min, int max)
          Returns a random integer from min to max (inclusive).
static java.lang.Object random(java.util.List list)
          Returns a random object from a List.
static int sign(double v)
          Returns the sign of the number.
static int sign(float v)
          Returns the sign of the number.
static int sign(int v)
          Returns the sign of the number.
static int sign(long v)
          Returns the sign of the number.
static int sign(short v)
          Returns the sign of the number.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MoreMath

public MoreMath()
Method Detail

sign

public static int sign(short v)
Returns the sign of the number. Returns -1 for negative, 1 for positive, and 0 otherwise.


sign

public static int sign(int v)
Returns the sign of the number. Returns -1 for negative, 1 for positive, and 0 otherwise.


sign

public static int sign(long v)
Returns the sign of the number. Returns -1 for negative, 1 for positive, and 0 otherwise.


sign

public static int sign(float v)
Returns the sign of the number. Returns -1 for negative, 1 for positive, and 0 otherwise.


sign

public static int sign(double v)
Returns the sign of the number. Returns -1 for negative, 1 for positive, and 0 otherwise.


ceil

public static int ceil(float f)
Faster ceil function to convert a float to an int. Contrary to the java.lang.Math ceil function, this function takes a float as an argument, returns an int instead of a double, and does not consider special cases.


floor

public static int floor(float f)
Faster floor function to convert a float to an int. Contrary to the java.lang.Math floor function, this function takes a float as an argument, returns an int instead of a double, and does not consider special cases.


random

public static int random(int max)
Returns a random integer from 0 to max (inclusive).


random

public static int random(int min,
                         int max)
Returns a random integer from min to max (inclusive).


random

public static float random(float max)
Returns a random float from 0 to max (inclusive).


random

public static float random(float min,
                           float max)
Returns a random float from min to max (inclusive).


random

public static java.lang.Object random(java.util.List list)
Returns a random object from a List.


chance

public static boolean chance(float p)
Returns true if a random "event" occurs. The specified value, p, is the probability (0 to 1) that the random "event" occurs.


isPowerOfTwo

public static boolean isPowerOfTwo(int n)
Returns true if the specified number is a power of 2.


getBitCount

public static int getBitCount(int n)
Gets the number of "on" bits in an integer.