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

updating a large number in MySQL larger than 100 trillion with PHP is unreliable

When I send a value to MySQL in PHP like this: $mysqli->query("update bank set cash = $cash"); It works fine for smaller numbers, but anything 100 trillion or larger yields unexpected results. Sometimes it updates the number in increments of 100,…
Nelson
  • 1,055
  • 1
  • 7
  • 4
-1
votes
1 answer

multiply two 32-bit numbers to get a 64-bit number, on a 8086 (32x32 => 64-bit with 16-bit multiplies)

How can i Multiply two 32bit digits in assembly or one 32bit another 16bit, anyone knows the algorithm ? data1 dw 32bit data2 dw 32bit mov ax,data2 Mul data1
DeadlyDagger
  • 599
  • 4
  • 12
  • 28
-2
votes
1 answer

File.length greater than 8 pebibytes?

How does JavaScript handle it when a Blob or File has a length greater than Number.MAX_SAFE_INTEGER bytes (8 PiB; 9 PB)? let file = await filePrompt("Please upload a ten petabyte file."); let len = file.byteLength; for ( let i = ((len <=…
-2
votes
1 answer

Get the data between previous 11 months till current month using SQL

Help me with the below question. I have ordermonth which is in BigInt format starting from 201801 till 202912. I need to get the records where ordermonth from last 11 months till current month. How to achieve this? Thanks in advance.
HelpSeeker
  • 21
  • 2
-2
votes
1 answer

Factorial Digit Sum Project Euler 20

I would need some help with this code bellow. function main(n) { factCounter = 1; for (let i = n; i > 0; --i) { factCounter *= i; } let numArr = BigInt(factCounter).toString().split(''); let sum = 0; numArr.forEach((el) => (sum +=…
Atzuki
  • 627
  • 1
  • 5
  • 16
-2
votes
1 answer

How to convert a non-decimal string to BigInt

Suppose I have a string of a non-decimal representation of a number beyond Number.MAX_SAFE_INTEGER. How would I get a BigInt of that number? Were the string a representation of a decimal number, I'd just have BigInt(string), but the number is…
-2
votes
1 answer

Issue with as_hex() function in perl

I am trying to write a code to CIDR for IPv6. Basicall, I am getting the CIDR perfix in my code and convert it to the binary. Then using as_hex() function in BigInt library, I convert it into the hexadecimal. That works fine. The problem is when…
-2
votes
3 answers

PHP int value is dependent on system

I use same code in different machine. Ubuntu 64 $test = 51339780210; echo (int) $test; die; //result : 51339780210 Centos 32 $test = 51339780210; echo (int) $test; die; //result : -199827342 Why these result is different?
Dinuka Thilanga
  • 4,220
  • 10
  • 56
  • 93
-2
votes
2 answers

How to convert this kind of date string to the big integer at sql server?

Ok this is how stupidly i am keeping my date as string 23.12.2012 21:24:31 Now at a select query i want to cast them as BigInt and do a search casted version : "20121223212431" like below select * from myTable where cast(datestring as bigint) >…
Furkan Gözükara
  • 22,964
  • 77
  • 205
  • 342
-3
votes
1 answer

Comparing inequalities for Go bigInt?

I am trying to compare two big ints. I'm looking at the docs: https://pkg.go.dev/math/big#Int and I don't see an inequality operator, but I do see an equality one (Cmp). How am I meant to compare a big int a to a big int b? Am I meant to subtract b…
Luke
  • 23
  • 3
-3
votes
1 answer

how to convert javascript BigInt to Uint8Array with negative values considered

I have a java backend that's reading/writing arbitrary precision numbers with javascript front-end using bytes. On Java side I just do: new BigInteger("123").toByteArray() The doc says: Returns a byte array containing the two's-complement…
nemo
  • 12,241
  • 3
  • 21
  • 26
-3
votes
1 answer

Dividing massive numbers in Swift

I have a UInt128 holding a massive number like 2000009100000000000000 and I want to divide it by 1/10^30 How do I do that?
Zack Shapiro
  • 6,648
  • 17
  • 83
  • 151
-4
votes
1 answer

SQL Inserting data from one table to another / Data type Error

I am trying to insert data from one SQL table to another. The problem is that the columns have different data types. And when I use Cast() I still get the following error message: [Msg 8114, Level 16, State 5, Line 3 Error converting data type…
johankent30
  • 65
  • 2
  • 3
  • 11
1 2 3
47
48