#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Processing Rounding Errors Big Numbers

edited December 2017

I have the number 700821472143. I'm trying to apply Fermat's factorisation to find the greatest prime factor of it.

Here's my code so far:

``````long n = 700821472143L;
long[] results = new long;

boolean isInteger(float num) {
return num%1==0;
}

void run() {
for (int i=0; i < n; i++) {
if(isInteger(sqrt(n+i*i))) {
results = (long)sqrt(n+i*i)+i;
results = (long)sqrt(n+i*i)-i;
break;
}
}
}

void setup() {
run();
println(results + " " + results);
}
``````

Now the problem with the above is that I can't even get this to give me the two factors of the form of (x-y)*(x+y) which make up my big value. There seem to be unavoidable rounding errors from Processing. I get 837,694 and 836,608. If I multiply those two numbers together on my calculator I don't get 700821472143... I get 700821501952 . How can I avoid these errors?

Tagged:

• `final double sqrtN = Math.sqrt(i*i + n)`