Class: SizedBigInt

SizedBigInt()

Sized BigInt's (SizedBigInt) are arbitrary-precision integers with defined number of bits. Each instance is a pair (size,number). Input and output accepts many optional representations.

Original source at github/SizedBigInt and foundations at this PDF.

Constructor

new SizedBigInt()

Source:

Methods

(static) baseLabel(label, retLabel)

Check and normalize the base label. Access the global kx_baseLabel.

Parameters:
Name Type Default Description
label string
retLabel boolean false

to return string instead pointer.

Source:
Returns:
  • object pointer (to the correct kx_baseLabel), or a string with normalized label.

(static) bigint_div(N, D, P) → {Array}

Division N/D. Returns integer part and "normalized fractional part"

Parameters:
Name Type Description
N BigInt

positive numerator.

D BigInt

positive non-zero denominator.

P BigInt

power to be used in 2**P, with P>0.

Source:
Returns:
  • values [integer_part,fractional_part] = [IP,FP] where F=FP*2^P.
Type
Array

(static) ilog2(n) → {integer}

Calculates the integer log2() of a BigInt... So, its number of bits.

Parameters:
Name Type Description
n BigInt

a positive integer.

Source:
Returns:
  • the ilog2(n)=ceil(log2(n))
Type
integer

(static) kx_baseLabel_setRules()

Apply correction rules to SizedBigInt.kx_baseLabel.

Source:

(static) kx_RefreshDefaults()

Internal class-level cache-builder for Base4h and Base16ph complete translations. and generates all other kx_baseLabel global defaults. Singleton Design Pattern.

Source:

(static) kx_trConfig()

Internal cache-builder for input radix methods. Generates the non-default objects. Changes the state of SizedBigInt.kx_tr.

Source:

(static) objSwap() → {object}

Swap-object utility.

Parameters:
Name Type Description
obj. object
Source:
Returns:
  • with swapped key-values.
Type
object

fixbits_last() → {BitInt}

Get the "last numeric SizedBigInt" using same number of bits.

Source:
Returns:
  • the maximum value.
Type
BitInt

fixbits_next(cycle)

Get the "next numeric SizedBigInt" using same number of bits.

Parameters:
Name Type Default Description
cycle false

boolean flag to use Sized Integers as cyclic group (no error on maximum value)

Source:
Returns:

null or BitInt of the "same-bit-length successor" of the current state.

fromInt(val, bits, maxBits)

Input from BigInt or integer part of a Number.

Parameters:
Name Type Default Description
val

Number or BigInt.

bits integer 0

optional, the bit-length of val, to padding zeros.

maxBits integer null

null or maximal number of bits, truncating.

Source:
Returns:
  • new or redefined SizedBigInt.

fromString(strval, radix, maxBits)

Input from string.

Parameters:
Name Type Default Description
strval string

with valid representation for radix.

radix integer 4

the representation adopted in strval, a label of SizedBigInt.kx_baseLabel.

maxBits null

null or maximal number of bits.

Source:
Returns:
  • new or redefined SizedBigInt.

toString(radix) → {string}

Overrides the default toString() method and implements radix convertions.

Parameters:
Name Type Description
radix integer

optional, the base-label (see keys of SizedBigInt.kx_baseLabel)

Source:
Returns:

the solicitated representation.

Type
string