示例#1
0
/* In the _vast_ majority of cases this simply checks that your chosen random
 * number is >= KLastSmallPrimeSquared and return EFalse and lets the normal
 * prime generation routines handle the situation.  In the case where it is
 * smaller, it generates a provable prime and returns ETrue.  The algorithm for
 * finding a provable prime < KLastPrimeSquared is not the most efficient in the
 * world, but two points come to mind
 * 1) The two if statements hardly _ever_ evaluate to ETrue in real life.
 * 2) Even when it is, the distribution of primes < KLastPrimeSquared is pretty
 * dense, so you aren't going to have check many.
 * This function is essentially here for two reasons:
 * 1) Ensures that it is possible to generate primes < KLastPrimeSquared (the
 * test code does this)
 * 2) Ensures that if you request a prime of a large bit size that there is an
 * even probability distribution across all integers < 2^aBits
 */
TBool TInteger::SmallPrimeRandomizeL(void)
	{
	TBool foundPrime = EFalse;
	//If the random number we've chosen is less than KLastSmallPrime,
	//testing for primality is easy.
	if(*this <= KLastSmallPrime)
		{
		//If Zero or One, or two, next prime number is two
		if(IsZero() || *this == One() || *this == Two())
			{
			CopyL(TInteger::Two());
			foundPrime = ETrue;
			}
		else
			{
			//Make sure any number we bother testing is at least odd
			SetBit(0);
			//Binary search the small primes.
			while(!IsSmallPrime(ConvertToUnsignedLong()))
				{
				//If not prime, add two and try the next odd number.

				//will never carry as the minimum size of an RInteger is 2
				//words.  Much bigger than KLastSmallPrime on 32bit
				//architectures.
				IncrementNoCarry(Ptr(), Size(), 2);
				}
			assert(IsSmallPrime(ConvertToUnsignedLong()));
			foundPrime = ETrue;
			}
		}
	else if(*this <= KLastSmallPrimeSquared)
		{
		//Make sure any number we bother testing is at least odd
		SetBit(0);

		while(HasSmallDivisorL(*this) && *this <= KLastSmallPrimeSquared)
			{
			//If not prime, add two and try the next odd number.

			//will never carry as the minimum size of an RInteger is 2
			//words.  Much bigger than KLastSmallPrime on 32bit
			//architectures.
			IncrementNoCarry(Ptr(), Size(), 2);
			}
		//If we exited while loop because it had no small divisor then it is
		//prime.  Otherwise, we've exceeded the limit of what we can provably
		//generate.  Therefore the normal prime gen routines will be run on it
		//now.
		if(*this < KLastSmallPrimeSquared)
			{
			foundPrime = ETrue;
			}
		}
	//This doesn't mean there is no such prime, simply means that the number
	//wasn't less than KSmallPrimeSquared and needs to be handled by the normal
	//prime generation routines.
	return foundPrime;
	}
示例#2
0
文件: sub.cpp 项目: CSCsw/CppAD
bool Sub(void)
{	bool ok = true;
	ok &= One();
	ok &= Two(); 
	ok &= Three(); 
	ok &= Four();
	return ok;
}
示例#3
0
void One_three()
{
	printf("One\n");
	Two();
	printf("three\n");
	
	return 0;
}
void handle_unexpected () {
  try
  {
    throw;
  }
  catch (One &)
  {
    throw Two ();
  }
}
示例#5
0
void main(void)
 {
   SomeClass One(1, 999); 
   cout << "One: " << One.my_data << ' ' << One.count << endl ;
   
   // Declare another instance
   SomeClass Two(2);
   cout << "Two: " << Two.my_data << ' ' << Two.count << endl ;
   
   // Declare another instance
   SomeClass Three(3);
   cout << "Three: " << Three.my_data << ' ' << Three.count << endl ;
 }
// ------------------------------------------------------------------------
int main( void ) {
	cout <<"                                 ID  Name\n";
	Ball One;			cerr <<"a. " << One <<endl;     // Default constructor 
	Ball Two( 75 );		cerr <<"b. " << Two <<endl;     // Normal constructor		
	Ball Three("Ali");	cerr <<"c. " << Three <<endl;	// Normal constructor		
	Ball Four( One );	cerr <<"d. " << Four <<endl; 	// Copy constructor
	Ball Five = Three;	cerr <<"e. " << Five <<endl;	// Copy Constructor
    cout << "\nReady to construct an array:" <<"\n";
	Ball Six[2];		cerr <<"\t" <<"f. "<< Six[0] <<"\t   " <<Six[1] <<"\n";
	// Ball Bad = Ball(77);						// Bad: Ball(77) not a Ball&
	cerr <<"\nNow " << One.getcount() <<" Ball objects have been created.\n"; 
	Four = Two; 		cerr << "g............................\n" // Assignment
                             <<"\t" << Four <<"\n\t"  << Two <<endl;   
	bye();
	return 0;
}
示例#7
0
TBool TInteger::IsPrimeL(void) const
	{
	if( NotPositive() )
		{
		return EFalse;
		}
	else if( IsEven() )
		{
		return *this == Two();
		}
	else if( *this <= KLastSmallPrime )
		{
		assert(KLastSmallPrime < KMaxTUint);
		return IsSmallPrime(this->ConvertToUnsignedLong());
		}
	else if( *this <= KLastSmallPrimeSquared )
		{
		return !HasSmallDivisorL(*this);
		}
	else 
		{
		return !HasSmallDivisorL(*this) && IsStrongProbablePrimeL(*this);
		}
	}
示例#8
0
文件: koenig5.C 项目: AHelper/gcc
void g (N::A *a, M::B *b, O::C *c)
{
  One (a); // ok
  One (a, b); // ok
  One (b); // { dg-error "not declared" }
  // { dg-message "suggested alternatives" "suggested alternative for One" { target *-*-* } 34 }

  Two (c); // ok
  Two (a, c); // ok
  Two (a); // { dg-error "not declared" }
  // { dg-message "suggested alternatives" "suggested alternative for Two" { target *-*-* } 39 }
  Two (a, a); // error masked by earlier error
  Two (b); // error masked by earlier error
  Two (a, b); // error masked by earlier error
  
  Three (b); // ok
  Three (a, b); // ok
  Three (a); // { dg-error "not declared" }
  // { dg-message "suggested alternatives" "suggested alternative for Three" { target *-*-* } 47 }
}