当前位置: 首页>>代码示例>>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;未经允许,请勿转载。