com.maryanovsky.gwtutils.client
Class MathUtils

java.lang.Object
  extended by com.maryanovsky.gwtutils.client.MathUtils

public class MathUtils
extends Object

Mathematical utilities.

Author:
Maryanovsky Alexander

Field Summary
static double DEG_TO_RAD
          Coefficient for converting degrees to radians.
protected static int[] POWERS_OF_TWO
          Powers of two.
static double RAD_TO_DEG
          Coefficient for converting radians to degrees.
 
Constructor Summary
MathUtils()
           
 
Method Summary
static double atan2(double dy, double dx)
          Returns the angle component of the polar coordinates of the specified cartesian coordinates (for some reason, there's no atan2 method in GWT's java.lang.Math).
static String doubleToFixedString(double number, int precision)
          Returns a string representation of the specified double, with the specified number of digits following the decimal point.
static int getPowerOfTwo(int n)
          Returns 2^n, for values of n between 0 and 31.
static double log2(double x)
          Returns the logarithm of x, base-2.
static int max(int value0, int... values)
          Returns the maximum of the specified values.
static int min(int value0, int... values)
          Returns the minimum of the specified values.
static int roundDownToMultiple(int value, int factor)
          Returns the largest integer smaller or equal to the specified one which is a multiple of the specified factor.
static int roundUpToMultiple(int value, int factor)
          Returns the smallest integer larger or equal to the specified one, which is a multiple of the specified factor.
static int sgn(int n)
          Returns the sign of the specified number, that is -1 if it is negative, 0 if it is zero and 1 if it positive.
static double sqr(double x)
          The square function.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEG_TO_RAD

public static final double DEG_TO_RAD
Coefficient for converting degrees to radians.

See Also:
Constant Field Values

RAD_TO_DEG

public static final double RAD_TO_DEG
Coefficient for converting radians to degrees.

See Also:
Constant Field Values

POWERS_OF_TWO

protected static final int[] POWERS_OF_TWO
Powers of two.

Constructor Detail

MathUtils

public MathUtils()
Method Detail

roundDownToMultiple

public static int roundDownToMultiple(int value,
                                      int factor)
Returns the largest integer smaller or equal to the specified one which is a multiple of the specified factor.


roundUpToMultiple

public static int roundUpToMultiple(int value,
                                    int factor)
Returns the smallest integer larger or equal to the specified one, which is a multiple of the specified factor.


doubleToFixedString

public static String doubleToFixedString(double number,
                                         int precision)
Returns a string representation of the specified double, with the specified number of digits following the decimal point.


getPowerOfTwo

public static int getPowerOfTwo(int n)
Returns 2^n, for values of n between 0 and 31.


sgn

public static int sgn(int n)
Returns the sign of the specified number, that is -1 if it is negative, 0 if it is zero and 1 if it positive.


sqr

public static double sqr(double x)
The square function.


atan2

public static double atan2(double dy,
                           double dx)
Returns the angle component of the polar coordinates of the specified cartesian coordinates (for some reason, there's no atan2 method in GWT's java.lang.Math).


max

public static int max(int value0,
                      int... values)
Returns the maximum of the specified values.


min

public static int min(int value0,
                      int... values)
Returns the minimum of the specified values.


log2

public static double log2(double x)
Returns the logarithm of x, base-2.