org.metasyntactic.math
Class Functions

java.lang.Object
  |
  +--org.metasyntactic.math.Functions

public class Functions
extends java.lang.Object

Simple alternative mathematical functions. Often int based as alternatives to the slower float based ones in java.lang.Math


Method Summary
static java.math.BigInteger[] extendedEuclideanAlgorithm(java.math.BigInteger a, java.math.BigInteger b)
          Input: positive integers a and b Output: integers x and y such that gcd(a, b) = xa + yb
static int extendedEuclidian(int a, int m)
           
static java.math.BigInteger greatestCommonDivisor(java.math.BigInteger a, java.math.BigInteger b)
           
static java.math.BigInteger inverse(java.math.BigInteger a, java.math.BigInteger m)
          Given a and m, we know that gcd(a, m) = a*x + m*y.
static int log2(long num)
           
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

log2

public static int log2(long num)

extendedEuclidian

public static int extendedEuclidian(int a,
                                    int m)

greatestCommonDivisor

public static java.math.BigInteger greatestCommonDivisor(java.math.BigInteger a,
                                                         java.math.BigInteger b)

inverse

public static java.math.BigInteger inverse(java.math.BigInteger a,
                                           java.math.BigInteger m)
Given a and m, we know that gcd(a, m) = a*x + m*y. The inverse of a mod m is defined simply as being x in the bazoot representation of the gcd


extendedEuclideanAlgorithm

public static java.math.BigInteger[] extendedEuclideanAlgorithm(java.math.BigInteger a,
                                                                java.math.BigInteger b)
Input: positive integers a and b Output: integers x and y such that gcd(a, b) = xa + yb


main

public static void main(java.lang.String[] args)