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

**Advertisement**

# Tag: biginteger

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

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

**Advertisement**