當前位置: 首頁>>代碼示例>>C++>>正文


C++ std::ceil方法代碼示例

本文整理匯總了C++中std::ceil方法的典型用法代碼示例。如果您正苦於以下問題:C++ std::ceil方法的具體用法?C++ std::ceil怎麽用?C++ std::ceil使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在std的用法示例。


在下文中一共展示了std::ceil方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: TEST

TEST(AgradFwdCeil,FvarFvarDouble) {
  using stan::math::fvar;
  using std::ceil;

  fvar<fvar<double> > x;
  x.val_.val_ = 1.5;
  x.val_.d_ = 2.0;

  fvar<fvar<double> > a = ceil(x);

  EXPECT_FLOAT_EQ(ceil(1.5), a.val_.val_);
  EXPECT_FLOAT_EQ(0, a.val_.d_);
  EXPECT_FLOAT_EQ(0, a.d_.val_);
  EXPECT_FLOAT_EQ(0, a.d_.d_);

  fvar<fvar<double> > y;
  y.val_.val_ = 1.5;
  y.d_.val_ = 2.0;

  a = ceil(y);
  EXPECT_FLOAT_EQ(ceil(1.5), a.val_.val_);
  EXPECT_FLOAT_EQ(0, a.val_.d_);
  EXPECT_FLOAT_EQ(0, a.d_.val_);
  EXPECT_FLOAT_EQ(0, a.d_.d_);
}
開發者ID:aseyboldt,項目名稱:math,代碼行數:25,代碼來源:ceil_test.cpp

示例2: ComputeMaxChildIndex

size_t DfpnSolver::ComputeMaxChildIndex(const std::vector<DfpnData>&
                                        childrenData) const
{
    HexAssert(!childrenData.empty());

    int numNonLosingChildren = 0;
    for (size_t i = 0; i < childrenData.size(); ++i)
        if (!childrenData[i].m_bounds.IsWinning())
            ++numNonLosingChildren;
    if (numNonLosingChildren < 2)
        return childrenData.size();

    // this needs experimenting!
    int childrenToLookAt = WideningBase() + (int) ceil(numNonLosingChildren
                                                       * WideningFactor());
    // Must examine at least two children when have two or more live,
    // since otherwise delta2 will be set to infinity in SelectChild.
    HexAssert(childrenToLookAt >= 2);

    int numNonLosingSeen = 0;
    for (size_t i = 0; i < childrenData.size(); ++i)
    {
        if (!childrenData[i].m_bounds.IsWinning())
            if (++numNonLosingSeen == childrenToLookAt)
                return i + 1;
    }
    return childrenData.size();
}
開發者ID:zahybnaya,項目名稱:generic-best-first-bandit,代碼行數:28,代碼來源:DfpnSolver.cpp

示例3: run

 static inline int run()
 {
   using std::ceil;
   using std::log;
   return cast<double,int>(ceil(-log(std::numeric_limits<double>::epsilon())
                                / log(10.0)));
 }
開發者ID:HerraHuu,項目名稱:stan,代碼行數:7,代碼來源:Eigen_NumTraits.hpp

示例4: PrimeFactors

std::vector<int64_t>* PrimeFactors(const int64_t NUMBER) {
    using std::ceil;
    using std::sqrt;
    using std::vector;
    // We only need to test up to the square root of the number, if this fails
    // we know it's prime
    const int64_t LIMIT = static_cast<int64_t>(ceil(sqrt(NUMBER)));
    vector<bool> const * const PRIMES = PrimeSieve(LIMIT);

    int64_t current_number = NUMBER;
    vector<int64_t>* prime_factors = new vector<int64_t>();
    // We try dividing through by primes until our number reaches 1, then
    // return the list of primes
    for (int64_t i = 0; i < LIMIT; ++i) {
        if (PRIMES->at(i) && current_number % i == 0) {  // Is Prime
            do {
                current_number = current_number / i;
                prime_factors->push_back(i);
                if (current_number <= 1) {
                    return prime_factors;
                }
            } while(current_number % i == 0);
        }
    }
    // Should return from the loop
    return NULL;
}
開發者ID:agude,項目名稱:Project-Euler,代碼行數:27,代碼來源:alexlib.cpp

示例5: nearbyint

      static source_type nearbyint ( argument_type s )
      {
#if !defined(BOOST_NO_STDC_NAMESPACE)
          using std::ceil ;
#endif
          return Double( ceil(s.v) );
      }
開發者ID:0xDEC0DE8,項目名稱:mcsema,代碼行數:7,代碼來源:numeric_cast_traits_test.cpp

示例6: calculateCharge

// Calculate parking charge for a customer
// First three hours are charged $2.00, each hour for next three hours are charged $0.50, and
// 24-hour period charge $10.00
double calculateCharge( double parkingHours )
{
	double charge = 0.0; // parking charge in $
	
	if (parkingHours < 3.0) { // charge for first three parking hours
		charge = 2.00;
	}
	else if (parkingHours >= 3.0 && parkingHours < 6.0) // from 3 to 6 hours period
	{
		const double 	chargePerHour = 0.50; 	// each hour is charged $0.50
		const double 	baseCharge = 2.00;		// base charge for first three hours
		const int 		baseHour = 3;			// base hour when different charge is used

		double differ;	// time difference between parking hours and base hour
		differ = parkingHours - baseHour; // widening! (int baseHours -> double baseHours)
		
		// Difference must be round up for appropriate hour charge.
		int chargeFactor; 
		chargeFactor = ceil( differ );
		
		// For each hour, additional charge is added to base charge (for first three hours i.e. $2.00)
		// 				
		// 				charge = baseCharge + chargeFactor * chargePerHour
		//
		charge = baseCharge + chargeFactor * chargePerHour;
	} 
	else { // 24-hour period
		double chargePerDay = 10.00; // 24-hour period charge
		charge = chargePerDay;
	}

	return charge;
}
開發者ID:Grayninja,項目名稱:General,代碼行數:36,代碼來源:main.cpp

示例7: nearbyint

  static source_type nearbyint ( argument_type s )
  {
    // Algorithm contributed by Guillaume Melquiond

#if !defined(BOOST_NO_STDC_NAMESPACE)
    using std::floor ;
    using std::ceil  ;
#endif

    // only works inside the range not at the boundaries
    S prev = floor(s);
    S next = ceil(s);

    S rt = (s - prev) - (next - s); // remainder type

    S const zero(0.0);
    S const two(2.0);

    if ( rt < zero )
      return prev;
    else if ( rt > zero )
      return next;
    else
    {
      bool is_prev_even = two * floor(prev / two) == prev ;
      return ( is_prev_even ? prev : next ) ;
    }
  }
開發者ID:EricAlex,項目名稱:PDAL,代碼行數:28,代碼來源:converter_policies.hpp

示例8: createInitialDistribution

void Stippler::createInitialDistribution() {
	using std::ceil;

	// find initial distribution
	boost::mt19937 rng;
	boost::uniform_01<boost::mt19937, float> generator( rng );

	float w = (float)(image.getWidth() - 1), h = (float)(image.getHeight() - 1);
	float xC, yC;

	for ( unsigned int i = 0; i < parameters.points; ) {
		xC = generator() * w;
		yC = generator() * h;

		//printf("%f //", generator());
		//printf("%f ::  ", ceil(generator()*255.0));
		//printf("%f \n", image.getIntensity(xC, yC));
		// do a nearest neighbour search on the vertices
		if ( ceil(generator() * 255.0f) <= image.getIntensity( xC, yC ) ) { //white is zero.
			//printf("aaaaaaa\n");
			vertsX[i] = xC;
			vertsY[i] = yC;
			radii[i] = 0.0f;

			i++;
		}
	}
}
開發者ID:yunhkim,項目名稱:stippling,代碼行數:28,代碼來源:stippler.cpp

示例9: PrimeSieve

std::vector<bool>* PrimeSieve(const int64_t& LENGTH) {
    using std::ceil;
    using std::fill;
    using std::sqrt;
    using std::vector;
    // Fill with true
    vector<bool>* primes = new vector<bool>(LENGTH);
    fill(primes->begin(), primes->end(), true);

    // 0, 1 are not prime
    if (LENGTH >= 2) {
        primes->at(0) = primes->at(1) = false;
    } else if (LENGTH < 1) {
        return NULL;
    } else {
        primes->at(0) = false;
    }

    // Sieve
    for (int64_t i = 2; i < ceil(sqrt(LENGTH)); ++i) {
        if (primes->at(i)) {
            for (int64_t j = i * i; j < LENGTH; j += i) {
                primes->at(j) = false;
            }
        }
    }
    return primes;
}
開發者ID:agude,項目名稱:Project-Euler,代碼行數:28,代碼來源:alexlib.cpp

示例10: start

void Ave::start(Context &context) {
    using std::ceil;

    geoSegment = &context.getSegment(Constants::SEGMENT_GEO);
    sourceSegment = &context.getSegment(Constants::SEGMENT_SYN_COLLOCATED);

    getAuxdataProvider(context, Constants::AUX_ID_SYCP).getUByte("ave_square", averagingFactor);

    const Grid &sourceGrid = sourceSegment->getGrid();
    //const size_t sizeL = sourceGrid.getSizeL() / averagingFactor;
    const size_t sizeM = ceil(sourceGrid.getSizeM() / double(averagingFactor));
    const size_t sizeK = sourceGrid.getSizeK();
    const size_t maxL = ceil((sourceGrid.getMaxL() - sourceGrid.getMinL() + 1) / double(averagingFactor)) - 1;
    targetSegment = &context.addSwathSegment(Constants::SEGMENT_SYN_AVERAGED, maxL + 1, sizeM, sizeK, 0, maxL);

    addVariables(context);
}
開發者ID:bcdev,項目名稱:s3-synergy,代碼行數:17,代碼來源:Ave.cpp

示例11: GetEigenvalueRange

Matrix::pVector SymMatrix::GetEigenvalueRange(int indexOfLow, int indexOfHigh)
{
   assert(indexOfLow >= 0);
   assert(indexOfLow <= indexOfHigh);
   assert(indexOfHigh < GetSize());
     //lapack parameter list
   char jobz = 'N';//compute eigenvalues only
   char range = 'I';//all eigenvalues will be found
   char uplo = 'U';//upper triangle of A is stored
   int n = GetSize();
   int lda = GetSize();
   double vl, vu;//no referenced when range = 'A' or 'I'
   int il = indexOfLow + 1, iu = indexOfHigh + 1;//1<= il <= iu <= N
   double abstol = 0;//absolute error tolerance for the eigenvalues
   int m;//the total number of eigenvalues found
   vector<double> w(n);//the first m elements contain the selected
                       //eigenvalues in ascending order
   vector<double> z(n*n);//not referenced when jobz = 'N', but this
			 //reserved space
   int ldz = n;//the leading dimension of the array z
   vector<int> isuppz(2 * n);//the support of the eigenvectors in Z
   int info;
   //got the optimal size of workspace
   int lwork = -1;//the dimension of the array work
   int liwork = -1;//the dimension of the array iwork
   vector<double> work(26 * n);//workspace
   vector<int> iwork(10 * n);//workspace
   //query the optimal size
   dsyevr_(&jobz, &range, &uplo, &n, GetData(), &lda, &vl, &vu, &il, &iu, &abstol,
	   &m, w.data(), z.data(), &ldz, isuppz.data(), work.data(), &lwork,
	   iwork.data(), &liwork, &info);
   if(info == 0)
   {//succeed
      lwork = ceil(work[0]);
      liwork = iwork[0];
      //reallocate
      work.resize(lwork);
      iwork.resize(liwork);
   }
   else
   {
      return pVector();
   }
   //compute
   dsyevr_(&jobz, &range, &uplo, &n, GetData(), &lda, &vl, &vu, &il, &iu, &abstol,
	   &m, w.data(), z.data(), &ldz, isuppz.data(), work.data(), &lwork,
	   iwork.data(), &liwork, &info);
   if(info == 0)
   {
      pVector result(new Vector());
      result->assign(w.begin(), w.begin() + (indexOfHigh - indexOfLow) + 1);
      return result;
   }
   else
      return pVector();
}
開發者ID:python27,項目名稱:learn_tech,代碼行數:56,代碼來源:sym_matrix.cpp

示例12: rng_dweibull

inline double rng_dweibull(double q, double beta,
                           bool& throw_warning) {
  if (ISNAN(q) || ISNAN(beta) || q <= 0.0 || q >= 1.0 ||
      beta <= 0.0) {
    throw_warning = true;
    return NA_REAL;
  }
  double u = rng_unif();
  return ceil(pow(log(u)/log(q), 1.0/beta) - 1.0);
}
開發者ID:cran,項目名稱:extraDistr,代碼行數:10,代碼來源:discrete-weibull-distribution.cpp

示例13: invcdf_dweibull

inline double invcdf_dweibull(double p, double q, double beta,
                              bool& throw_warning) {
#ifdef IEEE_754
  if (ISNAN(p) || ISNAN(q) || ISNAN(beta))
    return p+q+beta;
#endif
  if (q <= 0.0 || q >= 1.0 || beta <= 0.0 || !VALID_PROB(p)) {
    throw_warning = true;
    return NAN;
  }
  if (p == 0.0)
    return 0.0;
  return ceil(pow(log(1.0 - p)/log(q), 1.0/beta) - 1.0);
}
開發者ID:cran,項目名稱:extraDistr,代碼行數:14,代碼來源:discrete-weibull-distribution.cpp

示例14:

Bitmap::Bitmap( std::string filename ) {
	using std::ceil;

	file = PNG::load( filename );

	intensityMap = new unsigned char[file->w * file->h];
	unsigned char *imPtr = intensityMap, *cPtr = file->data;

	for (unsigned int y = 0; y < file->h; y++) {
		for (unsigned int x = 0; x < file->w; x++, imPtr++, cPtr+=4) {
			*imPtr = 255 - (unsigned char)ceil(((float)(*(cPtr)) * 0.2126 + (float)(*(cPtr+1)) * 0.7152 + (float)(*(cPtr+2)) * 0.0722));
		}
	}
}
開發者ID:Aeon,項目名稱:voronoi,代碼行數:14,代碼來源:bitmap.cpp

示例15: calculate_size

int calculate_size(const Eigen::VectorXd& x, 
                   const std::string& name,
                   const int digits,
                   std::ios_base::fmtflags& format) {
  using std::max;
  using std::ceil;
  using std::log10;
  
  double padding = 0;
  if (digits > 0)
    padding = digits + 1;

  double fixed_size = 0.0;
  if (x.maxCoeff() > 0)
    fixed_size = ceil(log10(x.maxCoeff()+0.001)) + padding;
  if (x.minCoeff() < 0)
    fixed_size = max(fixed_size, ceil(log10(-x.minCoeff()+0.01))+(padding+1));
  format = std::ios_base::fixed;
  if (fixed_size < 7) {
    return max(fixed_size,
               max(name.length(), std::string("-0.0").length())+0.0);
  }

  double scientific_size = 0;
  scientific_size += 4.0;   // "-0.0" has four digits
  scientific_size += 1.0;   // e
  double exponent_size = 0;
  if (x.maxCoeff() > 0)
    exponent_size = ceil(log10(log10(x.maxCoeff())));
  if (x.minCoeff() < 0)
    exponent_size = max(exponent_size,
                        ceil(log10(log10(-x.minCoeff()))));
  scientific_size += fmin(exponent_size, 3);
  format = std::ios_base::scientific;
  return scientific_size;
}
開發者ID:aflaxman,項目名稱:stan,代碼行數:36,代碼來源:print.cpp


注:本文中的std::ceil方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。