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
276
votes
12 answers

What is the equivalent of bigint in C#?

What am I supposed to use when handling a value in C#, which is bigint for an SQL Server database?
Asad
  • 21,468
  • 17
  • 69
  • 94
184
votes
4 answers

How does Rust's 128-bit integer `i128` work on a 64-bit system?

Rust has 128-bit integers, these are denoted with the data type i128 (and u128 for unsigned ints): let a: i128 = 170141183460469231731687303715884105727; How does Rust make these i128 values work on a 64-bit system; e.g. how does it do arithmetic…
ruohola
  • 21,987
  • 6
  • 62
  • 97
113
votes
3 answers

How to convert BigInt to Number in JavaScript?

I found myself in the situation where I wanted to convert a BigInt value to a Number value. Knowing that my value is a safe integer, how can I convert it?
Lucio Paiva
  • 19,015
  • 11
  • 82
  • 104
76
votes
3 answers

Is there a 128 bit integer in gcc?

I want a 128 bit integer because I want to store results of multiplication of two 64 bit numbers. Is there any such thing in gcc 4.4 and above?
MetallicPriest
  • 29,191
  • 52
  • 200
  • 356
75
votes
4 answers

How to format bigint field into a date in Postgresql?

I have a table with a field of type bigint. This field store a timestamp. I want to date format the field like this : to_char( bigint_field,'DD/MM/YYYY HH24:MI:SS') I get the following error : ERROR: multiple decimal points État SQL :42601
Stephan
  • 41,764
  • 65
  • 238
  • 329
50
votes
4 answers

node.js - Is there any proper way to parse JSON with large numbers? (long, bigint, int64)

When I parse this little piece of JSON: { "value" : 9223372036854775807 } This is what I get: { hello: 9223372036854776000 } Is there any way to parse it properly?
tartakynov
  • 2,768
  • 3
  • 26
  • 23
49
votes
1 answer

Arithmetic overflow error when summing an INT, how do I cast it as a BIGINT?

When I try to get the sum of a column from a table I get the error Arithmetic overflow error converting expression to data type int because the resulting number is to big for an INT. So I tried to CAST to a BIGINT using the following SELECT…
Brian
43
votes
2 answers

Efficient 128-bit addition using carry flag

I'm using a 128 bit integer counter in the very inner loops of my C++ code. (Irrelevant background: The actual application is evaluating finite difference equations on a regular grid, which involves repetitively incrementing large integers, and even…
Randall Meyers
  • 433
  • 1
  • 4
  • 5
40
votes
11 answers

How to use long id in Rails applications?

How can I change the (default) type for ActiveRecord's IDs? int is not long enough, I would prefer long. I was surprised that there is no :long for the migrations - does one just use some decimal?
Björn
  • 1,183
  • 2
  • 13
  • 18
39
votes
6 answers

Logarithm of a BigInt

Is there a way to get the logarithm of a BigInt in JavaScript? With normal numbers, you would use this code: const largeNumber = 1000; const result = Math.log(largeNumber); However, I need to work with factorial numbers, potentially higher than…
Mielipuoli
  • 1,306
  • 2
  • 12
  • 23
37
votes
1 answer

Is there anything special about -1 (0xFFFFFFFF) regarding ADC?

In a research project of mine I'm writing C++ code. However, the generated assembly is one of the crucial points of the project. C++ doesn't provide direct access to flag manipulating instructions, in particular, to ADC but this shouldn't be a…
Cassio Neri
  • 19,583
  • 7
  • 46
  • 68
36
votes
4 answers

BigInt inconsistencies in PowerShell and C#

According to microsoft documentation the [BigInt] datatype seems to have no defined maximum value and theoretically can hold an infinitely large number, but I found that after the 28th digit, some weird things start to occur: PS C:\Users\Neko>…
Nico Nekoru
  • 2,840
  • 2
  • 17
  • 38
32
votes
4 answers

BigInteger in C?

What is the easiest way to handle huge numbers in C? I need to store values in the Area 1000^900, or in more human readable form 10^2700. Does anybody know of an easy way to do that? Any help would really be appreciated!
Chris
  • 9,209
  • 16
  • 58
  • 74
32
votes
4 answers

How to convert strings to bigInt in JavaScript

I need to convert a string to BigInt like BigInteger in Javascript Example var reqId = "78099864177253771992779766288266836166272662"; var result = parseInt(reqId); document.write(result); Resultant value not matching since JavaScript only allows…
rselvaganesh
  • 1,032
  • 2
  • 18
  • 30
30
votes
5 answers

What's the biggest BigInt value in js as per spec

It turns out (outer a bit of thought it's more obvious but whatever) that BigInt recently introduced to javascript has a limit: My question would be - is there a constant similar to Number.MAX_SAFE_INTEGER but for BigInt? This snippet of code: …
shabunc
  • 23,119
  • 19
  • 77
  • 102
1
2 3
47 48