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

Handling very large numbers in Python

I've been considering fast poker hand evaluation in Python. It occurred to me that one way to speed the process up would be to represent all the card faces and suits as prime numbers and multiply them together to represent the hands. To whit: class…
Yes - that Jake.
  • 16,725
  • 14
  • 70
  • 96
83
votes
14 answers

How to implement big int in C++

I'd like to implement a big int class in C++ as a programming exercise—a class that can handle numbers bigger than a long int. I know that there are several open source implementations out there already, but I'd like to write my own. I'm trying to…
oneself
  • 38,641
  • 34
  • 96
  • 120
63
votes
13 answers

Big integers in C#

Currently I am borrowing java.math.BigInteger from the J# libraries as described here. Having never used a library for working with large integers before, this seems slow, on the order of 10 times slower, even for ulong length numbers. Does anyone…
Matthew Scharley
  • 127,823
  • 52
  • 194
  • 222
41
votes
6 answers

BigInteger equivalent in Swift?

Is there an equivalent to Java's BigInteger class in Swift? I am tying to do large calculations in Swift with positive integers larger than UInt64 maximum valye. What is the best way to handle these numbers in Swift?
liam923
  • 991
  • 1
  • 10
  • 19
36
votes
11 answers

working with incredibly large numbers in .NET

I'm trying to work through the problems on projecteuler.net but I keep running into a couple of problems. The first is a question of storing large quanities of elements in a List. I keep getting OutOfMemoryException's when storing large…
Greg B
  • 14,597
  • 18
  • 87
  • 141
33
votes
3 answers

How to sum large numbers?

I am trying to calculate 1 + 1 * 2 + 1 * 2 * 3 + 1 * 2 * 3 * 4 + ... + 1 * 2 * ... * n where n is the user input. It works for values of n up to 12. I want to calculate the sum for n = 13, n = 14 and n = 15. How do I do that in C89? As I know, I can…
Timʘtei
  • 753
  • 1
  • 8
  • 21
23
votes
10 answers

Handling large numbers in C++?

What is the best way to handle large numeric inputs in C++ (for example 10^100)? For algorithms I usually switch over to ruby and I sometimes use strings. Any other good methods?
kasperasky
  • 3,173
  • 5
  • 21
  • 16
13
votes
2 answers

Stocking large numbers into numpy array

I have a dataset on which I'm trying to apply some arithmetical method. The thing is it gives me relatively large numbers, and when I do it with numpy, they're stocked as 0. The weird thing is, when I compute the numbers appart, they have an int…
ysearka
  • 3,805
  • 5
  • 20
  • 41
12
votes
2 answers

java BigDecimal arithmaticException invalid operation

I cant find why I got a java.lang.ArithmeticException: Invalid operation while using big decimal. public static String E (int exponent, String value){ BigDecimal ten= new BigDecimal("10"); BigDecimal tempValue=new BigDecimal (value); return…
Error Messages
  • 304
  • 1
  • 3
  • 15
12
votes
3 answers

Generating very large random numbers java

How can we generate very large random number in java? I am talking something like 10000 digits? I know we have to use BigInteger but how can we do this? What is the most efficent way of doing something like this? Please provide a small example.…
Jeel Shah
  • 3,274
  • 17
  • 47
  • 68
12
votes
5 answers

Algorithm for dividing very large numbers

I need to write an algorithm(I cannot use any 3rd party library, because this is an assignment) to divide(integer division, floating parts are not important) very large numbers like 100 - 1000 digits. I found…
pocoa
  • 4,197
  • 9
  • 37
  • 45
12
votes
1 answer

How to work with large numbers in R?

I would like to change the precision in a calculation of R. For example I would like to calculate x^6 with x = c(-2.5e+59, -5.6e+60). In order to calculate it I should change the precision in R, otherwise the result is Inf, and I don't know how to…
user3430764
  • 241
  • 1
  • 2
  • 4
12
votes
6 answers

How to Code a Solution To Deal With Large Numbers?

I'm doing some Project Euler problems and most of the time, the computations involve large numbers beyond int, float, double etc. Firstly, I know that I should be looking for more efficient ways of calculation so as to avoid the large number…
r0ach
  • 511
  • 3
  • 6
  • 14
12
votes
2 answers

How to convert Active Directory pwdLastSet to Date/Time

public static string GetProperty(SearchResult searchResult, string PropertyName) { if (searchResult.Properties.Contains(PropertyName)) { return searchResult.Properties[PropertyName][0].ToString(); } …
software is fun
  • 7,286
  • 18
  • 71
  • 129
11
votes
3 answers

How to round/ceil/floor a bcmath number in PHP?

Is there any library function for this purpose, so I don't do it by hand and risk ending in TDWTF? echo ceil(31497230840470473074370324734723042.6); // Expected result 31497230840470473074370324734723043 // Prints
Eduardo Marinho
  • 446
  • 4
  • 14
1
2 3
30 31