当前位置: 首页>>代码示例>>C++>>正文


C++ Diff函数代码示例

本文整理汇总了C++中Diff函数的典型用法代码示例。如果您正苦于以下问题:C++ Diff函数的具体用法?C++ Diff怎么用?C++ Diff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Diff函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main (void)
{
  struct MyTime first_time = { 10, 501};
  struct MyTime second_time = { 2, 500};
  struct MyTime min_time = { 99999, 999999};
  struct MyTime max_time = { 0, 0};
  struct MyTime diff_time = { 0, 0};
  
  print_time ("First:", first_time);
  print_time ("Second:", second_time);

  print_time ("Min:", Min(first_time,second_time));
  print_time ("Max:", Max(first_time,second_time));
  print_time ("Diff:", Diff(second_time, first_time));
  
  getCurrentMyTime(& first_time);
  sleep (10);
  getCurrentMyTime(& second_time);
  
  print_time ("Average:", Avg(Diff(second_time,first_time), 10));
  
   diff_time.SEC = first_time.SEC-second_time.SEC;
   diff_time.FRAC_SEC = first_time.FRAC_SEC-second_time.FRAC_SEC;
    
  /* If the substraction results in negative answer */

   if(diff_time.FRAC_SEC < 0)
    {
        diff_time.FRAC_SEC = SCALE + diff_time.FRAC_SEC;
            if(diff_time.SEC > 0 )
               diff_time.SEC = diff_time.SEC-1;
            else
               diff_time.FRAC_SEC*=-1;
    }

   if(diff_time.FRAC_SEC < min_time.FRAC_SEC)
    min_time.FRAC_SEC = diff_time.FRAC_SEC;
  
   if(diff_time.FRAC_SEC > max_time.FRAC_SEC)
    max_time.FRAC_SEC = diff_time.FRAC_SEC;

   if(diff_time.SEC < min_time.SEC)
    min_time.SEC = diff_time.SEC;
  
   if(diff_time.SEC > max_time.SEC)
    max_time.SEC = diff_time.SEC;

   print_time("Old Min:", min_time);
   print_time("Old Max:", max_time);

  return 0;
}
开发者ID:IMCG,项目名称:cpptruths,代码行数:52,代码来源:min_max_time.c

示例2: getDiffs

Diffs Node::getDiffs (const RobotState& last, const RobotState& current)
{
  Diffs diffs;
  const ros::Time now = ros::Time::now();;
  
  // Use the fact that JointState is empty iff this is the first time around
  if (last.isEmpty() || now >= last_keyframe_+keyframe_interval_)
  {
    last_keyframe_ = now;
    if (last.isEmpty())
      cerr << "Last is empty, so using all diffs" << endl;
    else
      cerr << "Keyframe interval elapsed, so saving entire joint state" << endl;
    diffs.is_keyframe = true;
    for (size_t i=0; i<current.joint_state->position.size(); i++)
    {
      diffs.new_joint_states.push_back(Diff(i, current.joint_state->position[i]));
    }
    diffs.pose_diff = true;
    diffs.new_pose = current.pose;
  }
  else
  {
    for (size_t i=0; i<current.joint_state->position.size(); i++)
    {
      if (fabs(current.joint_state->position[i]-
               last.joint_state->position[i])>distance_threshold_ &&
          !joint_ignored_[i])
      {
        cerr << "Joint " << current.joint_state->name[i] << " value " <<
          current.joint_state->position[i] << " differs from " <<
          last.joint_state->position[i] << endl;
        diffs.new_joint_states.push_back(Diff(i, current.joint_state->position[i]));
      }
    }

    if ((current.pose.get() && !last.pose.get()) ||
        (!current.pose.get() && last.pose.get()) ||
        ((current.pose.get() && last.pose.get() &&
          poseDistance(*current.pose, *last.pose)>distance_threshold_)))
    {
      cerr << "Current pose: " << (bool)current.pose.get() << "; last pose: "
           << (bool)last.pose.get() << endl;
      diffs.pose_diff = true;
      diffs.new_pose = current.pose;
    }
  }
  return diffs;
}
开发者ID:bhaskara,项目名称:ros_logging,代码行数:49,代码来源:robot_state_logger.cpp

示例3: __ASSERT

EXPORT_C TAny* RDbRow::SetColumnWidthL(TDbColNo aColNo,TInt aWidth)
// set the width for column aCol to Width
// add extra NULL columns to buffer as required
// return pointer to data for that column
	{
	__ASSERT(aColNo>0);
	TDbCell* pC=Column(--aColNo);
	if (pC==0)
		{		// add extra NULL columns to buffer
		if (aWidth==0)
			return 0;	// setting to NULL, don't bother padding
		TInt cFill=(aColNo-iColumn)*sizeof(TInt);
		ExtendL(cFill+TDbCell::Size(aWidth));
		pC=iCell;
		Mem::FillZ(pC,cFill);
		pC=PtrAdd(pC,cFill);		// set cache
		SetCache(pC,aColNo);
		}
	else
		{
		TInt adjust=TDbCell::Size(aWidth)-pC->Size();	// how much to add
		if (adjust!=0)
			{
			ExtendL(adjust);
			pC=iCell;		// may have moved in extension
			TDbCell* pNext=pC->Next();
			TDbCell* pAdjust=PtrAdd(pNext,adjust);
			Mem::Move(pAdjust,pNext,Diff(pAdjust,iLast));
			}
		}
	pC->SetLength(aWidth);
	return pC->Data();
	}
开发者ID:cdaffara,项目名称:symbiandump-os2,代码行数:33,代码来源:UD_ROW.CPP

示例4: getVSpherePos

void Camera::rotate( float x, float y )
{
    Vector po = getVSpherePos((float) m_LastMouseX, m_LastMouseY);
    Vector pn = getVSpherePos(x, y);
    
    if((po-pn).lengthSquared() < 0.0001f )
        return;
    
    float cosangle = po.dot(pn);
    if(cosangle>1.0f) cosangle=1.0f;
    if(cosangle<-1.0f) cosangle=-1.0f;
    
    const float angle = acos(cosangle);
    Vector RotAxis = pn.cross(po);
    RotAxis.normalize();
    
    
    //Vector Diff = m_Position-m_Target;
    Vector Diff(0,0,(m_Position-m_Target).length());
    
    Vector RotDiff = rotateAxisAngle(Diff, RotAxis, angle);
    
    Vector cdir = m_Target-m_Position;
    cdir.normalize();
    Vector cup = m_Up;
    Vector cright = cdir.cross(cup);
    cright.normalize();
    cup = cright.cross(cdir);

    Vector RotDiffW;
    RotDiffW.X = cright.X * RotDiff.X + cup.X * RotDiff.Y +  -cdir.X * RotDiff.Z;
    RotDiffW.Y = cright.Y * RotDiff.X + cup.Y * RotDiff.Y +  -cdir.Y * RotDiff.Z;
    RotDiffW.Z = cright.Z * RotDiff.X + cup.Z * RotDiff.Y +  -cdir.Z * RotDiff.Z;
    m_Rotation = RotDiffW - (m_Position-m_Target);
}
开发者ID:flair2005,项目名称:3D-room-planner,代码行数:35,代码来源:Camera.cpp

示例5: diff_to_index

 Diff diff_to_index(Repository const & repo, Tree & t, git_diff_options const & opts)
 {
     git_diff * diff;
     auto op_res = git_diff_tree_to_index(&diff, repo.ptr(), t.ptr(), nullptr, &opts);
     assert(op_res == 0);
     return Diff(diff);
 }
开发者ID:kluete,项目名称:libgit2cpp,代码行数:7,代码来源:diff.cpp

示例6: assert

bool DiffWrapperBase<T, TDiff>::GetElementDiffs(
    google::protobuf::RepeatedPtrField<ElementDiff> *dst,
    const google::protobuf::RepeatedPtrField<Element> &old_elements,
    const google::protobuf::RepeatedPtrField<Element> &new_elements) {
  bool differs = false;
  assert(dst != nullptr);
  int i = 0;
  int j = 0;
  while (i < old_elements.size() && j < new_elements.size()) {
    const Element &old_element = old_elements.Get(i);
    const Element &new_element = new_elements.Get(i);

    if (Diff(old_element, new_element)) {
      ElementDiff *diff = dst->Add();
      Element *old_elementp = nullptr;
      Element *new_elementp = nullptr;
      if (!diff || !(old_elementp = diff->mutable_old()) ||
          !(new_elementp = diff->mutable_new_())) {
        llvm::errs() << "Failed to add diff element\n";
        ::exit(1);
      }
      *old_elementp = old_element;
      *new_elementp = new_element;
      diff->set_index(i);
      differs = true;
    }
    i++;
    j++;
  }
  if (old_elements.size() != new_elements.size()) {
    GetExtraElementDiffs(dst, i, j, old_elements, new_elements);
    differs = true;
  }
  return differs;
}
开发者ID:xeronith,项目名称:platform_development,代码行数:35,代码来源:abi_diff_wrappers.cpp

示例7: diff_index_to_workdir

 Diff diff_index_to_workdir(Repository const & repo, git_diff_options const & opts)
 {
     git_diff * diff;
     auto op_res = git_diff_index_to_workdir(&diff, repo.ptr(), nullptr, &opts);
     assert(op_res == 0);
     return Diff(diff);
 }
开发者ID:kluete,项目名称:libgit2cpp,代码行数:7,代码来源:diff.cpp

示例8: Diff

 Matrix<double,ndim,1> Edge::jacobian(const double & t) const
 {
   GeoPoint & a = *M_points[0];
   GeoPoint & b = *M_points[1];
   GeoPoint Diff(b-a);
   return Matrix<double,ndim,1>(Diff[0],Diff[1]);
 }
开发者ID:10341074,项目名称:pacs,代码行数:7,代码来源:femMesh.cpp

示例9: test_with_matvec_reduced_maps

// B here is the "reduced" matrix.  Square matrices w/ Row=Domain=Range only.
double test_with_matvec_reduced_maps(const Epetra_CrsMatrix &A, const Epetra_CrsMatrix &B, const Epetra_Map & Bfullmap){
  const Epetra_Map & Amap  = A.DomainMap();
  Epetra_Vector Xa(Amap), Ya(Amap), Diff(Amap);
  const Epetra_Map *Bmap  = Bfullmap.NumMyElements() > 0 ? &B.DomainMap() : 0;
  Epetra_Vector *Xb = Bmap ? new Epetra_Vector(*Bmap) : 0;
  Epetra_Vector *Yb = Bmap ? new Epetra_Vector(*Bmap) : 0;

  Epetra_Vector Xb_alias(View,Bfullmap, Bmap ? Xb->Values(): 0);
  Epetra_Vector Yb_alias(View,Bfullmap, Bmap ? Yb->Values(): 0);

  Epetra_Import Ximport(Bfullmap,Amap);

  // Set the input vector
  Xa.SetSeed(24601);
  Xa.Random();
  Xb_alias.Import(Xa,Ximport,Insert);

  // Do the multiplies
  A.Apply(Xa,Ya);
  if(Bmap) B.Apply(*Xb,*Yb);

  // Check solution
  Epetra_Import Yimport(Amap,Bfullmap);
  Diff.Import(Yb_alias,Yimport,Insert);


  Diff.Update(-1.0,Ya,1.0);
  double norm;
  Diff.Norm2(&norm);

  delete Xb; delete Yb;
  return norm;
}
开发者ID:KineticTheory,项目名称:Trilinos,代码行数:34,代码来源:cxx_main.cpp

示例10: diff

 Diff diff(Repository const & repo, Tree & a, Tree & b, git_diff_options const & opts)
 {
     git_diff * diff;
     auto op_res = git_diff_tree_to_tree(&diff, repo.ptr(), a.ptr(), b.ptr(), &opts);
     assert(op_res == 0);
     return Diff(diff);
 }
开发者ID:kluete,项目名称:libgit2cpp,代码行数:7,代码来源:diff.cpp

示例11: Diff

void DiffSideBySidePanel::OnVertical(wxRibbonButtonBarEvent& event)
{
    m_splitter->Unsplit();
    m_splitter->SplitVertically(m_splitterPageLeft, m_splitterPageRight);
    m_config.SetViewMode(DiffConfig::kViewVerticalSplit);
    Diff();
}
开发者ID:MichalBliznak,项目名称:codelite,代码行数:7,代码来源:DiffSideBySidePanel.cpp

示例12: Diff

void DiffSideBySidePanel::OnHorizontal(wxCommandEvent& event)
{
    m_splitter->Unsplit();
    m_splitter->SplitHorizontally(m_splitterPageLeft, m_splitterPageRight);
    m_config.SetViewMode(DiffConfig::kViewHorizontalSplit);
    Diff();
}
开发者ID:GaganJotSingh,项目名称:codelite,代码行数:7,代码来源:DiffSideBySidePanel.cpp

示例13: main

int main(){
    int len = 3000;
    gsl_vector *v = gsl_vector_alloc(len);
    for (double i=0; i< len; i++) gsl_vector_set(v, i, 1./(i+1));
    double square;
    gsl_blas_ddot(v, v, &square);
    printf("1 + (1/2)^2 + (1/3)^2 + ...= %g\n", square);

    double pi_over_six = gsl_pow_2(M_PI)/6.;
    Diff(square, pi_over_six);

    /* Now using apop_dot, in a few forms.
       First, vector-as-data dot itself.
       If one of the inputs is a vector,
       apop_dot puts the output in a vector-as-data:*/
    apop_data *v_as_data = &(apop_data){.vector=v};
    apop_data *vdotv = apop_dot(v_as_data, v_as_data);
    Diff(gsl_vector_get(vdotv->vector, 0), pi_over_six);

    /* Wrap matrix in an apop_data set. */
    gsl_matrix *v_as_matrix = apop_vector_to_matrix(v);
    apop_data dm = (apop_data){.matrix=v_as_matrix};

    // (1 X len) vector dot (len X 1) matrix --- produce a scalar (one item vector).
    apop_data *mdotv = apop_dot(v_as_data, &dm);
    double scalarval = apop_data_get(mdotv);
    Diff(scalarval, pi_over_six);

    //(len X 1) dot (len X 1) --- bad dimensions.
    apop_opts.verbose=-1; //don't print an error.
    apop_data *mdotv2 = apop_dot(&dm, v_as_data);
    apop_opts.verbose=0; //back to safety.
    assert(mdotv2->error);

    // If we want (len X 1) dot (1 X len) --> (len X len),
    // use apop_vector_to_matrix.
    apop_data dmr = (apop_data){.matrix=apop_vector_to_matrix(v, .row_col='r')};
    apop_data *product_matrix = apop_dot(&dm, &dmr);
    //The trace is the sum of squares:
    gsl_vector_view trace = gsl_matrix_diagonal(product_matrix->matrix);
    double tracesum = apop_sum(&trace.vector);
    Diff(tracesum, pi_over_six);

    apop_data_free(product_matrix);
    gsl_matrix_free(dmr.matrix);
}
开发者ID:b-k,项目名称:apophenia,代码行数:46,代码来源:dot_products.c

示例14: Find

// Find the SnapPoint nearest to time t
int SnapManager::Find(double t)
{
   int len = (int)mSnapPoints->GetCount();
   int index = Find(t, 0, len);

   // At this point, either index is the closest, or the next one
   // to the right is.  Keep moving to the right until we get a
   // different value
   int next = index + 1;
   while(next+1 < len && Get(next) == Get(index))
      next++;

   // Now return whichever one is closer to time t
   if (next < len && Diff(t, next) < Diff(t, index))
      return next;
   else
      return index;
}
开发者ID:Cactuslegs,项目名称:audacity-of-nope,代码行数:19,代码来源:Snap.cpp

示例15: main

int main(int argc, char *argv[])
{
  Value I(1), m(4);
  for(int a = 0; a < 1000; a++)
    m = Diff (I, m);

  if (!(m / 4 == I))
    abort ();
  return 0;
}
开发者ID:MaxKellermann,项目名称:gcc,代码行数:10,代码来源:pr33604.C


注:本文中的Diff函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。