Exemple #1
0
int main()
{
	char X[MONTHS][15];
	char Y[MONTHS][15];
	int i,j;
	char **Z;
	char **ret;
	strcpy(X[0],"January");strcpy(X[1],"February");strcpy(X[2],"March");
	strcpy(X[3],"April");strcpy(X[4],"May"); strcpy(X[5],"June");
	strcpy(X[6],"July");strcpy(X[7],"August");strcpy(X[8],"September");
	strcpy(X[9],"October");strcpy(X[10],"November");strcpy(X[11],"December");

	copy1(X,Y);
	ret=copy2(X);
	copy3(X,&Z);
	printf("Output of copy1 --> Array Y\n");
	for(i=0;i<MONTHS;i++)
			printf("%s\n",Y[i]);
	printf("\n\n\n");

	printf("Output of copy2 --> ret\n");
	for(i=0;i<MONTHS;i++)
			printf("%s\n",ret[i]);
	printf("\n\n\n");

	printf("Output of copy3 --> Z\n");
	for(i=0;i<MONTHS;i++)
			printf("%s\n",Z[i]);
	printf("\n\n\n");

	return 0;
}
Exemple #2
0
void date_alphaday(enum nilop op) {
	decNumber x;
	int y, m, d, dow;

	getX(&x);
	if (decNumberIsSpecial(&x) || extract_date(&x, &y, &m, &d))
		err(ERR_BAD_DATE);
	else {
		dow = day_of_week(y, m, d, NULL);
		copy3(&("MONTUEWEDTHUFRISATSUN"[3*(dow-1)]));
	}
}
Exemple #3
0
void date_alphamonth(enum nilop op) {
	decNumber x;
	int y, m, d;
	static const char mons[12*3] = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";

	getX(&x);
	if (decNumberIsSpecial(&x) || extract_date(&x, &y, &m, &d))
		err(ERR_BAD_DATE);
	else {
		copy3(&(mons[3*m - 3]));
	}
}
Exemple #4
0
string_t time_current_string(timeval_t &timeval_curr) {
	time_current_cache_t &cache = time_current_cache;

	timeval_t t = timeval::current();
	timeval_curr = t;

	uint64_t cache_time = (t - timeval::unix_origin) / interval::second;

	if(cache_time != cache.last_time) {
		unsigned long cache_date = cache_time / (60 * 60 * 24);

		if(cache_date != cache.last_date) {
			timestruct_t ts(t);

			copy3(wnames[ts.wday], cache.buf);
			dig2(ts.day + 1, cache.buf + 5);
			copy3(mnames[ts.month], cache.buf + 5 + 3);
			dig4(ts.year + 1, cache.buf + 5 + 3 + 4);

			cache.last_date = cache_date;
		}

		// (timeval::unix_origin - timeval::epch_origin) % (60 * 60 * 24) == 0

		unsigned int _time = cache_time % (60 * 60 * 24);

		dig2(_time % 60, cache.buf + 5 + 3 + 4 + 5 + 3 + 3); _time /= 60;
		dig2(_time % 60, cache.buf + 5 + 3 + 4 + 5 + 3); _time /= 60;
		dig2(_time, cache.buf + 5 + 3 + 4 + 5);

		cache.last_time = cache_time;
	}

	return
		string_t::ctor_t(sizeof(cache.buf))
			(str_t(cache.buf, sizeof(cache.buf)))
		;
}
void tst_QAtomicIntegerXX::copy()
{
    QFETCH(LargeInt, value);

    QAtomicInteger<T> atomic(value);
    QAtomicInteger<T> copy(atomic);
    QCOMPARE(copy.load(), atomic.load());

    QAtomicInteger<T> copy2 = atomic;
    QCOMPARE(copy2.load(), atomic.load());

    // move
    QAtomicInteger<T> copy3(qMove(copy));
    QCOMPARE(copy3.load(), atomic.load());

    QAtomicInteger<T> copy4 = qMove(copy2);
    QCOMPARE(copy4.load(), atomic.load());
}
Exemple #6
0
void t02_dup(){ 
	INIT_LOCAL();
	
	Onion::Dict normal;
	normal.add("Hello", "World");

	Onion::Dict copy4;
	copy4=normal.c_handler();
	FAIL_IF_NOT_EQUAL_STRING(copy4.get("Hello"), "World");

	Onion::Dict copy2;
	copy2=normal;
	FAIL_IF_NOT_EQUAL_STRING(copy2.get("Hello"), "World");
	
	Onion::Dict copy=normal;
	FAIL_IF_NOT_EQUAL_STRING(copy.get("Hello"), "World");

	Onion::Dict copy3(normal);
	FAIL_IF_NOT_EQUAL_STRING(copy3.get("Hello"), "World");
	
	Onion::Dict dup=normal.hard_dup();
	FAIL_IF_NOT_EQUAL_STRING(dup.get("Hello"), "World");
	
	dup.add("Hello","world!",OD_REPLACE|OD_DUP_ALL);
	FAIL_IF_EQUAL_STRING(dup.get("Hello"), "World");
	FAIL_IF_NOT_EQUAL_STRING(dup.get("Hello"), "world!");

	FAIL_IF_EQUAL_STRING(copy.get("Hello"), "world!");
	FAIL_IF_EQUAL_STRING(copy2.get("Hello"), "world!");

	normal.add("Tst","tst");
	FAIL_IF_NOT_EQUAL_STRING(copy.get("Tst"), "tst");
	FAIL_IF_NOT_EQUAL_STRING(copy2.get("Tst"), "tst");
	FAIL_IF_EQUAL_STRING(dup.get("Tst"), "tst");
	
	END_LOCAL();
}
Exemple #7
0
TEST(WTF_HashSet, CopyCapacityIsNotOnBoundary)
{
    // Starting at 4 because the minimum size is 8.
    // With a size of 8, a medium load can be up to 3.3333->3.
    // Adding 1 to 3 would reach max load.
    // While correct, that's not really what we care about here.
    for (unsigned size = 4; size < 100; ++size) {
        HashSet<unsigned> source;
        for (unsigned i = 1; i < size + 1; ++i)
            source.add(i);

        HashSet<unsigned> copy1(source);
        HashSet<unsigned> copy2(source);
        HashSet<unsigned> copy3(source);

        EXPECT_EQ(size, copy1.size());
        EXPECT_EQ(size, copy2.size());
        EXPECT_EQ(size, copy3.size());
        for (unsigned i = 1; i < size + 1; ++i) {
            EXPECT_TRUE(copy1.contains(i));
            EXPECT_TRUE(copy2.contains(i));
            EXPECT_TRUE(copy3.contains(i));
        }
        EXPECT_FALSE(copy1.contains(size + 2));
        EXPECT_FALSE(copy2.contains(size + 2));
        EXPECT_FALSE(copy3.contains(size + 2));

        EXPECT_TRUE(copy2.remove(1));
        EXPECT_EQ(copy1.capacity(), copy2.capacity());
        EXPECT_FALSE(copy2.contains(1));

        EXPECT_TRUE(copy3.add(size + 2).isNewEntry);
        EXPECT_EQ(copy1.capacity(), copy3.capacity());
        EXPECT_TRUE(copy3.contains(size + 2));
    }
}
void maximize_the_injectivity_radius(
	MatrixPairList			*gen_list,
	Boolean					*basepoint_moved,
	DirichletInteractivity	interactivity)
{
	int					num_matrix_pairs;
	double				distance_moved,
						prev_distance_moved,
						total_distance_moved;
	Boolean				keep_going;
	ObjectiveFunction	objective_function;
	int					num_constraints;
	Constraint			*constraints;
	Solution			solution;
	Boolean				may_be_saddle_point,
						saddle_query_given;
	int					choice;

	static const Solution	zero_solution = {0.0, 0.0, 0.0},
							small_displacement = {0.001734, 0.002035, 0.000721};

	const static char		*saddle_message = "The basepoint may be at a saddle point of the injectivity radius function.";
	const static int		num_saddle_responses = 2;
	const static char		*saddle_responses[2] = {
								"Continue On",
								"Stop Here and See Dirichlet Domain"};
	const static int		saddle_default = 1;

	const static char		*zero_deriv_message = "The derivative of the distance to the closest translate of the basepoint is zero.";
	const static char		num_zero_deriv_responses = 2;
	const static char		*zero_deriv_responses[2] = {
								"Displace Basepoint and Continue On",
								"Stop Here and See Dirichlet Domain"};
	const static int		zero_deriv_default = 1;


	/*
	 *	Count the number of MatrixPairs.
	 */
	num_matrix_pairs = count_matrix_pairs(gen_list);

	/*
	 *	Make sure that
	 *
	 *	(1)	the identity and at least two other MatrixPairs are present,
	 *
	 *	(2)	the MatrixPairs are in order of increasing height.
	 *
	 *	Technical notes:  We don't really need to have the gen_list
	 *	completely sorted -- it would be enough to have the identity come
	 *	first and the element of lowest image height come immediately after.
	 *	But I think the algorithm will run a tad faster if all elements are
	 *	in order of increasing image height.  That way we get to the
	 *	meaningful constraints first.
	 */
	verify_gen_list(gen_list, num_matrix_pairs);

	/*
	 *	Initialize *basepoint_moved to FALSE.
	 *	If we later move the basepoint, we'll set *basepoint_moved to TRUE.
	 */
	*basepoint_moved = FALSE;

	/*
	 *	Keep track of the total distance we've moved the basepoint.
	 *	We don't want to go too far without recomputing the Dirichlet
	 *	domain to get a fresh set of group elements.
	 */
	total_distance_moved = 0.0;

	/*
	 *	Some ad hoc code for handling low precision situations
	 *	needs to keep track of the prev_distance_moved.
	 */
	prev_distance_moved = DBL_MAX;

	/*
	 *	We don't want to bother the user with the saddle query
	 *	more than once.  We initialize saddle_query_given to FALSE,
	 *	and then set it to TRUE if and when the query takes place.
	 */
	saddle_query_given = FALSE;

	/*
	 *	We want to move the basepoint to a local maximum of the injectivity
	 *	radius function.  Solve the linear approximation to this problem,
	 *	and repeat until a solution is found.
	 */
	do
	{
		/*
		 *	Set the objective function using the first nonidentity matrix
		 *	on the list.  If the derivative of the objective function is
		 *	nonzero, proceed normally.  Otherwise ask the user how s/he
		 *	would like to proceed.
		 */

		if (set_objective_function(objective_function, gen_list->begin.next->next) == func_OK)
		{
			/*
			 *	Allocate space for the Constraints.
			 *	There'll be num_matrix_pairs - 2 regular constraints
			 *	(one for each MatrixPair, excluding the identity and the
			 *	MatrixPair used to define the objective function),
			 *	preceded by three constraints which limit the step size
			 *	to MAX_STEP_SIZE.
			 */
			num_constraints = (num_matrix_pairs - 2) + 3;
			constraints = NEW_ARRAY(num_constraints, Constraint);

			/*
			 *	Set up the three step size constraints.
			 */
			step_size_constraints(constraints, objective_function);

			/*
			 *	Set up the regular constraints.
			 */
			regular_constraints(constraints, gen_list, objective_function, &may_be_saddle_point);

			/*
			 *	If we're not near an apparent saddle point,
			 *	do the linear programming.
			 */
			if (may_be_saddle_point == FALSE)
				linear_programming(objective_function, num_constraints, constraints, solution);
			/*
			 *	Otherwise ask the user whether s/he would like
			 *	to continue on normally or stop here.
			 */
			else
			{
				switch (interactivity)
				{
					case Dirichlet_interactive:
						if (saddle_query_given == FALSE)
						{
							choice = uQuery(	saddle_message,
												num_saddle_responses,
												saddle_responses,
												saddle_default);
							saddle_query_given = TRUE;
						}
						else
							choice = 0;	/* continue on */
						break;

					case Dirichlet_stop_here:
						choice = 1;	/*  stop here  */
						break;

					case Dirichlet_keep_going:
						choice = 0;	/* continue on */
						break;
				}

				switch (choice)
				{
					case 0:
						/*
						 *	Continue on normally.
						 */
						linear_programming(objective_function, num_constraints, constraints, solution);
						break;

					case 1:
						/*
						 *	Stop here, set *basepoint_moved to FALSE
						 *	to force an exit from the loop, and look at
						 *	the Dirichlet domain.
						 */
						copy3(solution, zero_solution);
						*basepoint_moved = FALSE;
						break;
				}
			}

			/*
			 *	Free the Constraint array.
			 */
			my_free(constraints);
		}

		else
		{
			/*
			 *	The derivative of the objective function is zero.
			 *
			 *	Ask the user whether to use this basepoint, or move on in
			 *	search of a local maximum of the injectivity radius.
			 */
			switch (interactivity)
			{
				case Dirichlet_interactive:
					choice = uQuery(	zero_deriv_message,
										num_zero_deriv_responses,
										zero_deriv_responses,
										zero_deriv_default);
					break;

				case Dirichlet_stop_here:
					choice = 1;	/*  stop here  */
					break;

				case Dirichlet_keep_going:
					choice = 0;	/* continue on */
					break;
			}

			switch (choice)
			{
				case 0:
					/*
					 *	Displace the basepoint and continue on.
					 */
					copy3(solution, small_displacement);
					break;

				case 1:
					/*
					 *	We want to stay at this point, so set the solution
					 *	to (0, 0, 0), and set *basepoint_moved to FALSE
					 *	to force an exit from the loop.
					 */
					copy3(solution, zero_solution);
					*basepoint_moved = FALSE;
					break;
			}
		}

		/*
		 *	Use the solution to conjugate the MatrixPairs.
		 */
		conjugate_matrices(gen_list, solution);

		/*
		 *	Resort the gen_list according to increasing image height.
		 */
		sort_gen_list(gen_list, num_matrix_pairs);

		/*
		 *	How far was the basepoint moved this time?
		 */
		distance_moved = length3(solution);

		/*
		 *	What is the total distance we've moved the basepoint?
		 */
		total_distance_moved += distance_moved;

		/*
		 *	If the basepoint moved any meaningful distance,
		 *	set *basepoint_moved to TRUE.
		 */
		if (distance_moved > BASEPOINT_EPSILON)
		{
			*basepoint_moved = TRUE;
			/*
			 *	If we move too far from the original basepoint, we should
			 *	recompute the Dirichlet domain to get a fresh set of
			 *	group elements.  Otherwise we keep going.
			 */
			keep_going = (total_distance_moved < MAX_TOTAL_DISTANCE);
		}
		else
			keep_going = FALSE;

		/*
		 *	The preceding code works great when the constraints are
		 *	either in general position, or are given to moderately high
		 *	precision.  But for low precision, non general position
		 *	constraints (e.g. for an 8-component circular chain with no
		 *	twist), the algorithm can knock around forever making
		 *	changes on the order of 1e-9.  The following code lets the
		 *	algorithm terminate in those cases.
		 */
		if (prev_distance_moved < BIG_BASEPOINT_EPSILON
		 &&      distance_moved < BIG_BASEPOINT_EPSILON)
		{
			/*
			 *	For sure we don't want to keep going after making
			 *	two fairly small changes in a row.
			 */
			keep_going = FALSE;
			/*
			 *	If the total_distance_moved is less than BIG_BASEPOINT_EPSILON,
			 *	then we want to set *basepoint_moved to FALSE to prevent
			 *	recomputation of the Dirichlet domain.  Note that we still
			 *	allow the possibility that *basepoint_moved is TRUE even when
			 *	the total_distance_moved is greater than BIG_BASEPOINT_EPSILON,
			 *	as could happen if preceding code artificially set *basepoint_moved
			 *	to FALSE to force an exit from the loop.
			 */
			if (total_distance_moved < BIG_BASEPOINT_EPSILON)
				*basepoint_moved = FALSE;
		}
		prev_distance_moved = distance_moved;

	} while (keep_going == TRUE);
}
Exemple #9
0
int
MeshEdgeElementTable::calcLineIntersections(int elem_index, short elem_dir,
                                            Point3& lstart, Point3& ldir, Point3* isec_points)
{
  meshElementCode elem_code = getElementCode(elem_index);

  if (elem_code <  MEC_202 || elem_code >= 303)
    return 0;

  const int* nodeIds = getNodeIds(elem_index, elem_dir);

  Point3& p0 = meshNodes[nodeIds[0]];
  Point3& p1 = meshNodes[nodeIds[1]];
  
  Point3& normal = normals[elem_index];
  if (elem_dir == -1)
    scalarmult(-1, normal, normal);

  // Check end-point cases
  if ( samepoint(p0, lstart) ){
    copy3(p0, *isec_points);
    return 1;
  }
  if ( samepoint(p1, lstart) ){
    copy3(p1, *isec_points);
    return 1;
  }


  Point3 edge_dir, l_delta0, tmp;
 
  // Edge direction vector (normalized)
  edge_dir[0] = normal[1];
  edge_dir[1] = -1 * normal[0];
  edge_dir[2] = 0.0;

  // Edge length
  diff3(p1, p0, tmp);
  double edge_len = dot3(edge_dir, tmp);

  // Vector l_delta0 = lstart - p0
  diff3(lstart, p0, l_delta0);

  // Check that intersection is "within" the edge
  // project the intersection point to the edge
  double t = dot3(edge_dir, l_delta0);
  if ( isLess(t, 0.0) ||
       isGreater(t, edge_len)
     )
    return 0;

  // Check that intersection distance from the edge is ok
  // project intersection point to the edge normal
  double d = dot3(normal, l_delta0);
  if (d < 0)
    d *= -1;
  if ( isGreater(d, MeshEdgeElementTable::pickingTolerance) )
    return 0;

  // Intersection point is: p0 + t * (p1 - p0)
  scalarmult(t, edge_dir, tmp);
  add3(p0, tmp, *isec_points);

  return 1;
}
Exemple #10
0
// NOTE: This should work for all triangle elments (303 - 306), but only
// if mid-edge and middle nodes are after "corner" nodes in the node list!
// Return nof intersections
//
int
MeshFaceElementTable::calcTriangleLineIntersections(int elem_index, short direction,
                                                    Point3& lstart, Point3& ldir, Point3* isec_points)
{
  // Ccw ordered nodes (if elem_dir is -1, it is from the parent2
  // and nodes are cw oriented and must me reordered
  Point3& p0 = meshNodes[nodeIds[elem_index][0]];
  Point3& p1 = meshNodes[nodeIds[elem_index][1]];
  Point3& p2 = meshNodes[nodeIds[elem_index][2]];
  Point3& normal = normals[elem_index];

  static Point3* points[3];

  points[0] = (direction >= 0)? &p0 : &p1;
  points[1] = (direction >= 0)? &p1 : &p0;
  points[2] = &p2;

#if 0
  // If element is looking into wrong direction
  //
  // NOTE: This makes picking much faster, so wew have to use it (unless some better
  // method is found), although it means that elements cannot be selected from 'inside',
  // which would be quite convenient in some cases!
  //
  if ( direction == 1 ) {
    if ( !isLess(dot3(normal, ldir), 0) ) {
      return 0;
    }

  } else if ( direction == -1 ) {
    if ( !isGreater(dot3(normal, ldir), 0) ) {
      return 0;
    }
  }
#endif

  // Plane equation for the normal and a point in the plane is;
  // (r) dot (normal) = (r0) dot (normal) = d
  // So for the form Ax + By + Cz + D = 0, we have
  // A = normal[0], B = normal[1], C = normal[2], D = -d

  double D = -1 * dot3(p0, normal);

  double numer = dot3(normal, lstart) + D;
  double denom = dot3(normal, ldir);

  double t;

  // Intersection
  if (denom != 0) {
    t = - numer / denom;

  // Line is on the plane
  } else if (numer == 0) {
    t = 0.0;

  // Line is parallel,but not in the plane
  } else {
    return 0;
  }


  //-Calc intersection point from the line equation
  Point3 tmp;
  scalarmult(t, ldir, tmp);
  Point3 isec_point;
  add3(lstart, tmp, isec_point);

  // Finally check if intersection point
  // is inside the element (triangle)
  if ( pointInsideTriangle(isec_point, points, centers[elem_index], rSquares[elem_index]) ) {

    copy3(isec_point, *isec_points);
    return 1;

  } else {
    return 0;
  }

}
Exemple #11
0
/*
 * Copies the emissivity from a light to an output vector.
 * Param: light  The light to copy emissivity from.
 * Param: value  The output vector.
 */
void default_getemiss(light_t* light, double* value)
{
    copy3(light->emissivity, value);
}