The BigInteger class allows you to create and manipulate integer numbers of any size.

The BigInteger class stores a number as an array of unsigned, 32-bit integer "digits" with a radix, or base, of 4294967296. The class stores the digits in little-endian order, with the most-significant digit at the end of the array. The sign (positive or negative) is stored as a separate flag.

For speed, all of the basic math operations are written in C code. However, the BigInteger class and many of its methods are written in the IDL language. You can find the source code in the file lib/datatypes/biginteger__define.pro in your IDL installation.

Examples

Constructors

You can create BigIntegers from regular numbers or from strings. For example, all of the following statements produce the same BigInteger value:

b = BigInteger(-1440154473791)
b = -BigInteger(1440154473791)
b = BigInteger('-1440154473791')
b = BigInteger('1440154473791', SIGN=-1)
b = BigInteger('-14f4fe5553f', RADIX=16)
b = BigInteger('-0x14f4fe5553f')
b = BigInteger('14f4fe5553f', RADIX=16, SIGN=-1)
b = BigInteger('-10100111101001111111001010101010100111111', RADIX=2)
b = BigInteger('-0b10100111101001111111001010101010100111111')

You can also use special constructors to create BigIntegers. For example:

b = BigInteger.Factorial(100000)
c = BigInteger.Random(2048)
HELP, b, c

IDL prints:

B               BIGINTEGER <ID=1 LENGTH=1516705 bits> = 2.8242294079603480...x10^456573
C               BIGINTEGER <ID=2 LENGTH=2048 bits> = 2.4851685629963955...x10^616

Math Expressions

You can use BigIntegers in mathematical expressions in combination with other BigIntegers or regular numbers.

b = BigInteger(89681)
c = b*96079
d = c^1000 + 1
HELP, d

IDL prints:

D               BIGINTEGER <ID=1 LENGTH=33005 bits> = 2.1326348897083203...x10^9935

Useful Methods

The BigInteger class has numerous methods for exploring the properties of your BigInteger numbers. For example:

d = BigInteger.Prime(1024)
PRINT, d
PRINT, d.IsPrime() ? "true" : "false"
PRINT, "The next prime is ", d.NextPrime() - d, " greater."

IDL prints:

1149852122999776946265950910757778460801690763339596229715397877648741495523473947736
9123431875461037047773232597449876136824910342085113678568090440263273346403963966558
7022954039171507173198715249963367029415827692424955706299669891876155639956998605077
128420061437794990570729762185868510044669595754416741
 
true
 
The next prime is 298 greater.

Static Constructors

Methods

Additional Information

Syntax


Result = BigInteger( )

or

Result = BigInteger( Digits, SIGN=integer )

or

Result = BigInteger( Value, SIGN=integer )

or

Result = BigInteger( String, RADIX=integer, SIGN=integer )

Return Value


Returns a reference to the newly-created BigInteger.

Arguments


Digits

Set this argument to an array of unsigned long integers (type ULONG) that contains the BigInteger value as a series of digits in radix 4294967296. You should input the digits in little-endian order, with the most significant digit at the end of the array. For negative BigInteger numbers, set the SIGN keyword to –1.

Value

Set this argument to an integer or float to be transformed into a BigInteger. Float values will be truncated to integers. For negative numbers you can either specify a negative Value or set the SIGN keyword.

String

Set this argument to a string containing the number. You can use the RADIX keyword if your string is in a radix other than the default of base 10. The string is case insensitive. For negative numbers you can either use a "–" sign at the beginning of your string, or set the SIGN keyword.

Tip: If your string begins with 0b, 0o, or 0x then the number is automatically assumed to be binary (base 2), octal (base 8), or hexadecimal (base 16), respectively. In this case the RADIX keyword is ignored.

Keywords


RADIX

Integer, 2–36, default = 10

The radix of the input String. This keyword can only be used with a string argument. For example, if your String is in base 16 (hexadecimal) then you would set RADIX=16. In this case, the String should contain the digits 0–9 and the letters A–F or a–f. If your string happened to be in base 36 then you could use the digits 0–9 and all letters of the alphabet A–Z.

Tip: If your string begins with 0b, 0o, or 0x then the number is automatically assumed to be binary (base 2), octal (base 8), or hexadecimal (base 16), respectively. In this case the RADIX keyword is ignored.

SIGN

Integer, -1, 0, or 1, default = 1

The sign of the BigInteger: –1 for negative, 0 for zero value, 1 for positive.

Tip: If you use a string or integer value and it already has a minus sign, then you do not need to set the SIGN keyword.

Properties


You can retrieve the following properties using either "dot" notation or the ::GetProperty method. For example:

b = -BigInteger(2)^100
d = b.DIGITS
s = b.SIGN
; Or, using GetProperty...
; b.GetProperty, DIGITS=d, SIGN=s
PRINT, d, s

IDL prints:

0           0           0          16
-1

Note: BigInteger objects are immutable: You cannot set the DIGITS or SIGN properties.

DIGITS

This property contains the BigInteger number as a series of unsigned 32-bit integers in base 4294967296, stored in little-endian order (largest digit at the end).

SIGN

This property is an integer (–1, 0, or 1) that indicates whether the BigInteger number is negative, zero, or positive.

BigInteger::BitLength


The BigInteger::BitLength method returns the number of bits in the number.

Example


bigint = BigInteger(2)^1279 - 1
PRINT, bigint.BitLength()

IDL prints:

1279

Syntax


Result = bigint.BitLength( )

Return Value


An integer giving the number of bits in the BigInteger value.

Note: Since there is no "sign" bit in a BigInteger value, a negative BigInteger value will have the same bit length as the corresponding positive value.

Arguments


None

Keywords


None

BigInteger::Factorial


The BigInteger::Factorial static constructor method returns a new BigInteger containing the value of N!.

Example


bigint = BigInteger.Factorial(100)
PRINT, bigint

IDL prints:

9332621544394415268169923885626670049071596826438162146859296389521759999322991
5608941463976156518286253697920827223758251185210916864000000000000000000000000

Syntax


Result = BigInteger.Factorial( N )

Return Value


A BigInteger equal to N!.

Arguments


N

An integer giving the factorial value.

Keywords


None

BigInteger::GCD


The BigInteger::GCD method computes the greatest common divisor (the greatest common factor) between this BigInteger and another integer. The greatest common divisor is the largest integer that evenly divides each number (i.e., the remainder is 0). By definition the GCD will always be greater than or equal to 1 and less than or equal to the smaller of the two numbers.

Examples


u = BigInteger.Factorial(49000)
   v = BigInteger.Factorial(6000) + 34
  result = u.GCD(v)
HELP, u, v
PRINT, "GCD = ", result

IDL prints:

U               BIGINTEGER <ID=1 LENGTH=692762 bits> = 8.3655952924066987...x10^208541
V               BIGINTEGER <ID=2 LENGTH=66656 bits> = 2.6839997657267398...x10^20065
GCD = 275978

Syntax


Result = bigint.GCD( Value )

Return Value


Returns a BigInteger containing the greatest common divisor of bigint and Value.

Arguments


Value

Set this argument to either a normal IDL integer or a BigInteger.

Keywords


None

BigInteger::GetPrimes


The BigInteger::GetPrimes static method returns an unsigned integer array containing the prime numbers up to a certain maximum.

Note: The GetPrimes method will only return prime numbers up to the maximum that will fit in an unsigned 32-bit integer. For larger primes, use the NextPrime method.

Example


; All prime numbers up to 100.
result = BigInteger.GetPrimes(100, COUNT=c)
PRINT, "The first ", c, " primes are:"
PRINT, result, FORMAT='(13I4)'

IDL prints:

The first           25 primes are:
2   3   5   7  11  13  17  19  23  29  31  37  41
43  47  53  59  61  67  71  73  79  83  89  97

Syntax


Result = bigint.GetPrimes( N, COUNT=variable, /IS_INDEX )

Return Value


An array of unsigned 32-bit integers.

Arguments


N

An integer giving the maximum value to return. All prime numbers less than or equal to N will be included (N itself does not need to be prime).

Keywords


COUNT

Output variable

Returns the number of prime numbers in Result. If IS_INDEX is set then COUNT will be equal to N.

IS_INDEX

Flag, default=0

Treat the input N as the number of prime numbers to return instead of the maximum value. In the above example, if we wanted the same result we would set N=25 and /IS_INDEX.

BigInteger::GetProperty


You can retrieve the properties of a BigInteger using either "dot" notation or the ::GetProperty method.

Example


bigint = -BigInteger(2)^79 + 1
digits = bigint.DIGITS
sign = bigint.SIGN
; Or, using GetProperty...
bigint.GetProperty, DIGITS=digits, SIGN=sign
PRINT, digits
PRINT, sign

IDL prints:

4294967295   4294967295   32767
-1

Note: BigInteger objects are immutable: You cannot set the DIGITS or SIGN properties.

Syntax


Result = bigint.GetProperty( PROPERTY=variable )

Arguments


None

Keywords


DIGITS

This property contains the BigInteger number as a series of unsigned 32-bit integers in base 4294967296, stored in little-endian order (largest digit at the end).

SIGN

This property is an integer (–1, 0, or 1) that indicates whether the BigInteger number is negative, zero, or positive.

BigInteger::Hashcode


The BigInteger::Hashcode method returns a hash code based upon the BigInteger value. The hash code is constructed by calling the Hashcode method on the DIGITS property, then taking the bitwise not operator if the BigInteger is negative.

Example


bigint = BigInteger(2)^1279 - 1
HELP, bigint.Hashcode()

IDL prints:

<Expression>    ULONG     =   1097148854

Syntax


Result = bigint.Hashcode( )

Return Value


An integer giving the hash code based upon the BigInteger value.

Arguments


None

Keywords


None

BigInteger::IsPowerOfTwo


The BigInteger::IsPowerOfTwo method tests whether the value is a power of two and returns 1 (true) or 0 (false).

Example


bigint = BigInteger(2)^1279
PRINT, bigint.IsPowerOfTwo()

IDL prints:

1

Syntax


Result = bigint.IsPowerOfTwo( )

Return Value


Returns 1 (true) or 0 (false).

Arguments


None

Keywords


None

BigInteger::IsPrime


The BigInteger::IsPrime method returns 1 (true) if the number is probably prime, or 0 (false) if the number is definitely composite. The method uses three tests in succession:

  1. Division by all prime factors up to 1999.
  2. The Miller-Rabin probabilistic primality test. This is an iterative test, where random numbers are used to test the primality based upon a set of equalities. The algorithm follows the pseudocode in Donald E. Knuth, The Art of Computer Programming, Vol 2: Seminumerical Algorithms, 3rd ed., Addison Wesley, 1998, section 4.5.4, algorithm P.
  3. The Lucas probable prime test. This algorithm follows the pseudocode in NIST Federal Information Processing Standards 186-4: Digital Signature Standard (DSS), July 2013, downloaded from http://csrc.nist.gov/publications/PubsFIPS.html, Dec 2013, section C3.3.

If the number is less than 3996001, the first test is sufficient to guarantee that the number is prime or composite with no chance of failure. For larger numbers, if the number passes all three tests then the probability of failure is less than 2-100.

Example


bigint = BigInteger(2)^1279 - 1
PRINT, bigint.IsPrime() ? 'prime' : 'composite'

IDL prints:

prime

Syntax


Result = bigint.IsPrime( ITERATIONS=value )

Return Value


Returns 1 if the number is probably prime, 0 if the number is composite.

Arguments


None

Keywords


ITERATIONS

Integer >= 1

The number of iterations to perform for the Miller-Rabin primality test. Each iteration has a 1/4 chance (in the worst case) of incorrectly identifying a composite number as being prime. The default value is based upon the bit length, and is designed to give a probability of 2-100 of incorrectly identifying a composite number as prime:

Bit length Iterations
2048+ 2
1024–2047 4
512–1023 7
256–511 16
128–255 34
64–127 44
32–63 49
<32 64

The number of iterations was computed from the formula in section F1.1 of NIST Federal Information Processing Standards 186-4: Digital Signature Standard (DSS), July 2013, downloaded from http://csrc.nist.gov/publications/PubsFIPS.html, Dec 2013.

BigInteger::LCM


The BigInteger::LCM method computes the least common multiple (LCM) between this BigInteger and another integer. The least common multiple is the smallest integer that can be evenly divided (no remainder) by each number. By definition the LCM will always be greater than or equal to the larger of the two numbers.

Examples


u = BigInteger.Factorial(90)
   v = BigInteger.Factorial(60) + 34
  lcm = u.LCM(v)
HELP, u, v, lcm

IDL prints:

U               BIGINTEGER <ID=1 LENGTH=459 bits> = 1.4857159644817615...x10^138
V               BIGINTEGER <ID=2 LENGTH=273 bits> = 8.3209871127413901...x10^81
LCM         BIGINTEGER <ID=3 LENGTH=727 bits> = 3.6360657040137889...x10^218

Syntax


Result = bigint.LCM( Value )

Return Value


Returns a BigInteger containing the least common multiple of bigint and Value.

Arguments


Value

Set this argument to either a normal IDL integer or a BigInteger.

Keywords


None

BigInteger::Log2


The BigInteger::Log2 method returns the base-2 logarithm of the number, along with an optional remainder.

Note: If the number is 0 or negative then the method throws an error.

Example


bigint = BigInteger.Factorial(10000)
PRINT, bigint.Log2(REMAINDER=rem)
HELP, rem

IDL prints:

118458
REM             BIGINTEGER <ID=2 LENGTH=118455 bits> = 2.6859533835705141...x10^35658

Syntax


Result = bigint.Log2( )

Return Value


An integer giving the base-2 logarithm.

Arguments


None

Keywords


REMAINDER

Output variable

Returns a BigInteger containing the remainder, equal to bigint – 2Result.

BigInteger::Log10


The BigInteger::Log10 method returns the base-10 logarithm of the number, along with an optional remainder.

Note: If the number is 0 or negative then the method throws an error.

Example


bigint = BigInteger.Factorial(10000)
PRINT, bigint.Log10(REMAINDER=rem)
HELP, rem

IDL prints:

35659
REM             BIGINTEGER <ID=2 LENGTH=118458 bits> = 1.8462596809170546...x10^35659

Syntax


Result = bigint.Log10( )

Return Value


An integer giving the base-10 logarithm.

Arguments


None

Keywords


REMAINDER

Output variable

Returns a BigInteger containing the remainder, equal to bigint – 10Result.

BigInteger::ModInverse


The BigInteger::ModInverse method computes the multiplicative inverse of the BigInteger modulo the input Modulus. In order for the inverse to exist, the BigInteger and the Modulus must be co-prime (i.e. their GCD must be 1). If the ModInverse exists then bigint*result mod Modulus = 1. The ModInverse method uses the extended Euclidean algorithm.

If the BigInteger and Modulus are not co-prime then IDL throws an error.

Examples


u = BigInteger.Factorial(90)
v = BigInteger.Factorial(60) - 1
r = u.ModInverse(v)
PRINT, r
PRINT, "u*r mod v = ", u*r mod v

IDL prints:

5398464503473793715027616372607916377802131923010621870166614886971773279155082918
u*r mod v = 1

Syntax


Result = bigint.ModInverse( Modulus )

Return Value


Returns a BigInteger containing the multiplicative inverse of bigint and Modulus.

Arguments


Modulus

Set this argument to either a normal IDL integer or a BigInteger.

Keywords


None

BigInteger::ModPower


The BigInteger::ModPower method computes the modular exponentiation,

Result = bigintExponent mod Modulus

The method uses the right-to-left binary algorithm: the exponent is broken down into binary bits and the result is then the product of each power of two (if the bit is set) modulo the Modulus.

Examples


u = BigInteger.Random(1024)
v = BigInteger.Random(1024)
e = BigInteger(2)^1024 - 1
TIC & r = u.ModPower(e, v) & TOC
HELP, r

IDL prints:

% Time elapsed: 0.074999809 seconds.
R               BIGINTEGER <ID=1 LENGTH=1018 bits> = 2.2843081667189526...x10^306

Note that computing this result using ue mod v would be impossible because the ue would require approximately 10308 digits of storage and take longer than the age of the universe.

Syntax


Result = bigint.ModPower( Exponent, Modulus )

Return Value


Returns a BigInteger containing the modular exponentiation.

Arguments


Exponent

Set this argument to either a normal IDL integer or a BigInteger.

Modulus

Set this argument to either a normal IDL integer or a BigInteger.

Keywords


None

BigInteger::NextPrime


The BigInteger::NextPrime method computes the next prime number that follows this BigInteger.

The method uses an algorithm based upon the Sieve of Erastosthenes. Several thousand numbers are generated in sequence following the BigInteger value. The algorithm removes any numbers that are divisible by primes up to 997. The algorithm then tests the surviving numbers for primality and returns the first match.

The algorithm's speed is highly variable because it depends upon the gap between successive primes. See below for an example.

Example


From Thomas R. Nicely's website (http://www.trnicely.net), the first known gap of 10000 is found after the prime number 43775*547#/1866 - 1402. Here, the "#" symbol indicates the Primorial function. We can compute this gap as well as the next gap, and the time needed for the computation:

b = 43775*BigInteger.Primorial(547)/1866 - 1402
TIC & c = b.NextPrime() & TOC
TIC & d = c.NextPrime() & TOC
PRINT, 'Gap between b and c is ', c - b
PRINT, 'Gap between c and d is ', d - c

IDL prints:

% Time elapsed: 13.886000 seconds.
% Time elapsed: 0.32699990 seconds.
Gap between b and c is 10000
Gap between c and d is 84

Syntax


Result = bigint.NextPrime( )

Return Value


Returns a BigInteger containing the next prime number.

Arguments


None

Keywords


None

BigInteger::Prime


The BigInteger::Prime static constructor method returns a new BigInteger containing a random prime number with a given bit length.

Example


bigint = BigInteger.Prime(256)
PRINT, bigint

IDL prints:

103231891082001480830106615945373073145045889883067503900939711192099772102403

Syntax


Result = BigInteger.Prime( BitLength, SEED=value )

Return Value


A new BigInteger.

Arguments


BitLength

An integer giving the number of bits in the prime number.

Keywords


SEED

Integer or array

This seed will be used as the starting value for the RANDOMU function.

Note: Normally, you should never need to use the SEED keyword as BigInteger will automatically pick a new seed value each time it is called. You should only use the SEED keyword if you need to re-generate the same prime number for a given bit length.

BigInteger::Primorial


The BigInteger::Primorial static constructor method returns a new BigInteger containing the primorial of N.

The primorial (or "prime factorial") is defined as the product of all prime numbers less than or equal to N (N may be a prime number or a composite number).

Example


bigint = BigInteger.Primorial(100, COUNT=c)
PRINT, 'product of first ', c, ' primes is ', bigint

IDL prints:

product of first           25 primes is 2305567963945518424753102147331756070

Syntax


Result = BigInteger.Primorial( N, COUNT=variable, /IS_INDEX )

Return Value


A new BigInteger.

Arguments


N

An integer giving the maximum value to use when computing the primorial. All prime numbers less than or equal to N will be included in the product (N itself does not need to be prime).

Keywords


COUNT

Output variable

Returns the number of prime numbers that were multiplied together to produce the result. If IS_INDEX is set then COUNT will just be equal to N.

IS_INDEX

Flag, default=0

Treat the input N as the number of prime numbers to include in the primorial, instead of the maximum value. In the above example, if we wanted the same result, we would set N=25 and /IS_INDEX.

BigInteger::Random


The BigInteger::Random static constructor method returns a new BigInteger containing a random number between 0 and the given bit length. The RANDOMU function is used to construct the random digits.

Example


bigint = BigInteger.Random(2048)
HELP, bigint

IDL prints:

BIGINT          BIGINTEGER <ID=1 LENGTH=2047 bits> = 1.0066318959964815...x10^616

Syntax


Result = BigInteger.Random( BitLength, /EXACT, SEED=value )

Return Value


A new BigInteger.

Arguments


BitLength

An integer giving the maximum number of bits. The result could have less bits, unless the EXACT keyword is set.

Keywords


EXACT

Flag, default=0

Return a BigInteger with exactly BitLength bits. In other words, the number will be between 2BitLength and 2BitLength+1 – 1. The default is to return a random number between 0 and 2BitLength+1 – 1.

SEED

Integer or array

This seed will be used as the starting value for the RANDOMU function.

Note: Normally, you should never need to use the SEED keyword as BigInteger will automatically pick a new seed value each time it is called. You should only use the SEED keyword if you need to re-generate the same random number for a given bit length.

BigInteger::Signum


The BigInteger::Signum method returns –1 if the number is negative, 0 if the number is zero, and 1 if the number is positive.

Syntax


Result = bigint.Signum( )

Return Value


Returns –1, 0, or +1.

Arguments


None

Keywords


None

BigInteger::Sqrt


The BigInteger::Sqrt method uses Newton's iterative method to compute the square root of the number along with an optional remainder. If the number is negative, IDL throws an error.

Example


b = BigInteger.Random(2048)
c = b^2 + 1
b1 = c.Sqrt(REMAINDER=r)
PRINT, "sqrt(c) equals b:", b eq b1 ? "true" : "false"
PRINT, "remainder is ", r

IDL prints:

sqrt(c) equals b:   true
remainder is 1

Syntax


Result = bigint.Sqrt( REMAINDER=variable )

Return Value


Returns a BigInteger containing the "integer" part of the square root.

Arguments


None

Keywords


REMAINDER

Output variable

Returns a BigInteger containing the remainder, equal to bigintresult2.

BigInteger::ToDouble


The BigInteger::ToDouble method converts the number to a double-precision value.

Examples


Find the largest factorial that will still fit in a double:

bigint = BigInteger.Factorial(170)
HELP, bigint.ToDouble()

IDL prints:

<Expression>    DOUBLE    =   7.2574156e+306

Now find a huge factorial and use the optional EXPONENT keyword:

bigint = BigInteger.Factorial(100000)
HELP, bigint.ToDouble(EXPONENT=exponent), exponent

IDL prints:

<Expression>    DOUBLE    =        2.8242294
EXPONENT        LONG      =       456573

The value of 100000! is approximately 2.82x10456573.

Syntax


Result = bigint.ToDouble( EXPONENT=variable )

Return Value


Returns a double-precision value.

Arguments


None

Keywords


EXPONENT

Output variable

If set, then the ToDouble method will not include the exponent in the Result, but will instead return the exponent in this variable. This allows you to convert BigIntegers that are larger than 10308 into useable pieces.

If you do not specify EXPONENT and the BigInteger is too large, then ToDouble returns Infinity.

BigInteger::ToInteger


The BigInteger::ToInteger method converts the BigInteger to a signed 64-bit integer value. If the value is too large then IDL issues a warning and returns 0.

Examples


The largest prime that will still fit in a 64-bit integer:

bigint = BigInteger(2)^63
while (~bigint.IsPrime()) do bigint = bigint - 1
PRINT, bigint.ToInteger()

IDL prints:

9223372036854775783

Syntax


Result = bigint.ToInteger( )

Return Value


Returns a 64-bit signed integer value.

Arguments


None

Keywords


None

BigInteger::ToString


The BigInteger::ToString method converts the BigInteger to its string representation. By default the string is in base 10 but you can use the RADIX keyword to convert to a different base.

Examples


bigint = BigInteger('303117847695258070278031236')
PRINT, bigint.ToString()
PRINT, bigint.ToString(RADIX=2)
PRINT, bigint.ToString(RADIX=16, /UPPERCASE)
PRINT, bigint.ToString(RADIX=36, /UPPERCASE)

IDL prints:

303117847695258070278031236
1111101010111011101100110111001100010011100...
FABBB37313829F24214784
12345IDLISFUN67890

Syntax


Result = bigint.ToString( RADIX=value, /UPPERCASE )

Return Value


Returns the string representation of the number.

Arguments


None

Keywords


RADIX

Integer, 2–36, default = 10

Return the result in a different base.

UPPERCASE

Flag, default=0

Set this keyword to return the string using uppercase letters instead of lowercase. This keyword only has an effect if RADIX is greater than 10.

Additional Information


Operators

Name Operators Operands Result
Math + – * / ^ mod BigIntegers or numbers A new BigInteger

Increment,
Decrement

++ ––

BigInteger

The BigInteger is incremented or decremented

Comparisons EQ, NE, GT, GE, LT, LE BigIntegers or numbers Boolean 0 or 1
Bitwise AND, NOT, OR, XOR BigIntegers or numbers A new BigInteger
Min/max > < BigIntegers or numbers A new BigInteger

Logical Truth and Negation

A BigInteger is considered "true" if the value is not zero, otherwise it is false. The "~" negation operator will return a boolean 0 if the BigInteger was nonzero, or 1 if the BigInteger was zero.

Help and Print

The PRINT procedure will output the BigInteger value in base 10. To output to a different base you can use the ToString method.

The HELP procedure will output the BigInteger's heap ID and a shortened version of the BigInteger value.

ISA and TYPENAME

You can use the ISA function to determine if a variable is a BigInteger:

if ISA(bigint, "BigInteger") then ...

You can use the TYPENAME function or the TYPENAME attribute to retrieve the class name:

if (TYPENAME(bigint) eq "BIGINTEGER") then ...
if (bigint.TYPENAME eq "BIGINTEGER") then ...

Copying BigIntegers

If you assign a BigInteger variable to a new variable, you are creating a new reference to the same object. Since BigIntegers are immutable (the value cannot be changed) this is usually not a problem. If for some reason you must have a new object, you can use the DIGITS and SIGN properties to create a new BigInteger. For example:

b = BigInteger(2)^1279 - 1
c = b
d = BigInteger(b.digits, SIGN=b.sign)
HELP, b, c, d

IDL prints:

B               BIGINTEGER <ID=7 LENGTH=1279 bits> = 1.0407932194664400...x10^385
C               BIGINTEGER <ID=7 LENGTH=1279 bits> = 1.0407932194664400...x10^385
D               BIGINTEGER <ID=9 LENGTH=1279 bits> = 1.0407932194664400...x10^385

Notice that both b and c have the same heap variable ID, while d has a new heap ID.

Version History


8.4

Introduced

See Also


IDL Data Types, Mathematical Operators, Operator Precedence