本文整理汇总了C++中std::floor方法的典型用法代码示例。如果您正苦于以下问题:C++ std::floor方法的具体用法?C++ std::floor怎么用?C++ std::floor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std
的用法示例。
在下文中一共展示了std::floor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST
TEST(AgradFvar, fmod) {
using stan::agrad::fvar;
using std::fmod;
using std::floor;
fvar<double> x(2.0);
fvar<double> y(3.0);
x.d_ = 1.0;
y.d_ = 2.0;
fvar<double> a = fmod(x, y);
EXPECT_FLOAT_EQ(fmod(2.0, 3.0), a.val_);
EXPECT_FLOAT_EQ(1.0 * 1.0 + 2.0 * -floor(2.0 / 3.0), a.d_);
double z = 4.0;
double w = 3.0;
fvar<double> e = fmod(x, z);
EXPECT_FLOAT_EQ(fmod(2.0, 4.0), e.val_);
EXPECT_FLOAT_EQ(1.0 / 4.0, e.d_);
fvar<double> f = fmod(w, x);
EXPECT_FLOAT_EQ(fmod(3.0, 2.0), f.val_);
EXPECT_FLOAT_EQ(1.0 * -floor(3.0 / 2.0), f.d_);
}
示例2: TEST
TEST(AgradFwdFloor,FvarFvarDouble) {
using stan::agrad::fvar;
using std::floor;
fvar<fvar<double> > x;
x.val_.val_ = 1.5;
x.val_.d_ = 2.0;
fvar<fvar<double> > a = floor(x);
EXPECT_FLOAT_EQ(floor(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 = floor(y);
EXPECT_FLOAT_EQ(floor(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_);
}
示例3: 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 ) ;
}
}
示例4: get_height
void Terrain::get_height(Vector3f& position, Vector2f& direction) {
using std::floor;
using std::ceil;
static const float x_scale = 1.0;
static const float z_scale = 1.0;
float x = position.x() * x_scale; // Scale 1.0
float z = position.z() * z_scale; // Scale 1.0
float y1, y2, y3, dydx, dydz, height;
y1 = object->vertexArray[(int(x) + (int(z) + 1) * ttex.width)*3 + 1]; // Lower left
y2 = object->vertexArray[((int(x)+1) + int(z) * ttex.width)*3 + 1]; // Upper right
float dx = x-floor(x);
float dz = z-floor(z);
if(dx + dz > 1) { // Lower triangle
y3 = object->vertexArray[((int(x)+1) + (int(z)+1) * ttex.width)*3 + 1];
dydx = (y3 - y1)/x_scale;
dydz = (y3 - y2)/z_scale;
height = y3 - (1-dx)*dydx - (1-dz)*dydz;
} else {
y3 = object->vertexArray[(int(x) + int(z) * ttex.width)*3 + 1];
dydx = (y2 - y3)/x_scale;
dydz = (y1 - y3)/z_scale;
height = y3 + dx * dydx + dz * dydz;
}
direction << dydx, dydz;
position[1] = height;
}
示例5: find_grid
void find_grid(AxisAlignedBox3 bbox, float reso,vector<unsigned int> *no_planes){
/*This function finds the number of x, y and z planes that can fit in a given bounding box. The resolution(scaling factor) needed for the grid is specified as reso. This function fills up the no_planes vector by the number of x,y and z planes which will be able to fit in the bounding box. Assuming that th vector that will be passed to this function will be already initialized to length three. Since the bounding box is not to be treated too seriously to the point of one extra sample in one dimension, we will not specify two different fields for x direction size in no_planes.*/
Vector3 lengths= bbox.getExtent();
cout<<no_planes->size()<<endl;
assert(no_planes->size()==3);
(*no_planes)[0] = (unsigned int)floor(lengths[0]/(dist_x*reso));
(*no_planes)[1] = (unsigned int)floor(lengths[1]/(dist_y*reso));
(*no_planes)[2] = (unsigned int)floor(lengths[2]/(dist_z*reso));
return;
}
示例6: getIntensity
float Bitmap::getIntensity( float x, float y ) {
using std::floor;
// from wikipedia
unsigned char *iMPtr = intensityMap + (unsigned int)floor(y) * file->w + (unsigned int)floor(x);
float fX = x - floor(x), fY = y - floor(y);
return
(float)(*(iMPtr)) * (1 - fX) * (1 - fY) +
(float)(*(iMPtr + 1)) * fX * (1 - fY) +
(float)(*(iMPtr + file->w)) * (1 - fX) * fY +
(float)(*(iMPtr + file->w + 1)) * fX * fY;
}
示例7: fmod
inline
fvar<T>
fmod(const double x1, const fvar<T>& x2) {
using std::fmod;
using std::floor;
return fvar<T>(fmod(x1, x2.val_), -x2.d_ * floor(x1 / x2.val_));
}
示例8: nearbyint
static source_type nearbyint ( argument_type s )
{
#if !defined(BOOST_NO_STDC_NAMESPACE)
using std::floor;
#endif
return Double( floor(s.v) );
}
示例9: IsPrime
bool IsPrime(const int64_t& INPUT_NUM) {
using std::sqrt;
using std::floor;
// We hard code in a few cases, then test in general
if (INPUT_NUM < 2) { // 0, 1 and negative are not prime
return false;
} else if (INPUT_NUM < 4) { // 3 is prime
return true;
} else if (INPUT_NUM % 2 == 0) { // even numbers are not prime
return false;
} else if (INPUT_NUM < 9) { // 6, 8 has been removed above
return true;
} else if (INPUT_NUM % 3 == 0) { // numbers divisible by 3 are not prime
return false;
} else {
const double FLOOR_ROOT = floor(sqrt(INPUT_NUM));
const int R = static_cast<int>(FLOOR_ROOT);
int f = 5;
while (f <= R) {
if (INPUT_NUM % f == 0) {
return false;
} else if (INPUT_NUM % (f + 2) == 0) {
return false;
} else {
f += 6;
}
}
return true;
}
}
示例10: operator
result_type operator()(Engine& eng)
{
#ifndef BOOST_NO_STDC_NAMESPACE
using std::log;
using std::floor;
#endif
return IntType(floor(log(RealType(1)-eng()) / _log_p)) + IntType(1);
}
示例11: fmod
inline
fvar<typename stan::return_type<T1,T2>::type>
fmod(const T1& x1, const fvar<T2>& x2) {
using std::fmod;
using std::floor;
return fvar<typename stan::return_type<T1,T2>::type>(
fmod(x1, x2.val_), -x2.d_ * floor(x1 / x2.val_));
}
示例12: cdf_dlaplace
inline double cdf_dlaplace(double x, double p, double mu,
bool& throw_warning) {
#ifdef IEEE_754
if (ISNAN(x) || ISNAN(p) || ISNAN(mu))
return x+p+mu;
#endif
if (p <= 0.0 || p >= 1.0) {
throw_warning = true;
return NAN;
}
if (x < 0.0) {
// pow(p, -floor(x-mu))/(1.0+p);
return exp( (log(p) * -floor(x-mu)) - log1p(p) );
} else {
// 1.0 - (pow(p, floor(x-mu)+1.0)/(1.0+p))
return 1.0 - exp( log(p) * (floor(x-mu)+1.0) - log1p(p) );
}
}
示例13: fdim
inline
fvar<T>
fdim(const double x1, const fvar<T>& x2) {
using stan::math::fdim;
using std::floor;
if(x1 < x2.val_)
return fvar<T>(fdim(x1, x2.val_), 0);
else
return fvar<T>(fdim(x1, x2.val_), x2.d_ * -floor(x1 / x2.val_));
}
示例14: samplex
/** Calculates cubically interpolated value of the four given pixel values.
* The pixel values should be interpolated values from sampley, from four
* horizontally adjacent vertical lines. The parameters a, b, c and d
* should be in fixed point format with 8-bit decimal part.
* If we are calculating a pixel, whose x-coordinate in source image is
* i, these vertical lines from where a, b, c and d are calculated, should be
* floor(i) - 1, floor(i), floor(i) + 1, floor(i) + 2, respectively.
* Parameter len should be set to i.
* Returns the interpolated value in 8-bit format, ready to be written
* to output buffer.
*/
inline static int samplex(const int a, const int b, const int c, const int d, const double len) {
double lenf = len - floor(len);
int sum = 0;
sum += (int)(a * (((-1.0 / 3.0) * lenf + 4.0 / 5.0) * lenf - 7.0 / 15.0) * lenf);
sum += (int)(b * (((lenf - 9.0 / 5.0) * lenf - 1.0 / 5.0) * lenf + 1.0));
sum += (int)(c * ((((1 - lenf) - 9.0 / 5.0) * (1 - lenf) - 1.0 / 5.0) * (1 - lenf) + 1.0));
sum += (int)(d * (((-1.0 / 3.0) * (1 - lenf) + 4.0 / 5.0) * (1 - lenf) - 7.0 / 15.0) * (1 - lenf));
//if (sum < 0) sum = 0;
//if (sum > 255 * 256) sum = 255 * 256;
return sum / 256;
}
示例15: getColour
void Bitmap::getColour( float x, float y, unsigned char &r, unsigned char &g, unsigned char &b ) {
using std::floor;
float fX = x - floor(x), fY = y - floor(y);
float f00 = (1 - fX) * (1 - fY),
f10 = fX * (1 - fY),
f01 = (1 - fX) * fY,
f11 = fX * fY;
unsigned char *dataPtr = file->data + (((unsigned int)floor(y) * file->w + (unsigned int)floor(x)) * 4);
r = floor((float)(*(dataPtr)) * f00 +
(float)(*(dataPtr + 4)) * f10 +
(float)(*(dataPtr + file->w * 4)) * f01 +
(float)(*(dataPtr + file->w * 4 + 4)) * f11);
dataPtr++;
g = floor((float)(*(dataPtr)) * f00 +
(float)(*(dataPtr + 4)) * f10 +
(float)(*(dataPtr + file->w * 4)) * f01 +
(float)(*(dataPtr + file->w * 4 + 4)) * f11);
dataPtr++;
b = floor((float)(*(dataPtr)) * f00 +
(float)(*(dataPtr + 4)) * f10 +
(float)(*(dataPtr + file->w * 4)) * f01 +
(float)(*(dataPtr + file->w * 4 + 4)) * f11);
}