Questions tagged [bigint]

Arbitrary-precision arithmetic (also called bignum arithmetic, multiple precision arithmetic, or infinite-precision arithmetic) indicates that calculations are performed on numbers which digits of precision are limited only by the available memory of the host system. This contrasts with the faster fixed-precision arithmetic found in most arithmetic logic unit (ALU) hardware, which typically offers between 8 and 64 bits of precision.

Several modern programming languages have built-in support for bignums, and others have libraries available for arbitrary-precision integer and floating-point math. Rather than store values as a fixed number of binary bits related to the size of the processor register, these implementations typically use variable-length arrays of digits.

, , and , supports arbitrary precision integers (also known as infinite precision integers or bignums). Other languages which do not support this concept as a top-level construct may have libraries available to represent very large numbers using arrays of smaller variables, such as and class or "bigint" package.

These use as much of the computer's memory as is necessary to store the numbers; however, a computer has only a finite amount of storage, so they too can only represent a finite subset of the mathematical integers. These schemes support very large numbers, for example one kilobyte of memory could be used to store numbers up to 2466 decimal digits long.

Application

A common application is public-key cryptography (such as that in every modern Web browser), whose algorithms commonly employ arithmetic with integers having hundreds of digits. Another is in situations where artificial limits and overflows would be inappropriate. It is also useful for checking the results of fixed-precision calculations, and for determining the optimum value for coefficients needed in formulae, for example the √⅓ that appears in Gaussian integration.

Big ints can also be used to compute fundamental mathematical constants such as π to millions or more generally to investigate the precise behaviour of functions such as the Riemann zeta function where certain questions are difficult to explore via analytical methods. Another example is in rendering fractal images with an extremely high magnification.

Arbitrary-precision arithmetic can also be used to avoid overflow, which is an inherent limitation of fixed-precision arithmetic. Some processors can instead deal with overflow by saturation, which means that if a result would be unrepresentable, it is replaced with the nearest representable value.

718 questions
29
votes
4 answers

Producing good add with carry code from clang

I'm trying to produce code (currently using clang++-3.8) that adds two numbers consisting of multiple machine words. To simplify things for the moment I'm only adding 128bit numbers, but I'd like to be able to generalise this. First some…
Clinton
  • 22,361
  • 15
  • 67
  • 163
27
votes
5 answers

What is the simplest way of implementing bigint in C?

I am trying to calculate 100! (that is, the factorial of 100). I am looking for the simplest way to accomplish this using C. I have read around but have not found a concrete answer. If you must know, I program in Xcode in Mac os X.
AlexBrand
  • 11,971
  • 20
  • 87
  • 132
26
votes
1 answer

How to divide two native JavaScript BigInt's and get a decimal result

Here's what I've tried so far. I'm looking to get a 12.34: BigInt('12340000000000000000') / BigInt('1000000000000000000') 12n Number(BigInt('12340000000000000000') / BigInt('1000000000000000000')) 12 FWIW, when I use the JSBI lib, it's working…
robmisio
  • 1,066
  • 2
  • 12
  • 20
25
votes
5 answers

How can I handle long Int with GraphQL?

As you know that GraphQL has no data type like long int. So, whenever the number is something big like 10000000000, it throws an error like this: Int cannot represent non 32-bit signed integer value: 1000000000000 For that I know two solutions: Use…
Harsh Patel
  • 6,334
  • 10
  • 40
  • 73
25
votes
3 answers

What to do if the auto-increment value reaches its limit?

I am doing a little research for a problem that might occur someday. Lets say you have an InnoDB MySQL table with an id and a name field. the id field has BIGINT(20) and is AUTO_INCREMENT plus its the primary key. What do you do in a case that…
user3676604
23
votes
3 answers

Integer division algorithm

I was thinking about an algorithm in division of large numbers: dividing with remainder bigint C by bigint D, where we know the representation of C in base b, and D is of form b^k-1. It's probably the easiest to show it on an example. Let's try…
mornik
  • 231
  • 2
  • 5
22
votes
5 answers

Rails Migration: Bigint on PostgreSQL seems to be failing?

Trying to create a table with a bigint column creates a standard integer column instead. What could be going wrong? I don't know where to start looking. I'm using this in the migration: create_table :table_name do |t| t.integer :really_big_int,…
Lonecat
  • 2,697
  • 2
  • 17
  • 15
22
votes
8 answers

Assembly ADC (Add with carry) to C++

There is an x86 assembly instruction ADC. I've found this means "Add with carry". What does this mean/do? How would one implement the behavior of this instruction in C++? INFO: Compiled on Windows. I'm using a 32-bit Windows Installation. My…
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
22
votes
3 answers

A good and basic implementation of BigInt class in C++

I'm looking for a good and basic BigInt class in C++, I find a lot of implementation but most of the time, it's complex implementation for crypto library... By basic, I mean BigInt can deal with BigInt, long long and strings with operator…
Bebeoix
  • 579
  • 2
  • 5
  • 17
21
votes
2 answers

Base 36 to BigInt?

Suppose I want to convert a base-36 encoded string to a BigInt, I can do this: BigInt(parseInt(x,36)) But what if my string exceeds what can safely fit in a Number? e.g. parseInt('zzzzzzzzzzzzz',36) Then I start losing precision. Are there any…
mpen
  • 272,448
  • 266
  • 850
  • 1,236
21
votes
3 answers

How to write bigint (timestamp in milliseconds) value as timestamp in postgresql

I'm trying to store in timestamp with timezone field my value. It is in milliseconds from 1970. select TO_CHAR(TO_TIMESTAMP(1401432881230), 'DD/MM/YYYY HH24:MI:SS.MS') Expected 30/5/2014 11:29:42 10:54:41.230, but get 22/08/46379 23:27:02.000
Clyde
  • 991
  • 2
  • 9
  • 17
20
votes
3 answers

Java compare integer and bigInteger

How do I compare an int with a BigInteger in Java? I specifically need the know if an int is less than a BigInteger. Here is the code I am using: private static BigInteger two = new BigInteger("2"); private static BigInteger three = new…
Progo
  • 3,452
  • 5
  • 27
  • 44
19
votes
5 answers

C++ 128/256-bit fixed size integer types

I was wondering if any fellow SO's could recommend a good light-weight fixed size integer type (128-bit or even 256-bit, possibly even template parametrized) library. I've had a look at GMP and co, they care great, yet are a bit too large for my…
Matthieu N.
18
votes
4 answers

What to do when you need integers larger than 20 digits on mysql?

Seems like BIGINT is the biggest integer available on MySQL, right? What to do when you need to store a BIGINT(80) for example? Why in some cases, like somewhere in the Twitter API docs, they recommend us to store these large integers as…
Keyne Viana
  • 6,194
  • 2
  • 24
  • 55
18
votes
4 answers

What is the limit of the field type BIGINT in SQL?

What is the limit of the field type BIGINT in SQL? is 100000235882380 or 100000466411115 acceptable? (That is ID from facebook)
ozsenegal
  • 4,055
  • 12
  • 49
  • 64
1
2
3
47 48