Beispiel #1
0
Verylong::Verylong(const char *value)
{
	if(value)
	{
		vlsign = (*value == '-') ? 1:0;

		 if(ispunct(*value))
			{
				vlen = strlen(value)-1;
				vlstr = new char[vlen + 1];
				strcpy(vlstr, value+1);           
			}
		 else
			{
				vlen = strlen(value);
				vlstr = new char[vlen + 1];
				strcpy(vlstr, value);
			}
		strrev(vlstr);
	}
	else
	{
        vlstr = NULL;
		SetZero();
    }
}
void mexFunction(
				 int nlhs, mxArray *plhs[],
				 int nrhs, const mxArray *prhs[])
{
    
       SetZero( );
}
Beispiel #3
0
Verylong::Verylong(int n)
{
	int i;
	if ( n < 0 ) 
    { 
        vlsign = 1;
        n = (-n);
    }
	else 
        vlsign = 0;

	if ( n )
	{
		i = (int)log10((double)n)+2;
		vlstr = new char[i];
		vlen = i-1;
		i = 0;
		while (n >= 1)
		{
			vlstr[i] = n%10 + '0';
			n /= 10;
			i++;
		}
		vlstr[i] = '\0';
	}
	else
	{
        vlstr = NULL;
	    SetZero();
    }
}
Beispiel #4
0
pVec3_t CrossC(pVec3_t V1, pMat3_t M, int ind, pVec3_t Vout){
  Vec3_t tmpV;
  int i;
  if((ind < 0)||(ind > 2)) return(SetZero(Vout));
  for(i=0;i<3;i++) tmpV.val[i] = M->val[i][ind];
  return(Cross(V1, &tmpV, Vout));
}
void CMatrix4::SetUnit ()
{
	SetZero();
	mat[0][0]=1;
	mat[1][1]=1;
	mat[2][2]=1;
	mat[3][3]=1;
}
Beispiel #6
0
pVec2_t DotR(pVec2_t V1, pMat2_t M, int ind, pVec2_t Vout) 
{
  Vec2_t tmpV;
  int i;
  if((ind < 0)||(ind > 1)) return(SetZero(Vout));
  for(i=0;i<2;i++) tmpV.val[i] = M->val[ind][i];
  return(Dot(&tmpV, V1, Vout));
}
Beispiel #7
0
pVec3_t DotR(pVec3_t V1, pMat3_t M, int ind, pVec3_t Vout) // if V1 is zero, returns zero. otherwise, returns V1 projected onto row ind of M
{
  Vec3_t tmpV;
  int i;
  if((ind < 0)||(ind > 2)) return(SetZero(Vout));
  for(i=0;i<3;i++) tmpV.val[i] = M->val[ind][i];
  return(Dot(&tmpV, V1, Vout));
}
Beispiel #8
0
void
init_delta_time(delta_t *ctx)
{
#ifdef HAVE_ABSOLUTE_TIME
    SetZero(*ctx);
#else
    timerclear(ctx);
#endif 
}
 /*
 * Multiplies to Big ints according to basic school method
 * Remark: Bigints a and b must have the same length, which must be of
   form 2^{k}. p points to a Bigint of double size - 2^{k+1} - the
   result is saved in.
 */
 void NaivMultiplication( bigintexpo k, bigint* p, const bigint* a, const bigint* b )
 {
   
   bigintlength i, j;
   bigintlength length = 1 << k;
   
   SetZero( length*2, p );
   
   /* Collect the carries and add them later */
   bigint* overflows = (bigint*)malloc( sizeof(bigint)*length*2 );
   assert( overflows != NULL );
   SetZero( length*2, overflows );
   
   /* main part */
   for( i = 0; i < length; i++ )
   {
     for( j = 0; j < length; j++ ){
       
       long long w1, w2, w3;
       bool carry  = false;
       
       w1 = a[i];
       w2 = b[j];
       w3 = w1*w2;
       
       /*
       * If the rest of the code works properly
       * we can use the following line
       * without fear of memory corruption
       */
       Add( 2, p+(i+j), (bigint*)&w3, &carry );
       if(carry) overflows[i+j+2]++;
       
     }
   }
   
   /* evaluate the carries */
   bool carry = false;
   Add( 2*length, p, overflows, &carry );
   assert(!carry);
   
   free( overflows );
   
 }
Beispiel #10
0
Matrix4& Matrix4::createScaleMatrix4(float x, float y, float z) {
	SetZero(); 
	
	var[0][0] = x;
	var[1][1] = y;
	var[2][2] = z;

	var[3][3] = 1;
	return *this;
}
Beispiel #11
0
//缩放矩阵
Matrix4& Matrix4::createScaleMatrix4(const Vector3 &factor) {
	SetZero();

	var[0][0] = factor.x;
	var[1][1] = factor.y;
	var[2][2] = factor.z;

	var[3][3] = 1;
	return *this;
}
Beispiel #12
0
	JMatrix::JMatrix(float m11, float m12, float m13, float m14,
					float m21, float m22, float m23, float m24,
					float m31, float m32, float m33, float m34,
					float m41, float m42, float m43, float m44)
	{
		SetZero();
		_m11 = m11;	_m12 = m12;	_m13 = m13;	_m14 = m14;
		_m21 = m21;	_m22 = m22;	_m23 = m23;	_m24 = m24;
		_m31 = m31;	_m32 = m32;	_m33 = m33;	_m34 = m34;
		_m41 = m41;	_m42 = m42;	_m43 = m43;	_m44 = m44;
	}
Beispiel #13
0
Matrix4::Matrix4(float x, float y, float z) {
	SetZero();

	var[0][0] = 1.0f;
	var[1][1] = 1.0f;
	var[2][2] = 1.0f;
	var[3][3] = 1.0f;

	var[3][0] = x;
	var[3][1] = y;
	var[3][2] = z;
}
Beispiel #14
0
//平移矩阵
Matrix4::Matrix4(const Vector3& transition) {
	SetZero();

	var[0][0] = 1.0f;
	var[1][1] = 1.0f;
	var[2][2] = 1.0f;
	var[3][3] = 1.0f;

	var[3][0] = transition.x;
	var[3][1] = transition.y;
	var[3][2] = transition.z;
}
Beispiel #15
0
//将当前矩阵设为平移矩阵
Matrix4& Matrix4::createTransitionMatrix4(const Vector3 &transition) {
	SetZero();

	var[0][0] = 1.0f;
	var[1][1] = 1.0f;
	var[2][2] = 1.0f;
	var[3][3] = 1.0f;

	var[3][0] = transition.x;
	var[3][1] = transition.y;
	var[3][2] = transition.z;

	return *this;
}
Beispiel #16
0
Matrix4& Matrix4::createTransitionMatrix4(float x, float y, float z) {
	SetZero();

	var[0][0] = 1.0f;
	var[1][1] = 1.0f;
	var[2][2] = 1.0f;
	var[3][3] = 1.0f;

	var[3][0] = x;
	var[3][1] = y;
	var[3][2] = z;

	return *this;
}
Beispiel #17
0
//单轴旋转矩阵
Matrix4::Matrix4(char axis, float degree) {
	SetZero();

	var[0][0] = 1.0f;
	var[1][1] = 1.0f;
	var[2][2] = 1.0f;
	var[3][3] = 1.0f;

	//如果没进行旋转
	if (-0.001f <= degree && degree <= 0.001f) {
		return;
	}

	degree = DEGREE(degree);
	float c = cosf(degree);
	float s = sinf(degree);

	switch (axis)
	{
	case 'x':
	case 'X':
		var[1][1] = c;
		var[2][2] = c;
		var[1][2] = s;
		var[2][1] = -s;
		break;
	case 'y':
	case 'Y':
		var[0][0] = c;
		var[2][2] = c;
		var[2][0] = s;
		var[0][2] = -s;
		break;
	case 'z':
	case 'Z':
		var[0][0] = c;
		var[1][1] = c;
		var[0][1] = s;
		var[1][0] = -s;
		break;
	//Should never reach here
	default:
		break;
	}
}
Beispiel #18
0
void
fpis2i(Internal *i, void *v)
{
    Single *s = v;

    i->s = (*s & Sign) ? 1: 0;
    if((*s & ~Sign) == 0) {
        SetZero(i);
        return;
    }
    i->e = ((*s>>23) & 0x00FF) - SingleExpBias + ExpBias;
    i->h = (*s & 0x007FFFFF)<<(1+NGuardBits);
    i->l = 0;
    if(i->e)
        i->h |= HiddenBit;
    else
        i->e++;
}
 /*
 * Multiplies to Big ints of size <= 128 according to basic school method
 * Bemerkung: Works like a NaivMultiplication, but it has been optimized
   for and is restricted to the case of k <= 7.
 */
 void NaivMultiplicationRestricted( bigintexpo k, bigint* p, const bigint* a, const bigint* b )
 {
   
   assert( k <= 7 );
   
   unsigned char i, j;
   unsigned char length = 1 << k;
   
   /* Collect the carries and add them later */
   unsigned char overflows[256];
   memset( overflows, 0, length*2 * sizeof(unsigned char) );
   
   
   SetZero( length*2, p );
   
   /* main part */
   for( i = 0; i < length; i++ )
   {
     for( j = 0; j < length; j++ ){
       
       unsigned long long w = (unsigned long long)(a[i]) * (unsigned long long)(b[j]);
       
       *(unsigned long long*)(p+(i+j)) += w;
       if( *(unsigned long long*)(p+(i+j)) < w ) overflows[i+j+2]++;
       
     }
   }
   
   /* process carries */
   short int t;
   bool carry = false;
   for( t = 0; t < 2*length; t++ )
   {
     p[t] += overflows[t];
     if( carry ) p[t]++;
     if( ( !carry && overflows[i] > p[t] ) || ( carry && overflows[t] >= p[t] ) )
       carry = true;
     else
       carry = false;
   }
   assert(!carry);
   
 }
BlockRandomAccessDenseMatrix::BlockRandomAccessDenseMatrix(
    const vector<int>& blocks) {
  const int num_blocks = blocks.size();
  block_layout_.resize(num_blocks, 0);
  num_rows_ = 0;
  for (int i = 0; i < num_blocks; ++i) {
    block_layout_[i] = num_rows_;
    num_rows_ += blocks[i];
  }

  values_.reset(new double[num_rows_ * num_rows_]);

  cell_infos_.reset(new CellInfo[num_blocks * num_blocks]);
  for (int i = 0; i < num_blocks * num_blocks; ++i) {
    cell_infos_[i].values = values_.get();
  }

  SetZero();
}
Beispiel #21
0
void
fpiw2i(Internal *i, void *v)
{
    Word w, word = *(Word*)v;
    short e;

    if(word < 0) {
        i->s = 1;
        word = -word;
    }
    else
        i->s = 0;
    if(word == 0) {
        SetZero(i);
        return;
    }
    if(word > 0) {
        for (e = 0, w = word; w; w >>= 1, e++)
            ;
    } else
  int main()
  {
    printf( "\nBig Integer multiplication\n\n");
    
    
    /*******************************/
    /* Testing of functionality    */
    /*******************************/
    
    /*
    * For testing, we can use different patterns as control samples
    * Numbers of form 0xFFFFF...FF are fit, as you can immediatly check
      the result by yourself.
    */
    
    printf( "Checking consistency!\n" );
    
    {
      const bigintexpo k = 7;
      const bigintlength l = 1 << k; /* Length */
      
      /*Iteration*/
      long int v = 0, vmax = 10;
      
      for( v = 0; v < vmax; v++ ){
    
        bigint P[l], Q[l];
        bigint R1[2*l], R2[2*l];
        
        bigintlength i;
        srand( clock() + rand() + v );
        
        /* Fill in sample */
        for( i = 0; i < l; i++ )
        {
          /* P[i] = 0xFFFFFFFF; */
          P[i] = rand()*rand();
        }
        
        for( i = 0; i < l; i++ )
        {
          /* Q[i] = 0xFFFFFFFF; */
          Q[i] = rand()*rand();
        }
        
        /* Naiv method */
        NaivMultiplication( k, R1, P, Q );
        
        /* Karatsuba-Ofmann */
        Multiply( k, R2, P, Q );
        
        /* Comparing */
        if( Compare( l*2, R1, R2 ) != 0 )
        {
          printf("Error occurred!\n Length:%ld\n", l );
          printf("Naiv method:\n");
          OutputBigint( l*2, R1 );
          printf("Karatsuba-Ofmann:\n");
          OutputBigint( l*2, R2 );
          return 1;
        }
        
      }
      
    }
    
    printf( "Comparison ok\n\n" );
     
    
    
    /*******************************/
    /* Testing of functionality    */
    /* Numbers of arbitrary length */
    /*******************************/
    
    printf( "Testing multiplikation of arbitrary length numbers!\n" );
    
    {
      
      const bigintlength l_act = 32;
      /* Factors have size 32 in memory */
      /* Only a part of this will be used semantically */
      const bigintlength l_1 = 5;
      const bigintlength l_2 = 17;
      const bigintlength l_prod = l_1 + l_2;
      
      /* iteration*/
      long int v = 0, vmax = 10;
      
      for( v = 0; v < vmax; v++ ){
    
        bigint P[l_act], Q[l_act];
        bigint R1[l_act*2], R2[l_act*2];
        
        bigintexpo k = getFittingExponent( l_1 > l_2 ? l_1 : l_2 );
        
        assert( k == 5 );
        
        bigintlength i;
        srand( clock() + rand() + v );
        
        /* Fill in samples */
        SetZero( l_act, P );
        for( i = 0; i < l_1; i++ )
        {
          /* P[i] = 0xFFFFFFFF; */
          P[i] = rand()*rand();
        }
        
        SetZero( l_act, Q );
        for( i = 0; i < l_2; i++ )
        {
          /* Q[i] = 0xFFFFFFFF; */
          Q[i] = rand()*rand();
        }
        
        SetZero( l_act*2, R1 );
        SetZero( l_act*2, R2 );
        
        /* Naiv method */
        NaivMultiplication( k, R1, P, Q );
        
        /* Karatsuba-Ofmann */
        Multiplikation( R2, l_1, P, l_2, Q );
        
        /* Comparison */
        if( Compare( l_prod, R1, R2 ) != 0 && Compare( l_act*2, R1, R2 ) != 0 )
        {
          printf("Error occured with arbitrary length numbers\n" );
          printf("Naiv method:\n");
          OutputBigint( l_prod, R1 );
          printf("Karatsuba-Ofmann:\n");
          OutputBigint( l_prod, R2 );
          return 1;
        }
        
      }
      
    }
    
    printf( "Comparison ok\n\n" );
    
    
    
    
    /***************/
    /* Performance */
    /***************/
    
    printf( "performance test\n" );
    
    long int t1, t2;
    
    t1 = clock();
    
    {
      const bigintexpo k = 11;
      const bigintlength l = 1 << k; /* Number of digits */
      
      long int v = 0, vmax = 100;
      
      /* printf( "Multiply %ld-times two numbers of length %ld\n", vmax, l ); */
      printf( "Multiply %ld-times two numbers of length %ld in base 2^32-system\n", vmax, l );
      printf( "approx. %lld decimal digits\n", (long long) 9 * l );

      /*
      * We can use several samples:
      * Iterate one specific multiplication
      * A specific subset of mulitplications
      * random numbers
      * ...
      */
      
      for( v = 0; v < vmax; v++ ){
    
        bigint P[l], Q[l];
        bigint R[2*l];
        
        bigintlength i;
        
        srand( time(NULL) * rand() + v*v*v*v );
        for( i = 0; i < l; i++ )
        {
          /* P[i] = 0x12345678; */
          //P[i] = (v << 16) + v;
           P[i] = rand() * UINT_MAX * rand(); 
        }
        for( i = 0; i < l; i++ ){
          /* Q[i] = 0x12345678; */
          //Q[i] = (v << 16) + v;
          Q[i] = rand() * UINT_MAX * rand(); 
        }
        
        Multiply( k, R, P, Q );
        
      }
      
    }
    
    t2 = clock();
    
    printf( "time: %ld0 ms \n", (t2-t1)/10000 );
    
    return 0;
    
    
  }
Beispiel #23
0
pVec2_t Dot(pVec2_t V1, pVec2_t V2, pVec2_t Vout) // if V1 is zero, returns zero. otherwise, returns V2 projected onto V1
{
  Vec2_t tmp;
  if(!UnitVector(V1, &tmp)) return(SetZero(Vout));
  return(Mult_sv(Dot(V2, &tmp), &tmp, Vout));
}
Beispiel #24
0
Matrix4::Matrix4() {
	SetZero();
}
//////////////////////////////////////////////////////////////////////////////
//
// ColorValueXmm()
//
ColorValueXmm::ColorValueXmm()
{
    SetZero();
}
Beispiel #26
0
VOID MatrixN<N,T>::SetIdentity()
{
  SetZero();
  SetDiagonal(1);
}
Beispiel #27
0
WinTime::WinTime() : mnTime(0)
{
	//紀錄開始時間
	SetZero();
}
Beispiel #28
0
	JMatrix::JMatrix(bool bIdentity)
	{
		bIdentity ? SetIdentity() : SetZero();
	}