Processing Rounding Errors Big Numbers

edited December 2017 in Questions about Code

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[2];

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

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

void setup() {
 run();
 println(results[0] + " " + results[1]); 
}

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?

Answers

Sign In or Register to comment.