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
18
votes
3 answers

Convert a bigint to a string in Go

How do one convert a big int to a string (or integer) in Golang? bigint := big.NewInt(123) //This is what I have bigstr = "123" //This is what I want
Yster
  • 3,147
  • 5
  • 32
  • 48
17
votes
2 answers

Problems with ADC/SBB and INC/DEC in tight loops on some CPUs

I am writing a simple BigInteger type in Delphi. It mainly consists of a dynamic array of TLimb, where a TLimb is a 32 bit unsigned integer, and a 32 bit size field, which also holds the sign bit for the BigInteger. To add two BigIntegers, I create…
Rudy Velthuis
  • 28,387
  • 5
  • 46
  • 94
17
votes
5 answers

what is fastest x86-64 assembly-language divide algorithm for huge numbers?

I am writing a code library in x86-64 assembly-language to provide all conventional bitwise, shift, logical, compare, arithmetic and math functions for s0128, s0256, s0512, s1024 signed-integer types and f0128, f0256, f0512, f1024 floating-point…
honestann
  • 1,374
  • 12
  • 19
16
votes
3 answers

What if I need a very very big autoincrement ID?

According to the MySQL website, the signed bigint can go up to 18446744073709551615. What if I need a number bigger than that for the auto-incrementing primary key?
Artist Kampong
  • 161
  • 1
  • 1
  • 3
16
votes
4 answers

How to specify a BIGINT literal in T-SQL?

Aside from wrapping my literal in a CONVERT function, is there a way to specify that I want e.g. 12345 represented as a BIGINT and not an INT? In C#, I could specify 12345L, but I'm unaware of equivalent functionality in T-SQL.
Jason
  • 562
  • 2
  • 5
  • 13
16
votes
1 answer

Benchmark: bigint vs int on PostgreSQL

I want to increase my database performance. In a project, all tables went from int to bigint, which I think is a bad choice not only regarding storage, since int requires 4 bytes, and bigint requires 8 bytes;but also regarding performance. So I…
Valter Silva
  • 16,446
  • 52
  • 137
  • 218
16
votes
3 answers

Can T-SQL store ulong's?

I want to store a C#.NET ulong into a T-SQL database. I don't see any provisions for doing this, as the SQL bigint has the same Min/Max values as a normal long. Is there any way I can do this? Or is catching an OverflowException my only hope?
Onion-Knight
  • 3,477
  • 7
  • 31
  • 34
16
votes
4 answers

Javascript convert bigInt to string

I am trying to convert the following big int to a string in javascript with no success. My goal would end up with '582235852866076672' var foo = 582235852866076672; console.log(foo); // 582235852866076700 var baz = "'" + 582235852866076672 +…
srm
  • 655
  • 1
  • 8
  • 21
16
votes
1 answer

Using postgresql gin or gist index with bigint column

i am trying to create gin index on bigint column and getting an error (PostgreSQL 9.1.9 / Debian 7). CREATE TABLE test (id bigint CONSTRAINT test_pkey PRIMARY KEY, field bigint); CREATE INDEX idx_test_field ON test using GIN(field); ERROR: data…
therg
  • 465
  • 5
  • 11
15
votes
2 answers

256-bit arithmetic in Clang (extended integers)

I'm in the design phase of a project that needs to do a lot of simple 256-bit integer arithmetic (add, sub, mul, div only) and need something that is reasonably well optimised for these four operations. I'm already familiar with GMP, NTL and most of…
Owen2020
  • 153
  • 6
15
votes
1 answer

What does character 'n' after numeric literal mean in JavaScript?

I've seen const num = 123456789000000000000n; And don't know what the n at the end of numeric literal does? At the time of writing, when searching online for "What does character 'n' after numeric literal mean in JavaScript" nothing comes up.
Nikola Dim
  • 736
  • 7
  • 21
14
votes
4 answers

mysql alter int column to bigint with foreign keys

I want to change the datatype of some primary-key columns in my database from INT to BIGINT. The following definition is a toy-example to illustrate the problem: CREATE TABLE IF NOT EXISTS `owner` ( `id` int(11) NOT NULL AUTO_INCREMENT, …
deif
  • 1,349
  • 1
  • 14
  • 19
14
votes
4 answers

Converting bigint to timestamp in presto

I have a column in my dataset that has a datatype of bigint: Col1 Col2 1 1519778444938790 2 1520563808877450 3 1519880608427160 4 1520319586578960 5 1519999133096120 How do I convert Col2 to the following…
nak5120
  • 4,089
  • 4
  • 35
  • 94
14
votes
3 answers

How can I pick a random value between 0 and a bigint?

I have a combinatorics problem for which I want to be able to pick an integer at random between 0 and a big integer. Inadequacies of my current approach Now for regular integers I would usually write something like int rand 500; and be done with…
Zaid
  • 36,680
  • 16
  • 86
  • 155
13
votes
1 answer

Why Google Plus user id's are such big integers, even it's bigger than bigint on MySQL?

I was wondering today why google decided to do this for the google plus platform. I know I can handle these id's using varchars in mysql, but it's a bit weird to me why google decided to go for such big integers. An example google plus id is like…
Masum
  • 1,678
  • 15
  • 19
1 2
3
47 48