Home Reference Source
import BigInteger from 'konpeito/src/math/core/BigInteger.js'
public class | source

BigInteger

Extends:

KonpeitoInteger → BigInteger

Arbitrary-precision integer class (immutable).

Static Member Summary

Static Public Members
public static get

-1

public static get

Negative Infinity.

public static get

Not a Number.

public static get

1

public static get

Positive infinity.

public static get

10

public static get

2

public static get

0

Static Method Summary

Static Public Methods
public static

Create an entity object of this class.

public static

Random number of specified bit length.

public static

Return default Random class.

public static

Prime represented within the specified bit length.

public static

Set default class of random.

public static

Create an arbitrary-precision integer.

Constructor Summary

Public Constructor
public

Create an arbitrary-precision integer.

Member Summary

Public Members
public get

boolean value.

public get

64-bit floating point.

public get

64-bit integer value.

Private Members
private

An integer consisting of 16 bits per element of the array.

private

Numeric state.

Method Summary

Public Methods
public

Absolute value.

public

Add.

public

Logical AND.

public

Sum that the bit is 1 when represented in the two's complement.

public

Length when the number is binary.

public

Cube root.

public

Ceil.

public

Lower a specific bit.

public

Clip number within range.

public

Deep copy.

public

Compare values.

public

Compare values without sign.

public

Divide.

public

Divide.

public

Divide and rem.

public

Equals.

public

Numeric type match.

public

Extended Euclidean algorithm.

public

Factorization.

public

Factorial function, x!.

public

To integer rounded down to the nearest.

public

Invert a specific bit.

public

Floor.

public

Fraction.

public

Euclidean algorithm.

public

Number of digits in which the number "1" appears first when expressed in binary.

public

Value at the specified position of the internally used array that composed of hexadecimal numbers.

public

Inverse number of this value.

public

Return true if the value is finite number.

public

this === Infinity or -Infinity

public

this === NaN

public

this < 0

public

this === -Infinity

public

this >= 0

public

this === 1

public

this > 0

public

this === Infinity

public

Return true if the value is prime number.

public

Return true if the value is prime number by Miller-Labin prime number determination method.

public

this === 0

public

Least common multiple.

public

log_10(x)

public

log_2(x)

public

Maximum number.

public

Minimum number.

public

Modulo, positive rem of division.

public

Modular multiplicative inverse.

public

Modular exponentiation.

public

Multiply.

public

Multiply.

public

this * -1

public

Next prime.

public

Logical Not.

public

Logical OR.

public

Power function.

public

Remainder of division.

public

Remainder of division.

public

Rounding to the nearest integer.

public

Multiply a multiple of ten.

public

this | (1 << n)

public

this << n

public

this << n

public

this >> n

public

The positive or negative sign of this number.

public

The positive or negative sign of this number.

public

Square root.

public

Square.

public

Subtract.

public

Subtract.

public

Test if a particular bit is on.

public

return BigDecimal.

public

return BigInteger.

public

return Complex.

public

return Fraction.

public

Convert to JSON.

public

return Matrix.

public

Convert to string.

public

Logical Exclusive-OR.

Private Methods
private

this <<= n

private

Create a numerical value for addition.

Inherited Summary

From class KonpeitoInteger
public static get

-1

public static get

Negative Infinity.

public static get

Not a Number.

public static get

1

public static get

Positive infinity.

public static get

10

public static get

2

public static get

0

public static

create(number: any): KonpeitoInteger

Create an entity object of this class.

public static

valueOf(number: any): KonpeitoInteger

Create number.

public get

boolean value.

public get

floating point.

public get

integer value.

public

Absolute value.

public

add(number: any): KonpeitoInteger

Add.

public

and(number: any): KonpeitoInteger

Logical AND.

public

Ceil.

public

Deep copy.

public

compareTo(number: any): number

Compare values.

public

div(number: any): KonpeitoInteger

Divide.

public

divide(number: any): KonpeitoInteger

Divide.

public

equals(number: any): boolean

Equals.

public

extgcd(number: any): KonpeitoInteger[]

Extended Euclidean algorithm.

public

Factorization.

public

Factorial function, x!.

public

To integer rounded down to the nearest.

public

Floor.

public

Fraction.

public

gcd(number: any): KonpeitoInteger

Euclidean algorithm.

public

Inverse number of this value.

public

Return true if the value is finite number.

public

this === Infinity or -Infinity

public

this === NaN

public

this < 0

public

this === -Infinity

public

this >= 0

public

this === 1

public

this > 0

public

this === Infinity

public

Return true if the value is prime number.

public

isProbablePrime(certainty: any): boolean

Return true if the value is prime number by Miller-Labin prime number determination method.

public

this === 0

public

lcm(number: any): KonpeitoInteger

Least common multiple.

public

mod(number: any): KonpeitoInteger

Modulo, positive rem of division.

public

Modular multiplicative inverse.

public

modPow(exponent: any, m: any): KonpeitoInteger

Modular exponentiation.

public

mul(number: any): KonpeitoInteger

Multiply.

public

multiply(number: any): KonpeitoInteger

Multiply.

public

this * -1

public

nextProbablePrime(certainty: any, search_max: any): KonpeitoInteger

Next prime.

public

Logical Not.

public

or(number: any): KonpeitoInteger

Logical OR.

public

pow(exponent: any): KonpeitoInteger

Power function.

public

rem(number: any): KonpeitoInteger

Remainder of division.

public

remainder(number: any): KonpeitoInteger

Remainder of division.

public

Rounding to the nearest integer.

public

Multiply a multiple of ten.

public

this << n

public

sign(): any

The positive or negative sign of this number.

public

signum(): any

The positive or negative sign of this number.

public

Square.

public

sub(number: any): KonpeitoInteger

Subtract.

public

subtract(number: any): KonpeitoInteger

Subtract.

public

return BigDecimal.

public

return BigInteger.

public

return Complex.

public

return Fraction.

public

Convert to JSON.

public

return Matrix.

public

Convert to string.

public

xor(number: any): KonpeitoInteger

Logical Exclusive-OR.

Static Public Members

public static get MINUS_ONE: BigInteger: * source

-1

Override:

KonpeitoInteger#MINUS_ONE

Return:

BigInteger

1

public static get NEGATIVE_INFINITY: BigInteger: * source

Negative Infinity.

Override:

KonpeitoInteger#NEGATIVE_INFINITY

Return:

BigInteger

Infinity

public static get NaN: BigInteger: * source

Not a Number.

Override:

KonpeitoInteger#NaN

Return:

BigInteger

NaN

public static get ONE: BigInteger: * source

1

Override:

KonpeitoInteger#ONE

Return:

BigInteger

1

public static get POSITIVE_INFINITY: BigInteger: * source

Positive infinity.

Override:

KonpeitoInteger#POSITIVE_INFINITY

Return:

BigInteger

Infinity

public static get TEN: BigInteger: * source

10

Override:

KonpeitoInteger#TEN

Return:

BigInteger

10

public static get TWO: BigInteger: * source

2

Override:

KonpeitoInteger#TWO

Return:

BigInteger

2

public static get ZERO: BigInteger: * source

0

Override:

KonpeitoInteger#ZERO

Return:

BigInteger

0

Static Public Methods

public static create(number: KBigIntegerInputData): BigInteger source

Create an entity object of this class.

Override:

KonpeitoInteger#create

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

public static createRandomBigInteger(bitsize: KBigIntegerInputData, random: Random): BigInteger source

Random number of specified bit length.

Params:

NameTypeAttributeDescription
bitsize KBigIntegerInputData

Bit length.

random Random
  • optional

Class for creating random numbers.

Return:

BigInteger

public static getDefaultRandom(): Random source

Return default Random class. Used when Random not specified explicitly.

Return:

Random

public static probablePrime(bits: KBigIntegerInputData, random: Random, certainty: KBigIntegerInputData, create_count: KBigIntegerInputData): BigInteger source

Prime represented within the specified bit length.

Params:

NameTypeAttributeDescription
bits KBigIntegerInputData

Bit length.

random Random
  • optional

Class for creating random numbers.

certainty KBigIntegerInputData
  • optional
  • default: 100

Repeat count (prime precision).

create_count KBigIntegerInputData
  • optional
  • default: 500

Number of times to retry if prime generation fails.

Return:

BigInteger

public static setDefaultRandom(random: Random) source

Set default class of random. This is used if you do not specify a random number.

Params:

NameTypeAttributeDescription
random Random

public static valueOf(number: KBigIntegerInputData): BigInteger source

Create an arbitrary-precision integer.

  • Does not support strings using exponential notation.
  • If you want to initialize with the specified base number, please set up with an array ["ff", 16].

Override:

KonpeitoInteger#valueOf

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

Public Constructors

public constructor(number: KBigIntegerInputData) source

Create an arbitrary-precision integer.

Initialization can be performed as follows.

  • 1200, "1200", "12e2", "1.2e3", ["1200", 10]
  • "0xff", ["ff", 16]
  • "0o01234567", ["01234567", 8]
  • "0b0110101", ["0110101", 2]

Override:

KonpeitoInteger#constructor

Params:

NameTypeAttributeDescription
number KBigIntegerInputData
  • optional

Numeric data. See how to use the function.

Public Members

public get booleanValue: boolean: * source

boolean value.

Override:

KonpeitoInteger#booleanValue

Return:

boolean

public get doubleValue: number: * source

64-bit floating point.

  • If it is outside the range of JavaScript Number, it will not be an accurate number.

Override:

KonpeitoInteger#doubleValue

Return:

number

public get intValue: number: * source

64-bit integer value.

  • If it is outside the range of JavaScript Number, it will not be an accurate number.

Override:

KonpeitoInteger#intValue

Return:

number

Private Members

private element: Array<number> source

An integer consisting of 16 bits per element of the array.

private state: number source

Numeric state.

Public Methods

public abs(): BigInteger source

Absolute value.

Override:

KonpeitoInteger#abs

Return:

BigInteger

abs(A)

public add(number: KBigIntegerInputData): BigInteger source

Add.

Override:

KonpeitoInteger#add

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

A + B

public and(number: KBigIntegerInputData): BigInteger source

Logical AND.

Override:

KonpeitoInteger#and

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

A & B

public bitCount(): number source

Sum that the bit is 1 when represented in the two's complement.

Return:

number

public bitLength(): number source

Length when the number is binary.

Return:

number

public cbrt(): BigInteger source

Cube root.

Return:

BigInteger

floor(cbrt(A))

public ceil(): BigInteger source

Ceil.

Override:

KonpeitoInteger#ceil

Return:

BigInteger

ceil(A)

public clearBit(bit: KBigIntegerInputData): BigInteger source

Lower a specific bit.

Params:

NameTypeAttributeDescription
bit KBigIntegerInputData

Return:

BigInteger

public clip(min: KBigIntegerInputData, max: KBigIntegerInputData): BigInteger source

Clip number within range.

Params:

NameTypeAttributeDescription
min KBigIntegerInputData
max KBigIntegerInputData

Return:

BigInteger

min(max(x, min), max)

public clone(): BigInteger source

Deep copy.

Override:

KonpeitoInteger#clone

Return:

BigInteger

public compareTo(number: KBigIntegerInputData): number source

Compare values.

Override:

KonpeitoInteger#compareTo

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

number

A > B ? 1 : (A === B ? 0 : -1)

public compareToAbs(number: KBigIntegerInputData): number source

Compare values without sign.

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

number

abs(A) > abs(B) ? 1 : (abs(A) === abs(B) ? 0 : -1)

public div(number: KBigIntegerInputData): BigInteger source

Divide.

Override:

KonpeitoInteger#div

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

fix(A / B)

public divide(number: KBigIntegerInputData): BigInteger source

Divide.

Override:

KonpeitoInteger#divide

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

fix(A / B)

public divideAndRemainder(number: KBigIntegerInputData): Array<BigInteger> source

Divide and rem.

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

Array<BigInteger>

[C = fix(A / B), A - C * B]

public equals(number: KBigIntegerInputData): boolean source

Equals.

Override:

KonpeitoInteger#equals

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

boolean

A === B

public equalsState(number: KBigIntegerInputData): boolean source

Numeric type match.

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

boolean

public extgcd(number: KBigIntegerInputData): BigInteger[] source

Extended Euclidean algorithm.

Override:

KonpeitoInteger#extgcd

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger[]

[a, b, gcd(x, y)], Result of calculating ax + by = gcd(x, y).

public factor(): BigInteger[] source

Factorization.

  • Calculate up to 9007199254740991.

Override:

KonpeitoInteger#factor

Return:

BigInteger[]

factor

public factorial(): BigInteger source

Factorial function, x!.

Override:

KonpeitoInteger#factorial

Return:

BigInteger

n!

public fix(): BigInteger source

To integer rounded down to the nearest.

Override:

KonpeitoInteger#fix

Return:

BigInteger

fix(A), trunc(A)

public flipBit(bit: KBigIntegerInputData): BigInteger source

Invert a specific bit.

Params:

NameTypeAttributeDescription
bit KBigIntegerInputData

Return:

BigInteger

public floor(): BigInteger source

Floor.

Override:

KonpeitoInteger#floor

Return:

BigInteger

floor(A)

public fract(): BigInteger source

Fraction.

Override:

KonpeitoInteger#fract

Return:

BigInteger

fract(A)

public gcd(number: KBigIntegerInputData): BigInteger source

Euclidean algorithm.

Override:

KonpeitoInteger#gcd

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

gcd(x, y)

public getLowestSetBit(): number source

Number of digits in which the number "1" appears first when expressed in binary.

  • Return -1 If 1 is not found it.

Return:

number

public getShort(point: KBigIntegerInputData): number source

Value at the specified position of the internally used array that composed of hexadecimal numbers.

Params:

NameTypeAttributeDescription
point KBigIntegerInputData

Array address.

Return:

number

public inv(): BigInteger source

Inverse number of this value.

Override:

KonpeitoInteger#inv

Return:

BigInteger

1 / A

public isFinite(): boolean source

Return true if the value is finite number.

Override:

KonpeitoInteger#isFinite

Return:

boolean

!isNaN(A) && !isInfinite(A)

public isInfinite(): boolean source

this === Infinity or -Infinity

Override:

KonpeitoInteger#isInfinite

Return:

boolean

isPositiveInfinity(A) || isNegativeInfinity(A)

public isNaN(): boolean source

this === NaN

Override:

KonpeitoInteger#isNaN

Return:

boolean

isNaN(A)

public isNegative(): boolean source

this < 0

Override:

KonpeitoInteger#isNegative

Return:

boolean

public isNegativeInfinity(): boolean source

this === -Infinity

Override:

KonpeitoInteger#isNegativeInfinity

Return:

boolean

isNegativeInfinity(A)

public isNotNegative(): boolean source

this >= 0

Override:

KonpeitoInteger#isNotNegative

Return:

boolean

public isOne(): boolean source

this === 1

Override:

KonpeitoInteger#isOne

Return:

boolean

public isPositive(): boolean source

this > 0

Override:

KonpeitoInteger#isPositive

Return:

boolean

public isPositiveInfinity(): boolean source

this === Infinity

Override:

KonpeitoInteger#isPositiveInfinity

Return:

boolean

isPositiveInfinity(A)

public isPrime(): boolean source

Return true if the value is prime number.

  • Calculate up to 9007199254740991.

Override:

KonpeitoInteger#isPrime

Return:

boolean

If the calculation range is exceeded, null is returned.

public isProbablePrime(certainty: KBigIntegerInputData): boolean source

Return true if the value is prime number by Miller-Labin prime number determination method.

Attention : it takes a very long time to process.

Override:

KonpeitoInteger#isProbablePrime

Params:

NameTypeAttributeDescription
certainty KBigIntegerInputData
  • optional
  • default: 100

Repeat count (prime precision).

Return:

boolean

public isZero(): boolean source

this === 0

Override:

KonpeitoInteger#isZero

Return:

boolean

public lcm(number: KBigIntegerInputData): BigInteger source

Least common multiple.

Override:

KonpeitoInteger#lcm

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

lcm(x, y)

public log10(): BigInteger source

log_10(x)

Return:

BigInteger

log10(A)

public log2(): BigInteger source

log_2(x)

Return:

BigInteger

log2(A)

public max(number: KBigIntegerInputData): BigInteger source

Maximum number.

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

max([A, B])

public min(number: KBigIntegerInputData): BigInteger source

Minimum number.

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

min([A, B])

public mod(number: KBigIntegerInputData): BigInteger source

Modulo, positive rem of division.

  • Result has same sign as the Divisor.

Override:

KonpeitoInteger#mod

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

A mod B

public modInverse(m: KBigIntegerInputData): BigInteger source

Modular multiplicative inverse.

Override:

KonpeitoInteger#modInverse

Params:

NameTypeAttributeDescription
m KBigIntegerInputData

Return:

BigInteger

A^(-1) mod m

public modPow(exponent: KBigIntegerInputData, m: KBigIntegerInputData): BigInteger source

Modular exponentiation.

Override:

KonpeitoInteger#modPow

Params:

NameTypeAttributeDescription
exponent KBigIntegerInputData
m KBigIntegerInputData

Return:

BigInteger

A^B mod m

public mul(number: KBigIntegerInputData): BigInteger source

Multiply.

Override:

KonpeitoInteger#mul

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

A * B

public multiply(number: KBigIntegerInputData): BigInteger source

Multiply.

Override:

KonpeitoInteger#multiply

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

A * B

public negate(): BigInteger source

this * -1

Override:

KonpeitoInteger#negate

Return:

BigInteger

A

public nextProbablePrime(certainty: KBigIntegerInputData, search_max: KBigIntegerInputData): BigInteger source

Next prime.

Override:

KonpeitoInteger#nextProbablePrime

Params:

NameTypeAttributeDescription
certainty KBigIntegerInputData
  • optional
  • default: 100

Repeat count (prime precision).

search_max KBigIntegerInputData
  • optional
  • default: 100000

Search range of next prime.

Return:

BigInteger

public not(): BigInteger source

Logical Not. (mutable)

Override:

KonpeitoInteger#not

Return:

BigInteger

!A

public or(number: KBigIntegerInputData): BigInteger source

Logical OR.

Override:

KonpeitoInteger#or

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

A | B

public pow(exponent: KBigIntegerInputData): BigInteger source

Power function.

Override:

KonpeitoInteger#pow

Params:

NameTypeAttributeDescription
exponent KBigIntegerInputData

Return:

BigInteger

pow(A, B)

public rem(number: KBigIntegerInputData): BigInteger source

Remainder of division.

  • Result has same sign as the Dividend.

Override:

KonpeitoInteger#rem

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

A % B

public remainder(number: KBigIntegerInputData): BigInteger source

Remainder of division.

  • Result has same sign as the Dividend.

Override:

KonpeitoInteger#remainder

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

A % B

public round(): BigInteger source

Rounding to the nearest integer.

Override:

KonpeitoInteger#round

Return:

BigInteger

round(A)

public scaleByPowerOfTen(n: KBigIntegerInputData): BigInteger source

Multiply a multiple of ten.

Override:

KonpeitoInteger#scaleByPowerOfTen

Params:

NameTypeAttributeDescription
n KBigIntegerInputData

Return:

BigInteger

x * 10^n

public setBit(bit: KBigIntegerInputData): BigInteger source

this | (1 << n)

Params:

NameTypeAttributeDescription
bit KBigIntegerInputData

Return:

BigInteger

public shift(n: KBigIntegerInputData): BigInteger source

this << n

Override:

KonpeitoInteger#shift

Params:

NameTypeAttributeDescription
n KBigIntegerInputData

Return:

BigInteger

A << n

public shiftLeft(n: KBigIntegerInputData): BigInteger source

this << n

Params:

NameTypeAttributeDescription
n KBigIntegerInputData

Return:

BigInteger

A << n

public shiftRight(n: KBigIntegerInputData): BigInteger source

this >> n

Params:

NameTypeAttributeDescription
n KBigIntegerInputData

Return:

BigInteger

A >> n

public sign(): number source

The positive or negative sign of this number.

  • +1 if positive, -1 if negative, 0 if 0.

Override:

KonpeitoInteger#sign

Return:

number

public signum(): number source

The positive or negative sign of this number.

  • +1 if positive, -1 if negative, 0 if 0.

Override:

KonpeitoInteger#signum

Return:

number

public sqrt(): BigInteger source

Square root.

Return:

BigInteger

floor(sqrt(A))

public square(): BigInteger source

Square.

Override:

KonpeitoInteger#square

Return:

BigInteger

A^2

public sub(number: KBigIntegerInputData): BigInteger source

Subtract.

Override:

KonpeitoInteger#sub

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

A - B

public subtract(number: KBigIntegerInputData): BigInteger source

Subtract.

Override:

KonpeitoInteger#subtract

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

A - B

public testBit(bit: KBigIntegerInputData): boolean source

Test if a particular bit is on.

Params:

NameTypeAttributeDescription
bit KBigIntegerInputData

Return:

boolean

public toBigDecimal(mc: MathContext): BigDecimal source

return BigDecimal.

Override:

KonpeitoInteger#toBigDecimal

Params:

NameTypeAttributeDescription
mc MathContext
  • optional

MathContext setting after calculation.

Return:

BigDecimal

public toBigInteger(): BigInteger source

return BigInteger.

Override:

KonpeitoInteger#toBigInteger

Return:

BigInteger

public toComplex(): Complex source

return Complex.

Override:

KonpeitoInteger#toComplex

Return:

Complex

public toFraction(): Fraction source

return Fraction.

Override:

KonpeitoInteger#toFraction

Return:

Fraction

public toJSON(): string source

Convert to JSON.

Override:

KonpeitoInteger#toJSON

Return:

string

public toMatrix(): Matrix source

return Matrix.

Override:

KonpeitoInteger#toMatrix

Return:

Matrix

public toString(radix: KBigIntegerInputData): string source

Convert to string.

Override:

KonpeitoInteger#toString

Params:

NameTypeAttributeDescription
radix KBigIntegerInputData
  • optional
  • default: 10

Base number.

Return:

string

public xor(number: KBigIntegerInputData): BigInteger source

Logical Exclusive-OR.

Override:

KonpeitoInteger#xor

Params:

NameTypeAttributeDescription
number KBigIntegerInputData

Return:

BigInteger

A ^ B

Private Methods

private _shift(shift_length: KBigIntegerInputData): BigInteger source

this <<= n

Params:

NameTypeAttributeDescription
shift_length KBigIntegerInputData

Bit shift size.

Return:

BigInteger

A <<= n

private getTwosComplement(bit_length: number): BigInteger source

Create a numerical value for addition. If negative, two's complement.

Params:

NameTypeAttributeDescription
bit_length number
  • optional

Bit length. If not set, it will be calculated automatically.

Return:

BigInteger