I understand the certainty argument to mean: certainty – a measure of the uncertainty that the caller is willing to tolerate: if the call returns true the probability that this BigInteger is prime exceeds (1 – 1/2certainty) From my experiments, it seems to exceed it by quite a lot! The code below finds “probable primes” between 2 and 1 million

# Tag: biginteger

## Something wrong with BigInteger

when i test this function with base16 :F0F0F0F0F0F0F0, it return right result = 67818912035696880 BUT when i test with base16: F0F0F0F0F0F0F0F0, it returns wrong result: 17361641481138401580 which right result must be 17361641481138401520 please help me! Answer Math.pow delivers a double, 8 bytes. So from some huge double value, it becomes imprecise in the less significant digits. You could have used

## why is my primality test failing so often when randomizing a BigInteger?

I wasn’t able to get true for both p and q, most of the results is both false or rarely p is true but q is false, why wouldn’t this test ever be true for both p and q? BigInteger bitSize100 = new …

## Java BigInteger alternative

Is there a way to improve BigInteger performance with caching? When you operate on BigInteger it always creates a new BigInteger. For example, when you multiply two big integers, a new BigInteger is created to host the result. I want to use some mutable version of a BigInteger that will update one of the fields with the result. Answer There

## Fibonacci calculator with BigIntegers

I’m working on a homework project where I must have the user input a number, and the computer spits out the Fibonacci numbers up to that one. I’d normally be able to do this, with int values, except that for this program, I need to use the BigInteger type instead, because int, long, double, etc. types are too small to

## 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.

## Converting from Integer, to BigInteger

I was wondering if there was any way to convert a variable of type Integer, to BigInteger. I tried typecasting the Integer variable, but i get an error that says inconvertible type. Answer The method you want is BigInteger#valueOf(long val). E.g., Making a String first is unnecessary and undesired.