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

Need help implementing Karatsuba algorithm in C++

First a little background: - I'm a first time poster, a student in university (not in programming). - This is not a homework question, I'm only doing this for fun. - My programming experience consists of one semester (3 months) of C++, and some…
sth128
  • 93
  • 2
  • 8
6
votes
4 answers

Why do very large Fibonacci numbers create an ellipse-type shape?

in_range = int(input("range: ")) fibo_list = [] a = 0 b = 1 count = 0 if in_range < 0: print("faulty") elif in_range == 0: print("faulty") else: while count < in_range: c = a + b a = b b = c count += 1 …
Caspian Ahlberg
  • 934
  • 10
  • 19
6
votes
2 answers

Is there a library for large precision complex numbers in Python?

Is there a library for large precision complex numbers in Python?
eddie
  • 170
  • 7
6
votes
2 answers

C++ Random number from 1 to a very large number (e.g. 25 million)

How would you make a function that generates a random number from 1 to 25 million? I've thought about using rand() but am I right in thinking that the maximum number, RAND_MAX is = 32000 (there about)? Is there a way around this, a way that doesn't…
Alarming
  • 137
  • 1
  • 3
  • 14
6
votes
4 answers

infinite loop in c++

I'm learning C++ and writing little programs as I go along. The following is one such program: // This program is intended to take any integer and convert to the // corresponding signed char. #include int main() { signed char sch =…
108
  • 1,631
  • 3
  • 19
  • 25
6
votes
4 answers

Python: how so fast?

The period of the Mersenne Twister used in the module random is (I am told) 2**19937 - 1. As a binary number, that is 19937 '1's in a row (if I'm not mistaken). Python converts it to decimal pretty darned fast: $ python -m timeit…
telliott99
  • 7,762
  • 4
  • 26
  • 26
6
votes
1 answer

Handle large numbers with precision in Redis Lua

I need to handle large numbers in Lua which goes with Redis. Normally you would do that like: require"bc" bc.mul(...) bc.mod(...) etc. But unfortunately Redis Lua doesn't support "require". The only approach I've found is inserting a large numbers…
6
votes
3 answers

How to calculate "modular multiplicative inverse" when the denominator is not co-prime with m?

I need to calculate (a/b) mod m where a and b are very large numbers. What I am trying to do is to calculate (a mod m) * (x mod m), where x is the modular inverse of b. I tried using Extended Euclidean algorithm, but what to do when b and m are not…
Lazer
  • 90,700
  • 113
  • 281
  • 364
6
votes
3 answers

Compute 4^x mod 2π for large x

I need to compute sin(4^x) with x > 1000 in Matlab, with is basically sin(4^x mod 2π) Since the values inside the sin function become very large, Matlab returns infinite for 4^1000. How can I efficiently compute this? I prefer to avoid large data…
Bene
  • 157
  • 11
5
votes
2 answers

Why python isn't handling very large numbers in all areas?

I am doing a puzzle where I have to deal with numbers of order 10^18. However, I find python isn't able to handle very large numbers in all areas. To be specific, if we assign a = 1000000000000000000 (10^18) and do basic arithmetic calculations (+,…
Surya
  • 4,824
  • 6
  • 38
  • 63
5
votes
1 answer

Too many combinations

Hi I'm trying to generate all possible combinations of workers to buildings. (let me explain my scenario): I'm playing MineColonies on minecraft. In this mod you have colonists whom can be assigned jobs at buildings. These workers have skills and a…
5
votes
2 answers

Large decimal number formatting using NumberFormatter in Swift

I've done this to format the number, but it fails for large numbers let formatter = NumberFormatter() formatter.numberStyle = .decimal if let number = formatter.number(from: "123456789123456789123") , let str = formatter.string(from:number){ …
5
votes
2 answers

Best way to deal with very large Long numbers in Ajax?

Javascript represents all numbers as double-precision floating-point. This means it loses precision when dealing with numbers at the very highest end of the 64 bit Java Long datatype -- anything after 17 digits. For example, the…
Dean Moses
  • 2,372
  • 2
  • 24
  • 36
5
votes
6 answers

is a number a power of 2

How can I check whether a number is a power of 2? Below is what I have come up with so far: # check every number in a vector y <- 1:100000000 x <- 2^(0:100) y %in% x y[(y %in% x)==TRUE] # check a single number y <- 250000 x <- 2^(0:100) y %in%…
Mark Miller
  • 12,483
  • 23
  • 78
  • 132
5
votes
2 answers

Python 3 strange division

About half an hour thinking "what am i doing wrong!?" on the 5-lines code.. because Python3 is somehow rounding big integers. Anyone know why there is a problem such: Python2: int(6366805760909027985741435139224001 # This is 7**40. / 7)…
inexxt
  • 81
  • 1
  • 3
1 2
3
30 31