Skip to content
Advertisement

Tag: biginteger

BigInteger.isProbablePrime seems much more certain than it says it is

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

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

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

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