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

is there anyway to convert from Double to BigInteger?

Is there anyway to convert from double value to BigInteger? double doubleValue = 64654679846513164.2; BigInteger bigInteger = (BigInteger) doubleValue; I try to cast it but it didn't work.
Krack
  • 374
  • 1
  • 4
  • 7
24
votes
4 answers

BigInteger to byte[]

I need to convert a Java BigInteger instance to its value in bytes. From the API, I get this method toByteArray(), that returns a byte[] containing the two's-complement representation of this BigInteger. Since all my numbers are positive 128 bits…
Kami
  • 5,959
  • 8
  • 38
  • 51
23
votes
3 answers

How to implement (fast) bigint division?

I'm currently making my own BigInt class, by splitting numbers by 7 digits. (i.e. in base 10,000,000) I implemented addition, subtraction, and multiplication, and now I'm implementing division and mod. I wrote a code that performs division by long…
JiminP
  • 2,136
  • 19
  • 26
23
votes
3 answers

How do I compare values of BigInteger to be used as a condition in a loop?

I am trying to compare if the value of one BigInteger(base) is > (greater than) the value of another BigInteger(prime) and if the value of 'a' is not equal to one. If value of a is not 1, it should break out of the loop. How should I compare…
Scar
  • 725
  • 2
  • 7
  • 28
23
votes
3 answers

BigInteger in Kotlin

I need to make use of BigInteger but can't find anything similar in kotlin. Is there any alternative class in kotlin to BigInteger of java? or should I import java class into kotlin?
Akshar Patel
  • 8,998
  • 6
  • 35
  • 50
23
votes
1 answer

Golang, math/big: what is the max value of *big.Int

What is the max value of *big.Int and max precision of *big.Rat?
Dmitriy Blokhin
  • 574
  • 1
  • 6
  • 14
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
23
votes
2 answers

Multiplication time in BigInteger

My mini benchmark: import java.math.*; import java.util.*; import java.io.*; public class c { static Random rnd = new Random(); public static String addDigits(String a, int n) { if(a==null) return null; if(n<=0) return…
Jan Ajan
  • 1,461
  • 3
  • 12
  • 15
22
votes
5 answers

How to convert BigInteger value to Hex in Java

I am making a Java program. I have a BigInteger number and I need to convert it to Hexadecimal. I tried the following code: String dec = null; System.out.println("Enter the value in Dec: "); BufferedReader br = new BufferedReader(new…
Jury A
  • 19,192
  • 24
  • 69
  • 93
22
votes
3 answers

A good and basic implementation of BigInt class in C++

I'm looking for a good and basic BigInt class in C++, I find a lot of implementation but most of the time, it's complex implementation for crypto library... By basic, I mean BigInt can deal with BigInt, long long and strings with operator…
Bebeoix
  • 579
  • 2
  • 5
  • 17
21
votes
3 answers

Recursive function calculating factorials leads to stack overflow

I tried a recursive factorial algorithm in Rust. I use this version of the compiler: rustc 1.12.0 (3191fbae9 2016-09-23) cargo 0.13.0-nightly (109cb7c 2016-08-19) Code: extern crate num_bigint; extern crate num_traits; use num_bigint::{BigUint,…
mrLSD
  • 688
  • 1
  • 5
  • 14
21
votes
6 answers

BigInteger: count the number of decimal digits in a scalable method

I need the count the number of decimal digits of a BigInteger. For example: 99 returns 2 1234 returns 4 9999 returns 4 12345678901234567890 returns 20 I need to do this for a BigInteger with 184948 decimal digits and more. How can I do this fast…
Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
20
votes
5 answers

Extremely large numbers in javascript

I'm working on the Project Euler problems (currently question 13). For this question I have to find the first 10 digits of the sum of 100 numbers all of a size similar to this: 91,942,213,363,574,161,572,522,430,563,301,811,072,406,154,908,250 I…
JEJoll
  • 547
  • 1
  • 6
  • 20
20
votes
3 answers

Java compare integer and bigInteger

How do I compare an int with a BigInteger in Java? I specifically need the know if an int is less than a BigInteger. Here is the code I am using: private static BigInteger two = new BigInteger("2"); private static BigInteger three = new…
Progo
  • 3,452
  • 5
  • 27
  • 44
20
votes
4 answers

Hibernate returns BigIntegers instead of longs

This is my Sender entity @Entity public class Sender { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long senderId; ... ... public long getSenderId() { return senderId; } public void…
Tristan Van Poucke
  • 323
  • 1
  • 3
  • 14