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

Calculate 100 factorial with all the digits

I came across a problem of calculating 100 factorial. Here is what I tried first in Perl to calculate 100! : #!/usr/bin/perl use strict; use warnings; use Math::BigInt; my $n=<>; chomp($n); print fac($n); sub fac { my ($m) = @_; return 1…
Krishnachandra Sharma
  • 1,332
  • 2
  • 20
  • 42
7
votes
4 answers

Primary key id reaching limit of bigint data type

I have a table that is exposed to large inserts and deletes on a regular basis (and because of this there are large gaps in the number sequence of the primary id column). It had a primary id column of type 'int' that was changed to 'bigint'. Despite…
DrNoFruit
  • 185
  • 1
  • 3
  • 12
6
votes
1 answer

manipulating 32 bit numbers with 16 bit registers in 8086

Im trying to write a program which get two 6-digit decimal numbers and show the addition of them, but in 16 bit 8086 i defined numbers as double word and put LO in WORD 1 and HO in word 2. similar to below code but i dont have any idea to do…
6
votes
1 answer

Unsigned 64x64->128 bit integer multiply on 32-bit platforms

In the context of exploratory activity I have started to take a look at integer & fixed-point arithmetic building blocks for 32-bit platforms. My primary target would be ARM32 (specifically armv7), with a side glance to RISC-V32 which I expect to…
njuffa
  • 23,970
  • 4
  • 78
  • 130
6
votes
4 answers

how to check if a number is a BigInt in javascript

i want to check if a number is a BigInt in a acceptable size if statement i know there is the solution function isBigInt(x) { try { return BigInt(x) === x; // dont use == because 7 == 7n but 7 !== 7n } catch(error) { return…
user15020827
6
votes
3 answers

Large integer radix/base conversion from 10^x to 2^x

Preface I'm learning about computer math by writing and refining my own BigInt library. So far my first incarnation stores every digit of a base 10 number in successive elements of a vector. It can multiply and add with arbitrary precision. I want…
frontendloader
  • 365
  • 4
  • 12
6
votes
1 answer

How to get digits from a BigInt in javascript?

I am working on problem n°104 of project Euler Problem 104 and would like to do it in javascript. In order to solve this problem I need to compute large values of the Fibonacci sequence, but the numbers produced by this sequence are too large to be…
S. Sylvain
  • 81
  • 6
6
votes
1 answer

How to make Rails generate 'schema.rb' with bigint support for MySQL?

I am using Rails 3.0.5. I am using MySQL as a database storage. I have a model in which one of the columns needs to be BIGINT. I am using the following in my create migration file: t.column :my_column_name, :bigint which works fine. However,…
p.matsinopoulos
  • 7,655
  • 6
  • 44
  • 92
6
votes
3 answers

Convert a 74-bit integer to base 31

To generate a UFI number, I use a bitset of size 74. To perform step 2 of UFI generation, I need to convert this number: 9 444 732 987 799 592 368…
thibsc
  • 3,747
  • 2
  • 18
  • 38
6
votes
5 answers

Getting "value "3000002000" is out of range for type integer"

I’m using Rails 4.2.3 with a PostGre database. I want a column in my database to store a number of milliseconds — note, NOT a timestamp, but rather a duration in milliseconds. So I created my column like so time_in_ms | bigint However, when I go…
Dave
  • 15,639
  • 133
  • 442
  • 830
6
votes
8 answers

Calculate to sum of 2^1000 without using BigInt

As some of you may notice this question is problem 16 from Project Euler. I have solved it using the new "bigInt" feature of C# 4.0 which was fairly straightforward but which is also not really learning everything I should. I am assuming that since…
Chris G
  • 469
  • 8
  • 14
6
votes
3 answers

Approach for altering Primary Key from GUID to BigInt in SQL Server related tables

I have two tables with 10-20 million rows that have GUID primary keys and at leat 12 tables related via foreign key. The base tables have 10-20 indexes each. We are moving from GUID to BigInt primary keys. I'm wondering if anyone has any…
Tom DeMille
  • 3,207
  • 3
  • 23
  • 30
6
votes
1 answer

An efficient algorithm to calculate the integer square root (isqrt) of arbitrarily large integers

Notice For a solution in Erlang or C / C++, go to Trial 4 below. Wikipedia Articles Integer square root The definition of "integer square root" could be found here Methods of computing square roots An algorithm that does "bit magic" could be…
6
votes
1 answer

Bigint in OpenCL and Python

I am trying to implement RSA in Python but I want to run the intensive calculations on the GPU. I have successfully implemented my own modulo expoentiation running in PyOpenCL, but I max out on six digit integers for both the base and exponent.…
Christoffer Reijer
  • 1,925
  • 2
  • 21
  • 40
5
votes
1 answer

Is there a way to do a right bit-shift on a BigInt in Rust?

I get this error when attempting to do >> or >>= on a BigInt: no implementation for `BigInt >> BigInt using the num_bigint::BigInt library Edit: More Context: I am rewriting this program…
Poseidon
  • 165
  • 1
  • 8