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
13
votes
4 answers

Convert nvarchar to bigint in Sql server 2008

I want insert all rows of a table into another table, and I also want convert a nvarchar field into bigint, but when I use convert(bigint, col1) SQL Server shows an error: Error converting data type nvarchar to bigint How can I fix this problem?
Hossein Moradinia
  • 6,116
  • 14
  • 59
  • 85
13
votes
3 answers

JSON stringify and PostgreSQL bigint compliance

I am trying to add BigInt support within my library, and ran into an issue with JSON.stringify. The nature of the library permits not to worry about type ambiguity and de-serialization, as everything that's serialized goes into the server, and never…
vitaly-t
  • 24,279
  • 15
  • 116
  • 138
13
votes
3 answers

Is there a 256-bit integer type?

OS: Linux (Debian 10) CC: GCC 8.3 CPU: i7-5775C There is a unsigned __int128/__int128 in GCC, but is there any way to have a uint256_t/int256_t in GCC? I have read of a __m256i which seems to be from Intel. Is there any header that I can include to…
13
votes
3 answers

JavaScript big integer square root

This concerns the new JavaScript BigInt type, as supported in Chrome and Node v10.4 Both the following lines throw an error: Math.sqrt(9n) Math.sqrt(BigInt(9)) Error is: Cannot convert a BigInt value to a number How do I get the square root of a…
danday74
  • 52,471
  • 49
  • 232
  • 283
13
votes
2 answers

PostgreSql storing a value as integer vs varchar

I want to store a 15 digit number in a table. In terms of lookup speed should I use bigint or varchar? Additionally, if it's populated with millions of records will the different data types have any impact on storage?
Dhanushka Amarakoon
  • 3,502
  • 5
  • 31
  • 43
13
votes
4 answers

Can Java's Long hold an SQL BIGINT(20) value?

I have a table in an SQL database where the values' data type is BIGINT(20), and I need to get those data to my logic in Java for processing. What should be the appropriate data type in Java to store the BIGINT(20) value returned ? I thought of…
prime
  • 14,464
  • 14
  • 99
  • 131
13
votes
2 answers

sequelize js with big integers

I have an application written in Node JS and uses the Sequelize js ORM library to access my database which is MySql. My problem is that I have a column in my db which is BIGINT and when the value of it is large I get wrong values when I retrieve…
Sami
  • 5,819
  • 1
  • 23
  • 30
12
votes
3 answers

TypeScript: serialize BigInt in JSON

I'm looking for a way to force JSON.stringify to always print BigInts without complaining. I know it's non-standard, I know there's a package for that in pure JavaScript; but it doesn't fit my needs. I even know a fix in raw JavaScript by setting…
Tristan Duquesne
  • 512
  • 1
  • 6
  • 16
11
votes
2 answers

Alternative to Math.max and Math.min for BigInt type in Javascript

In Javascript: Math.max and Math.min do not work for BigInt types. For example: > Math.max(1n, 2n) Thrown: TypeError: Cannot convert a BigInt value to a number at Math.max () > Is there a built in function that performs these…
11
votes
3 answers

If you try 9n**9n**9n in Chrome's console, Chrome breaks (it resembles an infinite loop). Why does this happen?

If you try 9n**9n**9n in Chrome's console, Chrome breaks (it resembles an infinite loop). Does the V8 engine lack the implementation for this case? I mean, if you try 9**9**9 it will return Infinity, which is kind of nice. Why doesn't V8…
Tiberiu
  • 418
  • 1
  • 3
  • 12
11
votes
1 answer

Mysql returning incorrect bigint result by one, very strange error

I really don't know what is going on here. I have a database table that looks like this: With this data: When I run this query SELECT * FROM game WHERE id = 4 in phpmyadmin I get back this result as expected: But when I make this query on it…
user1180888
  • 497
  • 1
  • 10
  • 29
11
votes
3 answers

Java/Scala BigInteger Pasting

I have a problem with the Java BigInteger class: I can't paste a large value into BigInteger. For example, let's say I want to assign a BigInteger to this number: 26525285981219105863630848482795 I cannot assign it directly, because the compiler…
Michael Dickens
  • 1,454
  • 4
  • 18
  • 26
10
votes
11 answers

How can I multiply two 64-bit numbers using x86 assembly language?

How would I go about... multiplying two 64-bit numbers multiplying two 16-digit hexadecimal numbers ...using Assembly Language. I'm only allowed to use registers %eax, %ebx, %ecx, %edx, and the stack. EDIT: Oh, I'm using ATT Syntax on the…
Kawarazu
  • 121
  • 1
  • 1
  • 8
10
votes
3 answers

STL BigInt class implementation

Does STL have a BigInt class implementation? (numbers with many digits held into a container)
XCS
  • 27,244
  • 26
  • 101
  • 151
10
votes
3 answers

Convert binary string to bigint in MySQL?

I am attempting to hash a string to a 64-bit value (bigint) in MySQL. I am aware of the MD5() function, which returns a 128-bit hash as a binary string. I'd be happy to just take the bottom or top 64 bits of this result. However, I cannot figure out…
Sean Owen
  • 66,182
  • 23
  • 141
  • 173