ch.javasoft.util.numeric
Class BigIntegerUtil

java.lang.Object
  extended by ch.javasoft.util.numeric.BigIntegerUtil

public class BigIntegerUtil
extends Object

The BigIntegerUtil contains static utility methods concerning big integers


Method Summary
static BigInteger gcd(BigInteger... values)
          Calculates the greatest common divisor of the specified big integer numbers.
static BigInteger lcm(BigInteger... values)
          Calculates the least common multiple of the specified big integer numbers.
static BigInteger valueOf(Number number)
          Optimized value-of method, should actually be part of BigInteger.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

gcd

public static BigInteger gcd(BigInteger... values)
Calculates the greatest common divisor of the specified big integer numbers. This method might be useful to scale down a vector of big integers.

If all numbers are negative, the resulting gcd is also negative. If all numbers are zero, the result is zero. Otherwise, the result is positive.

Parameters:
values - values for which the gcd is to be computed
Returns:
gcd of all values, negative if all values negative, zero if all values zero, positive otherwise

lcm

public static BigInteger lcm(BigInteger... values)
Calculates the least common multiple of the specified big integer numbers. This method might be useful to scale up a vector of fractions to convert them to integers.

The result is negative if an uneven number of single values is negative, one for no values or if all values are zero and positive otherwise.

Parameters:
values - values for which the lcm is to be computed
Returns:
lcm of all values, negative for uneven number of negative values, one for no values or if all values are zero and positive otherwise

valueOf

public static BigInteger valueOf(Number number)
Optimized value-of method, should actually be part of BigInteger. If the number is any kind of integer, BigInteger.valueOf(long) is used. If number is fraction number, BigFraction.toBigInteger() is used. Otherwise, the number is converted into a string and the string constructor is used to instantiate a big integer.