1. Try it out

    Try the raw Biginteger and Bigrational libraries, short description with some examples below.

  2. Function List

    Some Examples

    Most of the functions, especially the basic functions are implemented as prototypes to the Bigintgers and Bigrationals respectively, so a simple addition of one and one to get two as the expected result (we assume decimal output here) needs the following, ready to be put into the textarea above:

    var one = new Bigint(1);
    var result = one.add(one);
    result.toString();
    

    You can give the Bigint constructor small numbers (up to 226) directly, larger numbers (up to 253) need to be given indirectly:

    var num = 134217728;
    var onehundredthirtyfourmilliontwohundredseventeenthousandsevenhundredtwentyeight = num.toBigint();
    onehundredthirtyfourmilliontwohundredseventeenthousandsevenhundredtwentyeight.toString();
    

    Even larger numbers need to be given as strings:

    var largenumberasastring = "82756729834529384756298356298375629834756298345623894756";
    var largenumber = largenumberasastring.toBigint();
    largenumber.toString();
    

    The rational number follow the same style with the exception of the second format. You can give small number directly:

    var smallfraction = new Bigrational(234,432);
    smallfraction.toString();
    

    Caution: the constructor does no reducing! You have to do it by hand, either in-place with bigrat.normalize() or on a copy with bigrat.reduce()

    var smallfraction = new Bigrational(234,432);
    smallfraction.normalize();
    smallfraction.toString();
    

    Larger numbers as strings:

    var largefractionasastring = "984756398475t3987539/5847698w347349857649569487";
    largefraction = largefractionasastring.toBigrational();
    largefraction.normalize();
    largefraction.toString();
    

    Larger numbers as two Bigintegers:

    var numerator   = "984756398475t39875395847698w347349857649569487";
    var denominator = "8736452873452873465287346528365823756873465t823746";
    numerator = numerator.toBigint();
    denominator = denominator.toBigint();
    largefraction = new Bigrational(numerator, denominator);
    largefraction.normalize();
    largefraction.toString();
    

    Bigrational as two Bigints:

    var numerator   = "-984756398475t39875395847698w347349857649569487";
    var denominator = "8736452873452873465287346528365823756873465t823746";
    numerator = numerator.toBigint();
    denominator = denominator.toBigint();
    largefraction = new Bigrational(numerator, denominator);
    largefraction.normalize();
    numerator2 = largefraction.num;
    denominator2 = largefraction.den;
    sign = largefraction.sign;
    alert(numerator2.toString() + "\r\n" + denominator2.toString() + "\r\n" + sign);
    

    Chaining is possible but does not work between the Bigints and Bigrationals automatically; these are the raw libraries. You need to do it manually as described above.
    Otherwise:

    var a = new Bigint(123);
    var b = new Bigint(243);
    /* c = a * a + b * b */
    var c = a.mul(a).add(b.mul(b));
    /* c = (a * a + b) * b */
    var d = a.mul(a).add(b).mul(b);
    "c = " + c.toString() + "\r\nd = " + d.toString();
    

    Finaly, compute the Riemann Zeta function at s = 3 (Apéry's constant) to 100 decimal digits precision.
    Please be patient, this may last a while. Most of the time is spent in the function D() b.t.w. which is to the highest extend unoptimised.
    Borwein, Peter. An efficient algorithm for the Riemann zeta function. Canadian Mathematical Society Conference Proceedings. Vol. 27. 2000

    function D(n) {
        var ret, sum, i;
        var ret = new Array(n + 1);
        var sum = new Bigrational(0, 1);
        var N = new Bigint(n);
        var num, den;
        for (i = 0; i <= n; i++) {
            num = factorial(n + i - 1).lShift(2 * i);
            den = factorial(n - i).mul(factorial(2 * i));
            num = new Bigrational(num, den);
            num.normalize();
            sum = sum.add(num)
            ret[i] = N.mul(sum.num).div(sum.den);
        }
        return ret;
    }
    function zeta(s, n) {
        var Ds, sum, k;
        Ds = D(n);
        sum = new Bigrational(0, 1);
        var sign = 1;
        var t1, t2, t3, t4, sm1;
        for (k = 0; k < n; k++) {
            t1 = Ds[k].sub(Ds[n]);
            t1.sign = (sign > 0) ? MP_ZPOS : MP_NEG;
            sign = -sign;
            // here is the reason why large s do need more time
            t2 = (k + 1).bigpow(s);
            t3 = new Bigrational(t1, t2);
            t3.normalize();
            sum = sum.add(t3);
        }
        sm1 = 1 - s;
        if (sm1 < 0) {
            t3 = new Bigint(1);
            t3.lShiftInplace(-sm1);
            t4 = new Bigint(1)
            t3 = new Bigrational(t4, t3);
            t2 = (new Bigrational(1, 1)).sub(t3)
        } else {
            //not yet implemented although Bernoulli numbers are
            return (new Bigrational()).setNaN();
        }
        t3 = new Bigrational(Ds[n], new Bigint(1))
        t1 = t3.mul(t2)
        t1.inverse();
        sum = sum.mul(t1);
        return sum;
    }
    var ret = zeta(3,Math.ceil(100*1.3));
    var multiplier = (10).bigpow(100);
    var t = ret.num.mul(multiplier);
    var rs = t.div(ret.den).toString();
    rs.slice(0,1)+"."+rs.slice(1,rs.length)
    

    Yes, the last two lines do not really fit, but if we had a working implementation of an arbitray precision floating point number, we wouldn't have to do it so complicated ;-)

    Common Functions

    Same name for both Bigint and Bigrational (do not mix, they are just the same names). Some do work for JavaScript's native numbers, too, if indicated with Number.
    Despite of their similar names they might work differently. The square root for example does an integer (truncating) square root for Bigintegers but a normal square root with a fractional part to arbitrary but preset precision for Bigrationals.
    add
    Addition
    addInt
    Addition with second argument a small integer
    sub
    Subtraction
    subInt
    Subtraction with second argument a small integer
    mul
    Multiplication
    mulInt
    Multiplication with second argument a small integer
    div
    Division
    divInt
    Division with second argument a small integer
    sqr
    square
    sqrt
    square root
    nthroot
    nth-root (Newton)
    abs
    return absolute value
    copy
    returns a deep copy
    free
    An offering to the garbage-collector. To free it completely it needs an extra oldbignumber = null;
    cmp
    compare. returns MP_GT if the second one is greater, MP_LT if it is smaller and MP_EQ if both are equal
    isNaN
    Is the Number not a number? Number
    setNaN
    The Number is not a number
    isFinite
    is it finite?
    isInf
    is it not finite?
    setInf
    tell that it not finite?
    isEven
    Is the Number even? Number
    isOdd
    Is the Number odd? Number
    isOne
    is it 1 (one)?
    isUnity
    is it one or minus one?
    isZero
    is it zero?
    neg
    change sign of copy and return it
    sign
    Sign of the number Number
    toString
    return value as a string Number
    The Bigint function toString and hence the Bigrational one, too, accepts more bases (2-62) than the native one of the Number object (2-36).
    There is also a primesieve available. This program offers ten functions which are in alphabetical order:
    fill(amount)
    Build a prime sieve up to the amount amount. Allows for skipping of the automated adapting of the sieve-size if amount is chosen high enough.
    Returns: undefined in case of an error
    See also: grow(amount)
    grow(amount)
    Grows the prime sieve by the amount amount. It just builds a new prime sieve with a different limit (if higher then the already existing limit) for now. Mostly used internally.
    Returns: undefined in case of an error
    See also: fill(amount)
    isSmallPrime(number)
    Tests if number is a prime. Automatically builds a sieve if number is larger then the existing sieve.
    Returns: true or false if number is a prime or not, respectively or undefined in case of an error.
    See also: Primesieve.raiseLimit(limit)
    nextPrime(number)
    Searches for the nearest prime larger than number. Automatically builds a sieve if number is larger then the existing sieve.
    Returns: Number or undefined in case of an error
    precPrime(number)
    Searches for the nearest prime smaller than number. Does not automatically build a sieve if number is larger then the existing sieve. Should it?
    Returns: Number or undefined in case of an error
    primePiApprox(number)
    The approximated result (upper bound) of the prime counting function for number
    Returns: Number or undefined in case of an error
    primePi(number)
    The exact result of the prime counting function for number. Automatically builds a sieve if number is larger then the existing sieve.
    Returns: Number or undefined in case of an error
    primeRange(low,high)
    Calculates the range of primes between low and high. It will detect if low and high are reversed and reruns itself with the arguments reversed. Automatically builds a sieve if number is larger then the existing sieve.
    Returns: Array or undefined in case of an error
    primes(number)
    Calculates primes up to and including number. Automatically builds a sieve if number is larger then the existing sieve.
    Returns: Array or undefined in case of an error
    raiseLimit(number)
    This module primesieve has a limit for the maximum size for the automatic sieve building. It is pre-defined at 0x800000 which is one megabyte. This function can raise it to the manager.
    Returns: undefined in case of an error
    sieve()
    Get the raw prime sieve. This function is not implemented in the CLI version.
    Returns: The raw prime sieve, either an `UInt32Array` or a normal `Array`
    sterror()
    An error number to string conversion. The following errors are used:
    1. "Success"
    2. "Argument not an integer"
    3. "Argument too low"
    4. "Argument too high"
    5. "Prime wanted is higher than the limit"
    6. "Unknown error"
    The numbers of the list correspond to the error numbers.
    Returns: String
    See also: error
    error
    Variable holding the error number. For a table of errors see strerror()

    Biginteger

    and
    binary arithmetic c = a&b
    clamp
    strip leading zeros
    clearBit
    clear bit (set to zero) of this
    clear
    An offering to the garbage-collector together with a set-to-zero of the Bigint for later use
    decr
    subtract one from this (like i--;) in-place
    digits
    number of decimal digits (return one for zero)
    divmod
    returns a tuple with the quotient and the modulus respectively, rounding to -inf (like in PARI/GP for example). Differs from divrem when some of the arguments are negative
    divrem
    returns a tuple with the quotient and the reminder respectively
    divremInt
    like divrem but the second argument can be a small integer
    dlShift
    multiply with 2bigbase, return copy
    dlShiftInplace
    multiply with 2bigbase in-place
    drShift
    divide by 2bigbase, return copy
    drShiftInplace
    divide by 2bigbase in-place
    egcd
    extended gcd
    exactDiv3
    works if the number is divisible by three without a reminder
    flipBit
    flip bit of this
    gcd
    compute the greatest common denominator
    getBit
    get bit of this
    grow
    grows the digits array without changing this.used. Returns the new length of the digit array
    highBit
    highest bit set (zero based) Number
    ilog2
    integer logarith base 2 (actually just highBit() + 1)
    ilogb(base)
    integer logarithm of base base
    incr
    add one to this (like i++;) in-place
    isNeg
    is the Bigint smaller than zero?
    isOk
    is a number and is finite
    isPos
    is the Bigint greater than zero?
    isPow2
    is it a power of two? Number
    jacobi
    Jacobi function
    lcm
    lowest common multiplicator
    lowBit
    lowest bit set (zero based) Number
    lShift
    multiply with 2n, return copy
    lShiftInplace
    multiply with 2n in-place
    mask
    create a bitmask c = (1<<n)-1
    mod2d
    returns reminder of division by 2n
    modInv
    modular inverse Number
    mulInt
    multiply with a small integer (< 2bigbase)
    not
    binary arithmetic c = ~a
    notInplace
    binary arithmetic a = ~a
    nthrootold
    integer nth-root (bracketing)
    numSetBits
    Hamming weight
    or
    binary arithmetic c = a|b
    pow
    returns this to the power of a small integer or a Bigint
    random (bits,seed)
    A random Bigint of bits length in bits and optional small integer as the seed to the underlying PRNG (Bob Jenkins' small PRNG (with the extra round))
    rShift
    divide by 2n, return copy
    rShiftInplace
    divide by 2n in-place
    rShiftRounded
    divide by 2n, round to +inf, return copy
    setBit
    set bit (set to one) of this
    swap
    swap two Bigints (with deep copy)
    toNumber
    Bigint to JavaScript Number
    xor
    binary arithmetic c = a^b

    Bigrational

    bernoulli
    Bernoulli numbers
    fastround
    Faster rounding method but with larger results
    fitsBitPrecision
    If number fits a given bit-precision
    fitsDecPrecision
    If number fits a given decimal-precision
    inverse
    Inverses the fraction in-place
    isBitPrecision
    If number is of given bit-precision
    isDecPrecision
    If number is of given decimal-precision
    isEpsGreaterZero
    greater than zero plus EPS
    isEpsLowerZero
    lower than zero minus EPS
    isEpsZero
    number inside range zero plus/minus EPS
    isInt
    is the number an integer, that is, is the denominator one
    isLowerOne
    Is the absolute value between zero and one
    normalize
    Reduce the fraction in-place
    parts
    returns the parts of the fraction splitted into the integer part and the fraction part
    powInt
    to the power of a small integer
    reciprocal
    returns reciprocal of the fraction
    reduce
    returns the reduced fraction
    round
    Median rounding

    Integer Functions

    These are normal JavaScript functions, no prototypes.
    There are some tricks used with the factors of factorials, the functions can be used themself but they were not meant for that and hence are tricky to use. Please see the source for more information until proper documentation has been written.
    add_factored_factorial
    compute_factored_factorial
    compute_signed_factored_factorial
    factor_factorial
    negate_factored_factorials
    power_factored_factorials
    subtract_factored_factorials( subtrahend,
    The normal integer functions are:
    bell
    Bell numbers
    binomial
    Binomial coefficients
    catalan
    Catalan numbers
    doublefactorial
    Doublefactorial
    euler
    Eulerian (zig) numbers
    factorial
    Factorial
    fallingfactorial
    Falling factorial
    fibonacci
    Fibonacci numbers (fast algorithm using matrix exponentiation)
    free_stirling1cache
    Make offerings to the garbage-collector
    free_stirling2cache
    Make offerings to the garbage-collector
    prime_divisors
    How often does the prime p divide the factorial of the number n
    risingfactorial
    Rising factorial</dd>
    stirling1
    Stirling numbers of the first kind (cached)
    stirling2
    Stirling numbers of the second kind (series, faster for small numbers)
    stirling2caching
    Stirling numbers of the second kind (cached)
    subfactorial
    Sub-factorial (derangement)
    superfactorial
    Superfactorial (as defined by Sloane and Plouffe)

Needful Links