org.apfloat
Class ApintMath

java.lang.Object
  |
  +--org.apfloat.ApintMath

public class ApintMath
extends java.lang.Object

Various mathematical functions for arbitrary precision integers.


Method Summary
static Apint abs(Apint x)
          Absolute value.
static Apint[] cbrt(Apint x)
          Cube root and remainder.
static Apint[] div(Apint x, Apint y)
          Quotient and remainder.
static Apint gcd(Apint a, Apint b)
          Greatest common divisor.
static Apint lcm(Apint a, Apint b)
          Least common multiple.
static Apint modMultiply(Apint a, Apint b, Apint m)
          Modular multiplication.
static Apint modPow(Apint a, Apint b, Apint m)
          Modular power.
static Apint negate(Apint x)
          Returns an apint whose value is -x.
static Apint pow(Apint x, long n)
          Integer power.
static Apint[] root(Apint x, long n)
          Positive integer root and remainder.
static Apint scale(Apint x, long scale)
          Multiply by a power of the radix.
static Apint[] sqrt(Apint x)
          Square root and remainder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

pow

public static Apint pow(Apint x,
                        long n)
                 throws java.lang.ArithmeticException,
                        ApfloatRuntimeException
Integer power.

Parameters:
x - Base of the power operator.
n - Exponent of the power operator.
Returns:
x to the n:th power, that is xn.
Throws:
java.lang.ArithmeticException - If both x and n are zero.
ApfloatRuntimeException

sqrt

public static Apint[] sqrt(Apint x)
                    throws java.lang.ArithmeticException,
                           ApfloatRuntimeException
Square root and remainder.

Parameters:
x - The argument.
Returns:
An array of two apints: [q, r], where q2 + r = x.
Throws:
java.lang.ArithmeticException - If x is negative.
ApfloatRuntimeException

cbrt

public static Apint[] cbrt(Apint x)
                    throws ApfloatRuntimeException
Cube root and remainder.

Parameters:
x - The argument.
Returns:
An array of two apints: [q, r], where q3 + r = x.
ApfloatRuntimeException

root

public static Apint[] root(Apint x,
                           long n)
                    throws java.lang.ArithmeticException,
                           ApfloatRuntimeException
Positive integer root and remainder.

Returns the n:th root of x, that is x1/n, rounded towards zero.

Parameters:
x - The argument.
n - Which root to take.
Returns:
An array of two apints: [q, r], where qn + r = x.
Throws:
java.lang.ArithmeticException - If n and x are zero, or x is negative and n is even.
ApfloatRuntimeException

negate

public static Apint negate(Apint x)
                    throws ApfloatRuntimeException
Returns an apint whose value is -x.

Parameters:
x - The argument.
Returns:
-x.
ApfloatRuntimeException

abs

public static Apint abs(Apint x)
                 throws ApfloatRuntimeException
Absolute value.

Parameters:
x - The argument.
Returns:
Absolute value of x.
ApfloatRuntimeException

scale

public static Apint scale(Apint x,
                          long scale)
                   throws ApfloatRuntimeException
Multiply by a power of the radix. Any rounding will occur towards zero.

Parameters:
x - The argument.
scale - The scaling factor.
Returns:
x*x.radix()scale.
ApfloatRuntimeException

div

public static Apint[] div(Apint x,
                          Apint y)
                   throws java.lang.ArithmeticException,
                          ApfloatRuntimeException
Quotient and remainder.

Parameters:
x - The dividend.
y - The divisor.
Returns:
An array of two apints: [quotient, remainder], that is [x / y, x % y].
Throws:
java.lang.ArithmeticException - In case the divisor is zero.
ApfloatRuntimeException

gcd

public static Apint gcd(Apint a,
                        Apint b)
                 throws ApfloatRuntimeException
Greatest common divisor. This method returns a positive number even if one of a and b is negative.

Parameters:
a - First argument.
b - Second argument.
Returns:
Greatest common divisor of a and b.
ApfloatRuntimeException

lcm

public static Apint lcm(Apint a,
                        Apint b)
                 throws ApfloatRuntimeException
Least common multiple. This method returns a positive number even if one of a and b is negative.

Parameters:
a - First argument.
b - Second argument.
Returns:
Least common multiple of a and b.
ApfloatRuntimeException

modMultiply

public static Apint modMultiply(Apint a,
                                Apint b,
                                Apint m)
                         throws ApfloatRuntimeException
Modular multiplication. Returns a * b % m

Parameters:
a - First argument.
b - Second argument.
m - Modulus.
Returns:
a * b mod m
ApfloatRuntimeException

modPow

public static Apint modPow(Apint a,
                           Apint b,
                           Apint m)
                    throws ApfloatRuntimeException
Modular power.

Parameters:
a - Base.
b - Exponent. Should be non-negative, since the modulus can't be factorized with this implementation.
m - Modulus.
Returns:
ab mod m
ApfloatRuntimeException