Questions tagged [largenumber]

Very large numbers often occur in fields such as mathematics, cosmology, cryptography and statistical mechanics. That numbers are significantly larger than those ordinarily used in everyday life, for instance in simple counting or in monetary transactions. The term typically refers to large positive integers, or more generally, large positive real numbers, but it may also be used in other contexts.

In computer science, arbitrary-precision arithmetic, also called bignum arithmetic, multiple precision arithmetic, or sometimes 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 large numbers (also known as infinite precision integers or bignums), such as , , and . 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 package.

Other languages 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.

453 questions
5
votes
4 answers

Algorithm to convert infinitely long base 2^32 number to printable base 10

I'm representing an infinitely precise integer as an array of unsigned ints for processing on a GPU. For debugging purposes I'd like to print the base 10 representation of one of these numbers, but am having difficulty wrapping my head around it. …
Rich
  • 12,068
  • 9
  • 62
  • 94
5
votes
3 answers

How do I iterate over large numbers in Python using range()?

I want to iterate a large number such as 600851475143 using the range() function in Python. But whenever I run the program it gives me an OverflowError. I have used the following code - um = long(raw_input()) for j in range(1,num): .... I have…
Soham Banerjee
  • 79
  • 1
  • 2
  • 7
5
votes
5 answers

Best coding language for dealing with large numbers (50000+ digits)

Can you recommend good languages to do math with large numbers in? So far I've used Actionscript 2 and Objective-c and with Objective-c even using NSDecimalNumbers I was limited to 32 digits in my calculations... I would need at a minimum to be able…
Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195
5
votes
2 answers

What is the logic behind Fourier division algorithm?

from Wikipedia: fourier division. Here is a screenshot of the same: (view in full-resolution) What is the logic behind this algorithm? I know it can be used to divide very large numbers, but how exactly does it work?
Lazer
  • 90,700
  • 113
  • 281
  • 364
5
votes
3 answers

android R.integer returns incorrect Extremely large value causing out of mem while creating array

I have declared few integer values in an xml and need to use the values in a Class to define the array size of an object.
Anshul
  • 680
  • 1
  • 5
  • 19
5
votes
2 answers

finding binomial co-effecient modulo prime number,Interview street challenge

I have done a lot of work on this but couldnt find the answer for larger test cases Problem statement In mathematics, binomial coefficients are a family of positive integers that occur as coefficients in the binomial theorem. C(n,k) denotes the…
5
votes
5 answers

Summing Large Numbers

I have being doing some problems on the Project Euler website and have come across a problem. The Question asks,"Work out the first ten digits of the sum of the following one-hundred 50-digit numbers." I am guessing there is some mathematical way to…
Jake Runzer
  • 957
  • 3
  • 17
  • 35
4
votes
1 answer

C++ - GMP pow() function

I am trying to do pow(2,500) in C++. But I think long long is not enough. Someone told me I can use gmp.h. But how do I do a pow(2,500) in gmp?
JJ Liu
  • 1,351
  • 8
  • 20
  • 36
4
votes
3 answers

Fast multiplication of very large numbers in perl

I have 50,000 numbers (that could range from 0 to 50,000). And I need (product of these numbers) MOD 1000000007. The following code is so trivial, there should be other ways. Heard about "Divide and conquer" techniques, but have no idea how to…
trinity
  • 10,394
  • 15
  • 49
  • 67
4
votes
1 answer

C++ and way-too-big numbers (Miller-Rabin primality test; calculating a power with pow() and then applying the modulo operator)

I had to write a code, that determines whether a number is prime or not via Miller-Rabin primality test. The code here: #include #include #include #include using namespace std; int main() { …
4
votes
2 answers

Fast method for testing a bit of a large int

In a number-theoretic algorithm manipulating very large integer n (hundred thousand bits to few millions), I need to test the jth bit. Either of these work: if 1<>j & 1 != 0 : # bit j of n is set but…
fgrieu
  • 2,724
  • 1
  • 23
  • 53
4
votes
2 answers

Bash number sequence returned in scientific notation?

I'm trying to create a file with all the numbers up 75 million on every line. I'm typing in my terminal using Bash: seq 1 75000000 > myfile.csv But anything above 1 million gets turned into scientific notation and I'd want everything as integer…
FinanceGardener
  • 188
  • 2
  • 17
4
votes
4 answers

Multiply a float with a very large integer in Python

In Python, is there any way to multiply a float with a very large integer? As an example, I tried print (10**100000) * 1.414 and it gave me: OverflowError: long int too large to convert to float Note that the values (the float and that large…
Sushil Verma
  • 659
  • 9
  • 23
4
votes
2 answers

How to correctly use Mod 10^9+7

In Java, I need to calculate sum of squares of first n numbers i.e. 1^2 + 2^2+ 3^2+.....+n^2 which is n(n+1)(2n+1)/6 OR n^3/3 + n^2/2 + n/6 Then I need to calculate another value n*(n-1/2)^2 As n is going to be very big answer can be…
Kaushik Lele
  • 6,439
  • 13
  • 50
  • 76
4
votes
2 answers

How does this way of calculating large numbers work?

Typically, to handle integers that exceed the range of long long in C++, you'd have to represent them as string and perform operations on them that way. But, I found this code on the internet which seems to work like magic. It calculates any sum of…
Stefan Dimeski
  • 438
  • 4
  • 16