本文整理匯總了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_);
}
示例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();
}
示例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)));
}
示例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;
}
示例5: nearbyint
static source_type nearbyint ( argument_type s )
{
#if !defined(BOOST_NO_STDC_NAMESPACE)
using std::ceil ;
#endif
return Double( ceil(s.v) );
}
示例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;
}
示例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 ) ;
}
}
示例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++;
}
}
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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));
}
}
}
示例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;
}