Questions tagged [biginteger]

BigInteger is an arbitrary-precision arithmetic type in Java, C#, and other languages. It behaves like a signed integer whose size is limited only by available memory.

BigInteger is an arbitrary-precision arithmetic type in the .NET Framework, Java, and other languages. It behaves like a signed integer whose size is limited only by available memory.

1971 questions
52
votes
1 answer

JSON transfer of bigint: 12000000000002539 is converted to 12000000000002540?

I'm transferring raw data like [{id: 12000000000002539, Name: "Some Name"}] and I'm getting the object [{id: 12000000000002540, Name: "Some Name"}] after parsing, for now server side converting id into string seems to help. But is there a better way…
feipinghuang
  • 1,053
  • 1
  • 9
  • 13
46
votes
7 answers

BIGINT UNSIGNED value is out of range

I am getting the error BIGINT UNSIGNED value is out of range in '(1301980250 - mydb.news_articles.date)' When I run the query SELECT *, ((1 / log(1301980250 - date)) * 175) as weight FROM news_articles ORDER BY weight; Removing the ORDER BY…
Joyce Babu
  • 19,602
  • 13
  • 62
  • 97
45
votes
8 answers

A realistic example where using BigDecimal for currency is strictly better than using double

We know that using double for currency is error-prone and not recommended. However, I'm yet to see a realistic example, where BigDecimal works while double fails and can't be simply fixed by some rounding. Note that trivial problems double total =…
maaartinus
  • 44,714
  • 32
  • 161
  • 320
42
votes
4 answers

How to convert BigInteger to BigDecimal?

Is there any way to convert a BigInteger into a BigDecimal? I know you can go from a BigDecimal to a BigInteger, but I can't find a method to go the other way around in Java.
Regis
  • 421
  • 1
  • 4
  • 3
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
39
votes
6 answers

Logarithm of a BigInt

Is there a way to get the logarithm of a BigInt in JavaScript? With normal numbers, you would use this code: const largeNumber = 1000; const result = Math.log(largeNumber); However, I need to work with factorial numbers, potentially higher than…
Mielipuoli
  • 1,306
  • 2
  • 12
  • 23
39
votes
4 answers

Big numbers library in c++

I'm doing a project which requires really big numbers, up to 100 digits. I have read that java supports big integers (java.Math.BigInteger), and I want to know if there is something like that in C++. So, here is my question: Is there a standard or…
Rontogiannis Aristofanis
  • 8,883
  • 8
  • 41
  • 58
38
votes
3 answers

How does BigInteger store its data?

I've been searching around for quite a while, and I've found almost nothing on how BigInteger actually holds its numbers. Are they an array of chars? Something else? And how is data converted to/from BigInteger? From what I've found, I am assuming…
Jon Egeland
  • 12,470
  • 8
  • 47
  • 62
38
votes
8 answers

Calculate square root of a BigInteger (System.Numerics.BigInteger)

.NET 4.0 provides the System.Numerics.BigInteger type for arbitrarily-large integers. I need to compute the square root (or a reasonable approximation -- e.g., integer square root) of a BigInteger. So that I don't have to reimplement the wheel, does…
Anonym
  • 7,345
  • 8
  • 35
  • 32
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
36
votes
7 answers

Django BigInteger auto-increment field as primary key?

I'm currently building a project which involves a lot of collective intelligence. Every user visiting the web site gets created a unique profile and their data is later used to calculate best matches for themselves and other users. By default,…
letoosh
  • 511
  • 2
  • 6
  • 13
35
votes
10 answers

JavaScript summing large integers

In JavaScript I would like to create the binary hash of a large boolean array (54 elements) with the following method: function bhash(arr) { for (var i = 0, L = arr.length, sum = 0; i < L; sum += Math.pow(2,i)*arr[i++]); return sum; } In…
Raven
  • 1,453
  • 3
  • 18
  • 29
34
votes
2 answers

How to generate a "big" random number in Python?

How can I generate a big (more than 64 bits) random integer in Python?
Charles Brunet
  • 21,797
  • 24
  • 83
  • 124
33
votes
5 answers

BigInteger.toString method is deleting leading 0

I am trying to generate MD5 sum using MessageDigest. And i am having following code. byte[] md5sum = digest.digest(); BigInteger bigInt = new BigInteger(1, md5sum); output = bigInt.toString(16); This returns not 32 character string but a 31…
Dheeraj Joshi
  • 3,057
  • 8
  • 38
  • 55
32
votes
3 answers

Unsigned long in Java

Currently, I am using signed values, -2^63 to 2^63-1. Now I need the same range (2 * 2^64), but with positive values only. I found the java documentations mentioning unsigned long, which suits this use. I tried to declare 2^64 to a Long wrapper…
Annapoorni D
  • 831
  • 2
  • 13
  • 30