org.openmali
Class FastMathd

java.lang.Object
  extended by org.openmali.FastMathd

public class FastMathd
extends java.lang.Object

The FastMath class provides fast and optimized mathematical functions.


Nested Class Summary
static class FastMathd.FRExpResultd
          Helper class to return result tuple of frexp()
 
Field Summary
static double DEG_TO_RAD
           
static double E
           
static double INV_PI
           
static double INV_TWO_PI
           
static double LOG10_TO_LOG2
           
static double LOG10_TO_LOG2d
           
static double PI
           
static double PI_HALF
           
static double RAD_TO_DEG
           
static double TWO_PI
           
 
Constructor Summary
FastMathd()
           
 
Method Summary
static double acos(double x)
           
static double asin(double x)
           
static double atan(double x)
           
static double atan2(double y, double x)
           
static double cbrt(double x)
           
static double ceil(double x)
           
static double cos(double x)
           
static double cosh(double x)
           
static boolean epsilonEquals(double v1, double v2, double epsilon)
           
static double floor(double x)
           
static FastMathd.FRExpResultd frexp(double value)
          An implementation of the C standard library frexp() function.
static FastMathd.FRExpResultd frexp(double value, FastMathd.FRExpResultd result)
          An implementation of the C standard library frexp() function.
static int getPrecision()
           
static java.util.Random getRandom()
          Gets the Random generator.
static double hypot(double a, double b)
          sqrt(a^2 + b^2) without under/overflow.
static double invSqrt(double x)
           
static double log(double x)
           
static double log10(double x)
           
static double log1p(double x)
           
static double log2(double x)
           
static double pow(double base, double exp)
           
static double pow2(double base)
           
static double pow3(double base)
           
static double randomDouble()
          Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.
static double randomDouble(float max)
          Generates the next random double (minimum: 0 inclusive).
static double randomDouble(float min, float max)
          Generates the next random double.
static int randomInt()
          Generates the next random int (minimum: 0 inclusive, maximum: Integer.MAX_VALUE exclusive).
static int randomInt(int max)
          Generates the next random int (minimum: 0 inclusive).
static int randomInt(int min, int max)
          Generates the next random int.
static long randomLong()
          Generates the next random long (minimum: 0 inclusive, maximum: Long.MAX_VALUE exclusive).
static long randomLong(long max)
          Generates the next random long (minimum: 0 inclusive).
static long randomLong(long min, long max)
          Generates the next random long.
static void setPrecision(int precision)
           
static double sin(double x)
           
static double sinh(double x)
           
static double sqrt(double x)
           
static double tan(double x)
           
static double tanh(double x)
           
static double toDeg(double x)
           
static double toRad(double x)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PI

public static final double PI
See Also:
Constant Field Values

PI_HALF

public static final double PI_HALF
See Also:
Constant Field Values

TWO_PI

public static final double TWO_PI
See Also:
Constant Field Values

INV_PI

public static final double INV_PI
See Also:
Constant Field Values

INV_TWO_PI

public static final double INV_TWO_PI
See Also:
Constant Field Values

E

public static final double E
See Also:
Constant Field Values

DEG_TO_RAD

public static final double DEG_TO_RAD
See Also:
Constant Field Values

RAD_TO_DEG

public static final double RAD_TO_DEG
See Also:
Constant Field Values

LOG10_TO_LOG2d

public static final double LOG10_TO_LOG2d
See Also:
Constant Field Values

LOG10_TO_LOG2

public static final double LOG10_TO_LOG2
See Also:
Constant Field Values
Constructor Detail

FastMathd

public FastMathd()
Method Detail

setPrecision

public static final void setPrecision(int precision)

getPrecision

public static final int getPrecision()

sin

public static final double sin(double x)

asin

public static final double asin(double x)

sinh

public static final double sinh(double x)

cos

public static final double cos(double x)

acos

public static final double acos(double x)

cosh

public static final double cosh(double x)

tan

public static final double tan(double x)

atan

public static final double atan(double x)

atan2

public static final double atan2(double y,
                                 double x)

tanh

public static final double tanh(double x)

cbrt

public static final double cbrt(double x)

sqrt

public static final double sqrt(double x)

invSqrt

public static final double invSqrt(double x)

ceil

public static final double ceil(double x)

floor

public static final double floor(double x)

log

public static final double log(double x)
Parameters:
x -
Returns:
the natural logarithm (base e)
See Also:
Math.log(double)

log10

public static final double log10(double x)

log1p

public static final double log1p(double x)

log2

public static final double log2(double x)
Parameters:
x -
Returns:
the logarithm to base 2

toDeg

public static final double toDeg(double x)

toRad

public static final double toRad(double x)

pow

public static final double pow(double base,
                               double exp)

pow2

public static final double pow2(double base)

pow3

public static final double pow3(double base)

epsilonEquals

public static final boolean epsilonEquals(double v1,
                                          double v2,
                                          double epsilon)

hypot

public static final double hypot(double a,
                                 double b)
sqrt(a^2 + b^2) without under/overflow.


frexp

public static final FastMathd.FRExpResultd frexp(double value,
                                                 FastMathd.FRExpResultd result)
An implementation of the C standard library frexp() function.

Parameters:
value - the number to split
result -
Returns:
a touple of normalised mantissa and exponent

frexp

public static final FastMathd.FRExpResultd frexp(double value)
An implementation of the C standard library frexp() function.

Parameters:
value - the number to split
Returns:
a touple of normalised mantissa and exponent

getRandom

public static final java.util.Random getRandom()
Gets the Random generator.

Returns:
the Random generator.

randomDouble

public static final double randomDouble()
Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.

The general contract of nextFloat is that one float value, chosen (approximately) uniformly from the range 0.0f (inclusive) to 1.0f (exclusive), is pseudorandomly generated and returned. All 224 possible float values of the form m x 2-24, where m is a positive integer less than 224 , are produced with (approximately) equal probability. The method nextFloat is implemented by class Random as follows:

 public float nextFloat() {
      return next(24) / ((float)(1 << 24));
 }
The hedge "approximately" is used in the foregoing description only because the next method is only approximately an unbiased source of independently chosen bits. If it were a perfect source or randomly chosen bits, then the algorithm shown would choose float values from the stated range with perfect uniformity.

[In early versions of Java, the result was incorrectly calculated as:

 return next(30) / ((float)(1 << 30));
This might seem to be equivalent, if not better, but in fact it introduced a slight nonuniformity because of the bias in the rounding of floating-point numbers: it was slightly more likely that the low-order bit of the significand would be 0 than that it would be 1.]

Returns:
the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.

randomDouble

public static final double randomDouble(float max)
Generates the next random double (minimum: 0 inclusive).

Parameters:
max - the maximum number (exclusive)
Returns:
the generated number.

randomDouble

public static final double randomDouble(float min,
                                        float max)
Generates the next random double.

Parameters:
min - the minimum number (inclusive)
max - the maximum number (exclusive)
Returns:
the generated number.

randomInt

public static final int randomInt()
Generates the next random int (minimum: 0 inclusive, maximum: Integer.MAX_VALUE exclusive).

Returns:
the generated number.

randomInt

public static final int randomInt(int max)
Generates the next random int (minimum: 0 inclusive).

Parameters:
max - the maximum number (exclusive)
Returns:
the generated number.

randomInt

public static final int randomInt(int min,
                                  int max)
Generates the next random int.

Parameters:
min - the minimum number (inclusive)
max - the maximum number (exclusive)
Returns:
the generated number.

randomLong

public static final long randomLong()
Generates the next random long (minimum: 0 inclusive, maximum: Long.MAX_VALUE exclusive).

Returns:
the generated number.

randomLong

public static final long randomLong(long max)
Generates the next random long (minimum: 0 inclusive).

Parameters:
max - the maximum number (exclusive)
Returns:
the generated number.

randomLong

public static final long randomLong(long min,
                                    long max)
Generates the next random long.

Parameters:
min - the minimum number (inclusive)
max - the maximum number (exclusive)
Returns:
the generated number.