Changeset cd22d1a in git
- Timestamp:
- Jan 31, 2003, 10:04:38 AM (21 years ago)
- Branches:
- (u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
- Children:
- 0b937c66fb6d3cee867a7255179563d6e5108b3b
- Parents:
- 2eb3dbb39cecb0405a162b62f67738ea926e7e2e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/ipshell.cc
r2eb3db rcd22d1a 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: ipshell.cc,v 1.7 8 2002-12-13 16:20:06Singular Exp $ */4 /* $Id: ipshell.cc,v 1.79 2003-01-31 09:04:38 Singular Exp $ */ 5 5 /* 6 6 * ABSTRACT: … … 11 11 #include <string.h> 12 12 #include <ctype.h> 13 #include <math.h> 13 14 14 15 #include "mod2.h" … … 578 579 else if (p == 2) return p; 579 580 else if (p < 0) return (-IsPrime(-p)); 580 else if (p > 32002) return 32003; // without this line, max prime is 32749581 581 else if (!(p & 1)) return IsPrime(p-1); 582 582 #ifdef HAVE_FACTORY 583 int a=0; 584 int e=cf_getNumSmallPrimes()-1; 585 i=e/2; 586 do 587 { 588 if (p==(j=cf_getSmallPrime(i))) return p; 589 if (p<j) e=i-1; 590 else a=i+1; 591 i=a+(e-a)/2; 592 } while ( a<= e); 593 if (p>j) return j; 594 else return cf_getSmallPrime(i-1); 583 else if (p<=32749) // max. small prime in factory 584 { 585 int a=0; 586 int e=cf_getNumSmallPrimes()-1; 587 i=e/2; 588 do 589 { 590 if (p==(j=cf_getSmallPrime(i))) return p; 591 if (p<j) e=i-1; 592 else a=i+1; 593 i=a+(e-a)/2; 594 } while ( a<= e); 595 if (p>j) return j; 596 else return cf_getSmallPrime(i-1); 597 } 598 #endif 599 #ifdef HAVE_FACTORY 600 int end_i=cf_getNumSmallPrimes()-1; 595 601 #else 596 for (j=p/2+1,i=3; i<p; i+=2) 597 { 598 if ((p%i) == 0) return IsPrime(p-2); 599 if (j < i) return p; 602 int end_i=p/2; 603 #endif 604 int end_p=(int)sqrt((double)p); 605 restart: 606 for (i=0; i<end_i; i++) 607 { 608 #ifdef HAVE_FACTORY 609 j=cf_getSmallPrime(i); 610 #else 611 if (i==0) j=2; 612 else j=2*i-1; 613 #endif 614 if ((p%j) == 0) 615 { 616 #ifdef HAVE_FACTORY 617 if (p<=32751) return IsPrime(p-2); 618 #endif 619 p-=2; 620 goto restart; 621 } 622 if (j > end_p) return p; 600 623 } 601 624 return p; 602 #endif603 625 } 604 626
Note: See TracChangeset
for help on using the changeset viewer.