Home Manual Reference Source Test Repository

Function

Static Public Summary
public

and(a: *, a0: *, b: *, b0: *, c: *, c0: *, c1: *)

BINARY and APPLIED ON a AND b

public

badd_t(r: int): *

public

band_t(r: *): *

BIG ENDIAN BINARY and APPLIED ON a AND b

public

bcmp_t(): *

public

bdiv_t(lt: *, sub: *): *

public

bkaratsuba_t(add: function, sub: function, mul: function, calloc: function, mov: function, r: uint, wrap: function): *

/!\ BLOCK MULTIPLICATION RESULT MUST HOLD IN THE JAVASCRIPT NUMBER TYPE (DOUBLE i.e.

public

bmul53_t(r: *): *

/!\ BLOCK MULTIPLICATION RESULT MUST HOLD IN THE JAVASCRIPT NUMBER TYPE (DOUBLE i.e.

public

bmul_t(r: *): *

public

bsub_t(r: int): *

public

convert(f: *, t: *, a: *, ai: *, aj: *): *

public

convert_keep_zeros(f: *, t: *, a: *, ai: *, aj: *): *

public

eq_t(cmp: *): *

Wrapper for a comparison operator that returns true iff a is equal to b.

public

ge_t(cmp: *): *

Wrapper for a comparison operator that returns true iff a is greater or equal to b.

public

gt_t(cmp: *): *

Wrapper for a comparison operator that returns true iff a is greater than b.

public

ladd_t(r: int): *

public

land_t(r: *): *

LITTLE ENDIAN BINARY and APPLIED ON a AND b

public

lcmp_t(): *

public

le_t(cmp: *): *

Wrapper for a comparison operator that returns true iff a is less or equal to b.

public

lmul53_t(r: *): *

/!\ BLOCK MULTIPLICATION RESULT MUST HOLD IN THE JAVASCRIPT NUMBER TYPE (DOUBLE i.e.

public

lsub_t(r: int): *

public

lt_t(cmp: *): *

Wrapper for a comparison operator that returns true iff a is less than b.

public

ne_t(cmp: *): *

Wrapper for a comparison operator that returns true iff a is not equal to b.

public

parse(f: *, t: *, string: *): *

public

parse_keep_zeros(f: *, t: *, string: *): *

public

parse_t(t: int, f: int, iter: function): *

Function template for number parsing.

public

stringify(f: *, t: *, a: *, ai: *, aj: *): *

public

stringify_keep_zeros(f: *, t: *, a: *, ai: *, aj: *): *

public

stringify_t(f: int, t: int, iter: function, zfill_t: function): *

Function template for number stringification.

public

trim_natural(a: *, ai: *, aj: *): *

public

wrapbin(fn: *): *

Wrapper for binary operator.

public

wrapcmp(cmp: *): *

public

wrapmov(fn: *): *

Static Private Summary
private

_CMP(a: array, ai: int, aj: int, b: array, bi: int, bj: int): int

Compares two big endian arrays, |a| >= |b|

private

__pow__(alloc: *, isnotzero: *, setone: *, iseven: *, div2: *, minus1: *)

Computes pow(a, b) using naive exponentiation.

private

_alloc(n: *): *

private

_build(base: *, number: *): *

private

_chr(x: *): *

private

_cmp(a: *, ai: *, aj: *, b: *, bi: *, bj: *): *

private

_convert(f: Number, t: Number, a: Array, ai: Number, aj: Number, b: Array, bi: Number, bj: Number): *

private

_convert_slow(f: Number, t: Number, a: Array, ai: Number, aj: Number, b: Array, bi: Number, bj: Number)

private

_convert_to_larger(f: Number, t: Number, a: Array, ai: Number, aj: Number, b: Array, bi: Number, bj: Number): *

private

_convert_to_larger_fast(ar: Number, z: Number, a: Array, ai: Number, aj: Number, b: Array, bi: Number, bj: Number)

private

_convert_to_smaller(f: Number, t: Number, a: Array, ai: Number, aj: Number, b: Array, bi: Number, bj: Number): *

private

_convert_to_smaller_fast(br: Number, z: Number, a: Array, ai: Number, aj: Number, b: Array, bi: Number, bj: Number)

private

_copy(a: *, ai: *, aj: *, b: *, bi: *)

private

_div(x: int, r: array, ri: int, rj: int, b: array, bi: int, bj: int, q: array, qi: int)

Computes quotient and remainder of two big endian arrays.

private

_ebs__(alloc: *, iszero: *, setone: *, iseven: *, div2: *, minus1: *)

Computes pow(a, b) using exponentiation by squaring.

private

_fill(a: *, ai: *, aj: *, v: *)

private

_int(x: *): *

private

_jz(a: array, ai: int, aj: int): boolean

Returns true if number is 0.

private

_log(x: *, y: *): *

private

_reset(a: *, ai: *, aj: *)

private

_sub(r: int, a: array, ai: int, aj: int, b: array, bi: int, bj: int, c: array, ci: int, cj: int)

Subtracts two big endian arrays, k >= i >= j wraps

private

_to_string(b: *): *

private

_trim_positive(a: *, ai: *, aj: *): *

private

_zeros(n: *): *

Static Public

public and(a: *, a0: *, b: *, b0: *, c: *, c0: *, c1: *) source

BINARY and APPLIED ON a AND b

Meaningful only when r is a power of 2.

|a| = |b| = |c| > 0

Params:

NameTypeAttributeDescription
a *
a0 *
b *
b0 *
c *
c0 *
c1 *

public badd_t(r: int): * source

Params:

NameTypeAttributeDescription
r int

base (radix)

Return:

*

public band_t(r: *): * source

BIG ENDIAN BINARY and APPLIED ON a AND b

Meaningful only when r is a power of 2.

|a| >= |b| > 0

treats b as if it was represented with the same number of blocks as a

Params:

NameTypeAttributeDescription
r *

Return:

*

public bcmp_t(): * source

Return:

*

public bdiv_t(lt: *, sub: *): * source

Params:

NameTypeAttributeDescription
lt *
sub *

Return:

*

public bkaratsuba_t(add: function, sub: function, mul: function, calloc: function, mov: function, r: uint, wrap: function): * source

/!\ BLOCK MULTIPLICATION RESULT MUST HOLD IN THE JAVASCRIPT NUMBER TYPE (DOUBLE i.e. 53 bits)

EXPLANATION

###########

We consider the numbers a and b, both of size N = 2n.

We divide a and b into their lower and upper parts.

a = a1 r^{n} + a0 (1) b = b1 r^{n} + b0 (2)

We express the product of a and b using their lower and upper parts.

a b = (a1 r^{n} + a0) (b1 r^{n} + b0) (3) = a1 b1 r^{2n} + (a1 b0 + a0 b1) r^{n} + a0 b0 (4)

This gives us 4 multiplications with operands of size n. Using a simple trick, we can reduce this computation to 3 multiplications.

We give the 3 terms of (4) the names z0, z1 and z2.

z2 = a1 b1 z1 = a1 b0 + a0 b1 z0 = a0 b0

a b = z2 r^{2n} + z1 r^{n} + z0

We then express z1 using z0, z2 and one additional multiplication.

(a1 + a0)(b1 + b0) = a1 b1 + a0 b0 + (a1 b0 + a0 b1) = z2 + z0 + z1

z1 = (a1 + a0)(b1 + b0) - z2 - z0

AN ANOTHER WAY AROUND (not used here)

(a1 - a0)(b1 - b0) = (a1 b1 + a0 b0) - (a1 b0 + a0 b1) (a0 - a1)(b1 - b0) = (a1 b0 + a0 b1) - (a1 b1 + a0 b0) a b = (r^{2n} + r^{n})a1 b1 + r^{n}(a0 - a1)(b1 - b0) + (r^{n} + 1)a0 b0

This algorithm is a generalization of the Toom-Cook algorithm, when m = n = 2.

For further reference, see

Params:

NameTypeAttributeDescription
add function

addition algorithm

sub function

subtraction algorithm

mul function

multiplication algorithm

calloc function

array allocator

mov function

copy algorithm

r uint

base (radix)

wrap function

recursive multiplication algorithm

Return:

*

public bmul53_t(r: *): * source

/!\ BLOCK MULTIPLICATION RESULT MUST HOLD IN THE JAVASCRIPT NUMBER TYPE (DOUBLE i.e. 53 bits)

big endian 1 block multiplication

Params:

NameTypeAttributeDescription
r *

Return:

*

public bmul_t(r: *): * source

Params:

NameTypeAttributeDescription
r *

Return:

*

public bsub_t(r: int): * source

Params:

NameTypeAttributeDescription
r int

base (radix)

Return:

*

public convert(f: *, t: *, a: *, ai: *, aj: *): * source

Params:

NameTypeAttributeDescription
f *
t *
a *
ai *
aj *

Return:

*

public convert_keep_zeros(f: *, t: *, a: *, ai: *, aj: *): * source

Params:

NameTypeAttributeDescription
f *
t *
a *
ai *
aj *

Return:

*

public eq_t(cmp: *): * source

Wrapper for a comparison operator that returns true iff a is equal to b.

Params:

NameTypeAttributeDescription
cmp *

Return:

*

public ge_t(cmp: *): * source

Wrapper for a comparison operator that returns true iff a is greater or equal to b.

Params:

NameTypeAttributeDescription
cmp *

Return:

*

public gt_t(cmp: *): * source

Wrapper for a comparison operator that returns true iff a is greater than b.

Params:

NameTypeAttributeDescription
cmp *

Return:

*

public ladd_t(r: int): * source

Params:

NameTypeAttributeDescription
r int

base (radix)

Return:

*

public land_t(r: *): * source

LITTLE ENDIAN BINARY and APPLIED ON a AND b

Meaningful only when r is a power of 2.

|a| >= |b| > 0

treats b as if it was represented with the same number of blocks as a

Params:

NameTypeAttributeDescription
r *

Return:

*

public lcmp_t(): * source

Return:

*

public le_t(cmp: *): * source

Wrapper for a comparison operator that returns true iff a is less or equal to b.

Params:

NameTypeAttributeDescription
cmp *

Return:

*

public lmul53_t(r: *): * source

/!\ BLOCK MULTIPLICATION RESULT MUST HOLD IN THE JAVASCRIPT NUMBER TYPE (DOUBLE i.e. 53 bits)

little endian 1 block multiplication

Params:

NameTypeAttributeDescription
r *

Return:

*

public lsub_t(r: int): * source

Params:

NameTypeAttributeDescription
r int

base (radix)

Return:

*

public lt_t(cmp: *): * source

Wrapper for a comparison operator that returns true iff a is less than b.

Params:

NameTypeAttributeDescription
cmp *

Return:

*

public ne_t(cmp: *): * source

Wrapper for a comparison operator that returns true iff a is not equal to b.

Params:

NameTypeAttributeDescription
cmp *

Return:

*

public parse(f: *, t: *, string: *): * source

Params:

NameTypeAttributeDescription
f *
t *
string *

Return:

*

public parse_keep_zeros(f: *, t: *, string: *): * source

Params:

NameTypeAttributeDescription
f *
t *
string *

Return:

*

public parse_t(t: int, f: int, iter: function): * source

Function template for number parsing. Endianess provided by the iterator function iterator function must be reverse ordered

Params:

NameTypeAttributeDescription
t int

to radix

f int

from radix

iter function

iterator function

Return:

*

public stringify(f: *, t: *, a: *, ai: *, aj: *): * source

Params:

NameTypeAttributeDescription
f *
t *
a *
ai *
aj *

Return:

*

public stringify_keep_zeros(f: *, t: *, a: *, ai: *, aj: *): * source

Params:

NameTypeAttributeDescription
f *
t *
a *
ai *
aj *

Return:

*

public stringify_t(f: int, t: int, iter: function, zfill_t: function): * source

Function template for number stringification. Endianess provided by the iterator function

Params:

NameTypeAttributeDescription
f int

from radix

t int

to radix

iter function

iterator function

zfill_t function

zero fill string function

Return:

*

public trim_natural(a: *, ai: *, aj: *): * source

Params:

NameTypeAttributeDescription
a *
ai *
aj *

Return:

*

public wrapbin(fn: *): * source

Wrapper for binary operator. Ensures

i >= j
i0, j0, k0 >= 0

Params:

NameTypeAttributeDescription
fn *

Return:

*

public wrapcmp(cmp: *): * source

Params:

NameTypeAttributeDescription
cmp *

Return:

*

public wrapmov(fn: *): * source

Params:

NameTypeAttributeDescription
fn *

Return:

*

Static Private

private _CMP(a: array, ai: int, aj: int, b: array, bi: int, bj: int): int source

Compares two big endian arrays, |a| >= |b|

Params:

NameTypeAttributeDescription
a array

first operand

ai int

a left

aj int

a right

b array

second operand

bi int

b left

bj int

b right

Return:

int

result 1 if a > b; 0 if a = b; -1 otherwise.

private __pow__(alloc: *, isnotzero: *, setone: *, iseven: *, div2: *, minus1: *) source

Computes pow(a, b) using naive exponentiation.

Params:

NameTypeAttributeDescription
alloc *
isnotzero *
setone *
iseven *
div2 *
minus1 *

private _alloc(n: *): * source

Params:

NameTypeAttributeDescription
n *

Return:

*

private _build(base: *, number: *): * source

Params:

NameTypeAttributeDescription
base *
number *

Return:

*

private _chr(x: *): * source

Params:

NameTypeAttributeDescription
x *

Return:

*

private _cmp(a: *, ai: *, aj: *, b: *, bi: *, bj: *): * source

Params:

NameTypeAttributeDescription
a *
ai *
aj *
b *
bi *
bj *

Return:

*

private _convert(f: Number, t: Number, a: Array, ai: Number, aj: Number, b: Array, bi: Number, bj: Number): * source

Params:

NameTypeAttributeDescription
f Number

the base to convert from

t Number

the base to convert to

a Array

the origin array

ai Number

start offset in the origin array

aj Number

end offset in the origin array

b Array

the destination array

bi Number

start offset in the destination array

bj Number

end offset in the destination array

Return:

*

private _convert_slow(f: Number, t: Number, a: Array, ai: Number, aj: Number, b: Array, bi: Number, bj: Number) source

Params:

NameTypeAttributeDescription
f Number

the base to convert from

t Number

the base to convert to

a Array

the origin array

ai Number

start offset in the origin array

aj Number

end offset in the origin array

b Array

the destination array

bi Number

start offset in the destination array

bj Number

end offset in the destination array

private _convert_to_larger(f: Number, t: Number, a: Array, ai: Number, aj: Number, b: Array, bi: Number, bj: Number): * source

Params:

NameTypeAttributeDescription
f Number

the base to convert from

t Number

the base to convert to

a Array

the origin array

ai Number

start offset in the origin array

aj Number

end offset in the origin array

b Array

the destination array

bi Number

start offset in the destination array

bj Number

end offset in the destination array

Return:

*

private _convert_to_larger_fast(ar: Number, z: Number, a: Array, ai: Number, aj: Number, b: Array, bi: Number, bj: Number) source

Params:

NameTypeAttributeDescription
ar Number

the base to convert from

z Number

if br is the base to convert to then log(br) = z log(ar)

a Array

the origin array

ai Number

start offset in the origin array

aj Number

end offset in the origin array

b Array

the destination array

bi Number

start offset in the destination array

bj Number

end offset in the destination array

private _convert_to_smaller(f: Number, t: Number, a: Array, ai: Number, aj: Number, b: Array, bi: Number, bj: Number): * source

Params:

NameTypeAttributeDescription
f Number

the base to convert from

t Number

the base to convert to

a Array

the origin array

ai Number

start offset in the origin array

aj Number

end offset in the origin array

b Array

the destination array

bi Number

start offset in the destination array

bj Number

end offset in the destination array

Return:

*

private _convert_to_smaller_fast(br: Number, z: Number, a: Array, ai: Number, aj: Number, b: Array, bi: Number, bj: Number) source

Params:

NameTypeAttributeDescription
br Number

the base to convert to

z Number

if ar is the base to convert to then log(ar) = z log(br)

a Array

the origin array

ai Number

start offset in the origin array

aj Number

end offset in the origin array

b Array

the destination array

bi Number

start offset in the destination array

bj Number

end offset in the destination array

private _copy(a: *, ai: *, aj: *, b: *, bi: *) source

Params:

NameTypeAttributeDescription
a *
ai *
aj *
b *
bi *

private _div(x: int, r: array, ri: int, rj: int, b: array, bi: int, bj: int, q: array, qi: int) source

Computes quotient and remainder of two big endian arrays.

Computes quotient and remainder of two big endian arrays using long division algorithm (the one teached in european primary schools).

/!\ This algorithm modifies its first operand.

HYP : q is at least as large as r b is not zero

Params:

NameTypeAttributeDescription
x int

the radix

r array

dividend and remainder

ri int

r left

rj int

r right

b array

divisor

bi int

b left

bj int

b right

q array

quotient, must be 0 initialized

qi int

q left

private _ebs__(alloc: *, iszero: *, setone: *, iseven: *, div2: *, minus1: *) source

Computes pow(a, b) using exponentiation by squaring.

could add an additional base case for b = 1

Params:

NameTypeAttributeDescription
alloc *
iszero *
setone *
iseven *
div2 *
minus1 *

private _fill(a: *, ai: *, aj: *, v: *) source

Params:

NameTypeAttributeDescription
a *
ai *
aj *
v *

private _int(x: *): * source

Params:

NameTypeAttributeDescription
x *

Return:

*

private _jz(a: array, ai: int, aj: int): boolean source

Returns true if number is 0.

Params:

NameTypeAttributeDescription
a array

first operand

ai int

a left

aj int

a right

Return:

boolean

private _log(x: *, y: *): * source

Params:

NameTypeAttributeDescription
x *
y *

Return:

*

private _reset(a: *, ai: *, aj: *) source

Params:

NameTypeAttributeDescription
a *
ai *
aj *

private _sub(r: int, a: array, ai: int, aj: int, b: array, bi: int, bj: int, c: array, ci: int, cj: int) source

Subtracts two big endian arrays, k >= i >= j wraps

Params:

NameTypeAttributeDescription
r int

base (radix)

a array

first operand

ai int

a left

aj int

a right

b array

second operand

bi int

b left

bj int

b right

c array

result, must be 0 initialized

ci int

c left

cj int

c right

private _to_string(b: *): * source

Params:

NameTypeAttributeDescription
b *

Return:

*

private _trim_positive(a: *, ai: *, aj: *): * source

Params:

NameTypeAttributeDescription
a *
ai *
aj *

Return:

*

private _zeros(n: *): * source

Params:

NameTypeAttributeDescription
n *

Return:

*