Example #1
0
inches_t Distance( coordinates_t A, coordinates_t B )
{
   int32_t operand1, operand2;
   Word upper, lower;
   inches_t xDiff, yDiff;
   
   xDiff = A.x - B.x;
   yDiff = A.y - B.y;
   
   _asm
   {
      LDY   xDiff
      LDD   xDiff
      EMULS
      STY   upper
      STD   lower
   }
   operand1.breakdown.upperWord = upper;
   operand1.breakdown.lowerWord = lower;
   
   _asm
   {
      LDY   yDiff
      LDD   yDiff
      EMULS
      STY   upper
      STD   lower
   }
   operand2.breakdown.upperWord = upper;
   operand2.breakdown.lowerWord = lower;
   
   return SquareRoot( operand1.quadword + operand2.quadword );
}
Example #2
0
const float Magnitude(const TVector4f& _krV)
{
	return(SquareRoot(	Square(_krV.m_fX)
							+	Square(_krV.m_fY)
							+	Square(_krV.m_fZ)
							+	Square(_krV.m_fW)));
}
/* Multiplier multiplies up all calculated values, so that decimal places can be represented */
void Statistics_Calculate(
	const StatisticsType *Instance,
	unsigned int          MeanMultiplier,
	uint64_t             *Mean,
	unsigned int          SDMultiplier,
	uint64_t             *StandardDeviation,
	unsigned int         *Minimum,
	unsigned int         *Maximum,
	unsigned int         *Samples)
{
	uint64_t Sum, Sum2, StandardDeviation2n2, StandardDeviationMn;
	*Samples = Instance->Samples;
	*Minimum = Instance->Minimum;
	*Maximum = Instance->Maximum;
	if (Instance->Samples == 0)
		return;

	Sum   = Instance->Sum;
	*Mean = div64_u64((uint64_t) MeanMultiplier * Sum + (uint64_t) (Instance->Samples / 2), (uint64_t) Instance->Samples);

	Sum2 = Instance->Sum2;
	StandardDeviation2n2 = (uint64_t) Instance->Samples * Sum2 - Sum * Sum;
	StandardDeviationMn  = SquareRoot(SDMultiplier * SDMultiplier * StandardDeviation2n2);
	*StandardDeviation = div64_u64(StandardDeviationMn + (uint64_t) (Instance->Samples / 2), (uint64_t) Instance->Samples);
}
/** Rebins the distributions and sets error values.
 */
MatrixWorkspace_sptr
VesuvioL1ThetaResolution::processDistribution(MatrixWorkspace_sptr ws,
                                              const double binWidth) {
  const size_t numHist = ws->getNumberHistograms();

  double xMin(DBL_MAX);
  double xMax(DBL_MIN);
  for (size_t i = 0; i < numHist; i++) {
    const std::vector<double> &x = ws->readX(i);
    xMin = std::min(xMin, x.front());
    xMax = std::max(xMax, x.back());
  }

  std::stringstream binParams;
  binParams << xMin << "," << binWidth << "," << xMax;

  IAlgorithm_sptr rebin = AlgorithmManager::Instance().create("Rebin");
  rebin->initialize();
  rebin->setChild(true);
  rebin->setLogging(false);
  rebin->setProperty("InputWorkspace", ws);
  rebin->setProperty("OutputWorkspace", "__rebin");
  rebin->setProperty("Params", binParams.str());
  rebin->execute();
  ws = rebin->getProperty("OutputWorkspace");

  for (size_t i = 0; i < numHist; i++) {
    const std::vector<double> &y = ws->readY(i);
    std::vector<double> &e = ws->dataE(i);

    std::transform(y.begin(), y.end(), e.begin(), SquareRoot());
  }

  return ws;
}
Example #5
0
const double Magnitude(const TVector4d& _krV)
{
	return(SquareRoot(	Square(_krV.m_dX)
							+	Square(_krV.m_dY)
							+	Square(_krV.m_dZ)
							+	Square(_krV.m_dW)));
}
Example #6
0
int main(int argc, char** argv) {

    unsigned int N=atoi(argv[1]);
    unsigned int i=N;
    myList=malloc(sizeof(LIST));

    //insert the values from 2 to N into the list
    for(;i>1;i--)
        insert(myList,i);

    root=SquareRoot(N); //calculate sqrt(N)
    c=0;
    NODE *ptr=myList->first;
    //first thread to delete multiples of 2
    pthread_create(&(threads[c]),NULL,removeMultiples,(void *)ptr); 

    //Wait for threads to finish their execution
    for (i = 0; i <=c; ++i)
         pthread_join (threads[i], NULL);
    pthread_mutex_destroy(&listLock);

    //prints the primes that are calculated
    NODE *f = myList->first;
    while(f){
        printf("%d\n",f->data);
        f=f->next;
    }
   // puts("END OF THE PROJECT 4");
    return (EXIT_SUCCESS);
}//END
Example #7
0
	AUR_FLOAT32 Vector3::Distance( const Vector3 &p_Other ) const
	{
		AUR_FLOAT32 X = m_X - p_Other.m_X;
		AUR_FLOAT32 Y = m_Y - p_Other.m_Y;
		AUR_FLOAT32 Z = m_Z - p_Other.m_Z;

		return SquareRoot( X*X + Y*Y + Z*Z );
	}
int main(){
	double x;
	double y;

	printf("Please input x, compute f(x)=x^1/2.  \"f(n+1)=(f(n)+x/f(n))/2\"\n");
	scanf("%lf", &x);
	if (x < 0){
		printf("\n\tError!");
	}
	else{
		y = SquareRoot(x);
		printf("\tf(%g)=%g", x, y);
	}
}
Example #9
0
inches_t GetFloorDistance( inches_t hypotenuse )
{
   int32_t hypotenuseSquared;
   Word upper, lower;
   static const CeilingHeightSquared = CEILING_HEIGHT * CEILING_HEIGHT;
   
   if ( hypotenuse < 0 ) return hypotenuse;
   
   _asm
   {
      LDY   hypotenuse 
      LDD   hypotenuse
      EMULS
      STY   upper
      STD   lower
   }
   hypotenuseSquared.breakdown.upperWord = upper;
   hypotenuseSquared.breakdown.lowerWord = lower;
   
   return SquareRoot( hypotenuseSquared.quadword - CeilingHeightSquared );
}
Example #10
0
UtilityMath::S_Vector2<T> UtilityMath::S_Vector2<T>::s_Refract(const UtilityMath::S_Vector2<T>& rIncidentVector, 
                                                               const UtilityMath::S_Vector2<T>& rNormal,
                                                               T refractiveIndex)
{
    // 各ベクトルを単位ベクトル化
    S_Vector2 normalizationIncidentVector = rIncidentVector.GetNormalize();
    S_Vector2 normalizationNormal = rNormal.GetNormalize();

    // 入射ベクトルと法線ベクトルの内積を求める
    T dotProduct = s_DotProduct(normalizationIncidentVector, normalizationNormal);

    // 屈折の角度
    T refractAngle = static_cast<T>(1) - refractiveIndex * refractiveIndex * (static_cast<T>(1) - dotProduct * dotProduct);

    // 屈折ベクトルを求める
    S_Vector2 refractVector;
    if (refractAngle < static_cast<T>(0)) return refractVector;

    refractVector = refractiveIndex * normalizationIncidentVector 
                  - (refractiveIndex * dotProduct * SquareRoot(refractAngle)) * normalizationNormal;

    return refractVector;
}
int32_t main( int32_t argc, char** argv )
{
   int32_t guess, lastGuess, operand;
   if ( argc != 2 )
   {
      printf( "Syntax: <executable> <operand>\n" );
      exit( 1 );
   }
   operand = atoi( argv[ 1 ] );
   /*guess = 40000;

   printf( "guess = %d\n", guess );
   for ( ; ; )
   {
      lastGuess = guess;
      guess = guess - ( ( guess * guess ) - operand ) / ( 2 * guess );
      printf( "guess = %d\n", guess );
      if ( lastGuess == guess ) break;
   }
   */
   SquareRoot( operand );
   return 0; 
}
Example #12
0
 int main(void)
 {
 	printf("%f", SquareRoot(4.0));
 	return 0;
 }
Example #13
0
	AUR_FLOAT32 Vector3::Magnitude( ) const
	{
		return SquareRoot( m_X * m_X + m_Y * m_Y + m_Z * m_Z );
	}
Example #14
0
 inline f32 InverseSquareRoot(f32 number) {
     return 1.0f / SquareRoot(number);
 }
Example #15
0
void Entity::Move(ID3D11Device* device, Vector3_t moveAccel, GameWorld* gameWorld, float frameTime)
{
    // CHANGE MOVE_BITMASK TO V3 inAccel
    float dt = frameTime/1000.0f;
    Vector3_t accelVec = {0, 0, 0};

    // Get the rotation in radians to correct in the movement
    float moveDirCos = 1.0f;
    float strafeDirCos = 0.0f;

    // Set the acceleration vector to just the x & z components first for normalization purposes
    accelVec.x = moveAccel.x;
    accelVec.z = moveAccel.z;

    // Normalize the X & Z movement
    float accelLength = LengthSq(accelVec);
    if(accelLength > 1.0f)
    {
        accelVec *= (1.0f / SquareRoot(accelLength));
    }

    // Twiddle factor for movment speed (8.0 is used to combat the drag for movement)
    float entitySpeed = WALK_SPEED*8.0f;
    accelVec *= entitySpeed;

    // TODO(ebd): ODE here!
    if (m_groundDragEn)
    {
        accelVec.x += -8.0f*m_velocity.x;
        accelVec.z += -8.0f*m_velocity.z;  
    }
    else
    {
        accelVec.x += -5.0f*m_velocity.x;
        accelVec.z += -5.0f*m_velocity.z;
    }

    // Now add in the y acceleration value
    accelVec.y = moveAccel.y*entitySpeed*20.0f;

    // Add gravity
    accelVec.y -= GRAVITY_ACCEL;

    // Now do physics based movement
    
    // Need to add Physics objects to the entity
    // RigidBody object -> holds postion, rotation, velocity, accel, and handles movement for the entity
    // Collider object -> holds information about the bounding box and handles collision functions
    // m_RigidBody->Move(&oldPosition);
    // m_Collider->CollisionTest(&position, &rotation);  // This should return a bool for if there was a collision or not
    
    // Do the movement internally for now
    Vector3_t oldPosition = m_position;
    Vector3_t positionDelta = (0.5f*accelVec*Square(dt) + m_velocity*dt);
    
    m_velocity = accelVec*dt + m_velocity;
    m_position = oldPosition + positionDelta;

    // Do minkowski based collision here
    // First get a list of game map tiles to search through
/*
    uint32 minTileX = FloorFloattoUint32(Minimum(m_position.x, oldPosition.x) - m_aabb.x/2);
    uint32 maxTileX = FloorFloattoUint32(Maximum(m_position.x, oldPosition.x) + m_aabb.x/2);
    uint32 minTileZ = FloorFloattoUint32(Minimum(m_position.z, oldPosition.z) - m_aabb.z/2);
    uint32 maxTileZ = FloorFloattoUint32(Maximum(m_position.z, oldPosition.z) + m_aabb.z/2);
*/
    uint32 minTileX = FloorFloattoUint32(Minimum(m_position.x, oldPosition.x));
    uint32 maxTileX = FloorFloattoUint32(Maximum(m_position.x, oldPosition.x));
    uint32 minTileZ = FloorFloattoUint32(Minimum(m_position.z, oldPosition.z));
    uint32 maxTileZ = FloorFloattoUint32(Maximum(m_position.z, oldPosition.z));

    // Set the time remaining on the search to 1.0
    // We use this to find where the collision was along the movement vector
    float tMin = 1.0f;
    Vector3_t collisionNormal = {0.0f, 0.0f, 0.0f};
    bool floorCollision = false;

    // Test each tile in the search space
    for (uint32 tileX = minTileX; tileX <= maxTileX; tileX++)
    {
        for (uint32 tileZ = minTileZ; tileZ <= maxTileZ; tileZ++)
        {
            // Get the normal for the current tile (is it a wall or floor or neither)
            collisionNormal = gameWorld->GetTileNormal(tileX, tileZ);

            // Get the current tile value, and if there is a valid tile then do collision there
            if (collisionNormal.y == 1.0f)
            {
                if (TestFloorCollision(oldPosition, positionDelta, &tMin))
                {
                    collisionNormal = {0.0f, 1.0f, 0.0f};
                    floorCollision = true;
                }     
            } 
        }
    }

    if (!floorCollision)
        collisionNormal = {0.0f, 0.0f, 0.0f};

    // Now update the entity position based on the output of the collision detection
    // Update the timeRemaining using tMin
    m_position.y = oldPosition.y + tMin*positionDelta.y;
    m_velocity = m_velocity - 1*Inner(m_velocity, collisionNormal)*collisionNormal;

/*
    if (m_position.y < 0)
    {
        m_position.y = 0;
        m_velocity.y = 0;
    }
*/

    // Now updat the model position to be where the entity is
    m_Model->UpdatePosition(device, m_position);
}
Example #16
0
T UtilityMath::S_Vector2<T>::GetLength() const
{
    return SquareRoot(GetLengthSquare());
}
Example #17
0
 /*************************************************************//**
  *
  *  @brief  平方根を求める
  *  @param  値
  *  @return 値の平方根
  *
  ****************************************************************/
 float C_Heage::s_SomeWhat(float value)
 {
     return SquareRoot(value);
 }
Example #18
0
 T S_Vector4<T>::GetLength() const
 {
     return SquareRoot(GetLengthSquare());
 }
Example #19
0
    //returns the standard deviation of all the numbers in the sequence
    float STD()
    {
        return SquareRoot((Sum(2) - (Sum(1) * Sum(1) / TotalNumbers())) / (TotalNumbers() - 1));

    }