net.charlesames.utility.math
Class MathMethods

java.lang.Object
  extended by net.charlesames.utility.math.MathMethods

public abstract class MathMethods
extends java.lang.Object

Miscellaneous Math methods.
The author of the permutations and combinations methods is unknown. The code source for these two methods is http://www.koders.com/java/fidB0DF1A89F0472F6F4039AF61944BA2D072AF6032.aspx

Author:
Charles Ames

Field Summary
static double LOG2
           
static double ONE_PLUS
           
static double TINY
           
static double TWO_PI
           
 
Constructor Summary
MathMethods()
           
 
Method Summary
static int abs(int i)
           
static long combinations(long n, long r)
          code source: http://www.koders.com/java/fidB0DF1A89F0472F6F4039AF61944BA2D072AF6032.aspx
static int compareDouble(double value1, double value2)
           
static double doubleFromText(java.lang.String valueText)
          Converts text to double-precision numbers, using option-5 to represent infinity.
static boolean even(int a)
           
static long factorial(int i)
           
static long factorial(long n)
           
static java.lang.String formatDouble(java.lang.Double value, int maxDecimalPoints)
          Converts double-precision numbers into text with a limited number of decimal places.
static long gcd(long a, long b)
           
static boolean haveSmallDifference(double a, double b)
          Tests if the difference between to double-precision numbers is very small.
static java.lang.String htmlFromDouble(double value)
          Converts double-precision numbers to HTML text, using option-5 to represent infinity.
static int intFromText(java.lang.String valueText)
          Converts text to integers, using option-5 to represent infinity.
static boolean isLarge(double a)
          Tests if a double precision number is very large.
static boolean isSmall(double a)
          Tests if a double precision number is very small.
static long lcm(long a, long b)
           
static double modulo(double a, double b)
          Calculates a modulo b using the actual rules of modular arithmetic.
static int modulo(int a, int b)
          Calculates a modulo b using the actual rules of modular arithmetic.
static long permutations(long n, long r)
          code source: http://www.koders.com/java/fidB0DF1A89F0472F6F4039AF61944BA2D072AF6032.aspx
static double reflect(double a, double b)
          Reflects a into the range from 0 to b.
static int reflect(int a, int b)
          Reflects a into the range from 0 to b.
static void sortDescending(double[] array)
           
static java.lang.String textFromDouble(double value)
          Converts double-precision numbers to text, using option-5 to represent infinity.
static java.lang.String textFromInt(int value)
          Converts integers to text, using option-5 to represent infinity.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TINY

public static final double TINY
See Also:
Constant Field Values

ONE_PLUS

public static final double ONE_PLUS
See Also:
Constant Field Values

LOG2

public static final double LOG2

TWO_PI

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

MathMethods

public MathMethods()
Method Detail

modulo

public static int modulo(int a,
                         int b)
Calculates a modulo b using the actual rules of modular arithmetic.

Parameters:
a - The argument
b - The modulus
Returns:
The remainder

reflect

public static int reflect(int a,
                          int b)
Reflects a into the range from 0 to b.

Parameters:
a - The argument
b - The modulus
Returns:
The remainder

even

public static boolean even(int a)
Parameters:
a -
Returns:
True if a is even; false otherwise.

modulo

public static double modulo(double a,
                            double b)
Calculates a modulo b using the actual rules of modular arithmetic.

Parameters:
a - The argument
b - The modulus
Returns:
The remainder

reflect

public static double reflect(double a,
                             double b)
Reflects a into the range from 0 to b.

Parameters:
a - The argument
b - The modulus
Returns:
The remainder

intFromText

public static int intFromText(java.lang.String valueText)
                       throws java.lang.NumberFormatException
Converts text to integers, using option-5 to represent infinity.

Parameters:
valueText -
Returns:
The integer value.
Throws:
java.lang.NumberFormatException

textFromInt

public static java.lang.String textFromInt(int value)
Converts integers to text, using option-5 to represent infinity.

Parameters:
value -
Returns:
The formatted text

isLarge

public static boolean isLarge(double a)
Tests if a double precision number is very large.

Parameters:
a - A double-precision number.
Returns:
True if a is very large; false otherwise;

isSmall

public static boolean isSmall(double a)
Tests if a double precision number is very small.

Parameters:
a - A double-precision number.
Returns:
True if a is very small; false otherwise;

haveSmallDifference

public static boolean haveSmallDifference(double a,
                                          double b)
Tests if the difference between to double-precision numbers is very small.

Parameters:
a - A double-precision number.
b - A double-precision number.
Returns:
True if the difference between a and b is very small; false otherwise;

doubleFromText

public static double doubleFromText(java.lang.String valueText)
Converts text to double-precision numbers, using option-5 to represent infinity.

Parameters:
valueText -
Returns:
The integer value.

formatDouble

public static java.lang.String formatDouble(java.lang.Double value,
                                            int maxDecimalPoints)
Converts double-precision numbers into text with a limited number of decimal places.

Parameters:
value - The input number.
maxDecimalPoints - The maximum number of decimal places.
Returns:
The formatted text.

textFromDouble

public static java.lang.String textFromDouble(double value)
Converts double-precision numbers to text, using option-5 to represent infinity.

Parameters:
value -
Returns:
The formatted text

htmlFromDouble

public static java.lang.String htmlFromDouble(double value)
Converts double-precision numbers to HTML text, using option-5 to represent infinity.

Parameters:
value -
Returns:
The formatted text

gcd

public static long gcd(long a,
                       long b)
Parameters:
a -
b -
Returns:
The greatest common divisor of a and b

lcm

public static long lcm(long a,
                       long b)
Parameters:
a -
b -
Returns:
The least common multiple of a and b

compareDouble

public static int compareDouble(double value1,
                                double value2)
Parameters:
value1 -
value2 -
Returns:
0 if value1 equals value 2

factorial

public static long factorial(int i)
Parameters:
i -
Returns:
The factorial of i

factorial

public static long factorial(long n)
Parameters:
n -
Returns:
The factorial of n

combinations

public static long combinations(long n,
                                long r)
code source: http://www.koders.com/java/fidB0DF1A89F0472F6F4039AF61944BA2D072AF6032.aspx

Parameters:
n -
r -
Returns:
Number of ways of choosing r out of n values.

permutations

public static long permutations(long n,
                                long r)
code source: http://www.koders.com/java/fidB0DF1A89F0472F6F4039AF61944BA2D072AF6032.aspx

Parameters:
n -
r -
Returns:
Number of ways of ordering r out of n values.

sortDescending

public static void sortDescending(double[] array)
Parameters:
array -

abs

public static int abs(int i)
Parameters:
i -
Returns:
i if i > 0; -i otherwise;