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


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

本文整理匯總了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_);
 }
開發者ID:danstowell,項目名稱:stan,代碼行數:25,代碼來源:fmod_test.cpp

示例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_);
}
開發者ID:HerraHuu,項目名稱:stan,代碼行數:25,代碼來源:floor_test.cpp

示例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 ) ;
    }
  }
開發者ID:EricAlex,項目名稱:PDAL,代碼行數:28,代碼來源:converter_policies.hpp

示例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;
    }
開發者ID:jonatanolofsson,項目名稱:cpgl,代碼行數:30,代碼來源:terrain.cpp

示例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;
}
開發者ID:ginkx,項目名稱:surfacing-tetrahedral,代碼行數:12,代碼來源:Surfacing.cpp

示例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;
}
開發者ID:Aeon,項目名稱:voronoi,代碼行數:13,代碼來源:bitmap.cpp

示例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_));
 }
開發者ID:javaosos,項目名稱:stan,代碼行數:7,代碼來源:fmod.hpp

示例8: nearbyint

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

示例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;
    }
}
開發者ID:agude,項目名稱:Project-Euler,代碼行數:31,代碼來源:alexlib.cpp

示例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);
  }
開發者ID:ANCL,項目名稱:autopilot,代碼行數:8,代碼來源:geometric_distribution.hpp

示例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_));
 }
開發者ID:danstowell,項目名稱:stan,代碼行數:8,代碼來源:fmod.hpp

示例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) );
  }
} 
開發者ID:cran,項目名稱:extraDistr,代碼行數:18,代碼來源:discrete-laplace-distribution.cpp

示例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_));         
 }
開發者ID:mcobzarenco,項目名稱:unet,代碼行數:10,代碼來源:fdim.hpp

示例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;
}
開發者ID:step21,項目名稱:inkscape-osx-packaging-native,代碼行數:22,代碼來源:pixblock-scaler.cpp

示例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);
}
開發者ID:Aeon,項目名稱:voronoi,代碼行數:27,代碼來源:bitmap.cpp


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