Exemple #1
0
void DotTemplate::paintPage(QPainter *painter, const QRectF &rect)
{
    const double step = mm(5);
    const double size = mm(m_dotSize);
    const double shiftX = (fmod(rect.width(), step) + step - size) / 2;
    const double shiftY = (fmod(rect.height(), step) + step - size) / 2;

    pagePen.setWidthF(mm(pagePenWidth()));
    painter->setPen(pagePen);
    painter->drawRect(rect);

    QRect point(0, 0, size, size);
    painter->setPen(Qt::NoPen);
    painter->setBrush(Qt::lightGray);

    const double fillWidth = rect.x() + rect.width() - shiftX;
    const double fillHeight = rect.y() + rect.height() - shiftY;
    for (double y = rect.y() + shiftY; y < fillHeight; y += step)
    {
        for (double x = rect.x() + shiftX; x < fillWidth; x += step)
        {
            point.moveTo(x, y);
            painter->drawEllipse(point);
        }
    }
}
Exemple #2
0
TEST(AgradFwdFmod,FvarFvarVar_FvarFvarVar_2ndDeriv_x) {
  using stan::agrad::fvar;
  using stan::agrad::var;
  using std::fmod;

  fvar<fvar<var> > x;
  x.val_.val_ = 3.0;
  x.val_.d_ = 1.0;

  fvar<fvar<var> > y;
  y.val_.val_ = 6.0;
  y.d_.val_ = 1.0;

  fvar<fvar<var> > a = fmod(x,y);

  EXPECT_FLOAT_EQ(fmod(3.0,6.0), a.val_.val_.val());
  EXPECT_FLOAT_EQ(1, a.val_.d_.val());
  EXPECT_FLOAT_EQ(0, a.d_.val_.val());
  EXPECT_FLOAT_EQ(0, a.d_.d_.val());

  AVEC q = createAVEC(x.val_.val_,y.val_.val_);
  VEC r;
  a.val_.d_.grad(q,r);
  EXPECT_FLOAT_EQ(0, r[0]);
  EXPECT_FLOAT_EQ(0, r[1]);
}
Exemple #3
0
 // an alternate version of transit to deal with longitudes in the direct
 // problem.
 static inline int transitdirect(real lon1, real lon2) {
   using std::fmod;
   // We want to compute exactly
   //   int(floor(lon2 / 360)) - int(floor(lon1 / 360))
   // Since we only need the parity of the result we can use std::remquo but
   // this is buggy with g++ 4.8.3 and requires C++11.  So instead we do
   lon1 = fmod(lon1, real(720)); lon2 = fmod(lon2, real(720));
   return ( ((lon2 >= 0 && lon2 < 360) || lon2 < -360 ? 0 : 1) -
            ((lon1 >= 0 && lon1 < 360) || lon1 < -360 ? 0 : 1) );
 }
Exemple #4
0
 inline
 fvar<T>
 fmod(const fvar<T>& x1, double x2) {
   using std::fmod;
   if (unlikely(is_nan(value_of(x1.val_))
                || is_nan(x2)))
     return fvar<T>(fmod(x1.val_, x2), NOT_A_NUMBER);
   else
     return fvar<T>(fmod(x1.val_, x2), x1.d_ / x2);
 }
Exemple #5
0
 inline
 fvar<T>
 fmod(const fvar<T>& x1, const double x2) {
   using std::fmod;
   using stan::math::value_of;
   if (unlikely(boost::math::isnan(value_of(x1.val_))
                || boost::math::isnan(x2)))
     return fvar<T>(fmod(x1.val_,x2),stan::math::NOT_A_NUMBER);
   else
     return fvar<T>(fmod(x1.val_, x2), x1.d_ / x2);
 }
Exemple #6
0
  void Rotation<T>::normalize()
  {
    using std::fmod;

    if (radians_ > pi)
    {
      radians_ = fmod(radians_ + pi, double_pi) - pi;
    }

    else if (radians_ < -pi)
    {
      radians_ = fmod(radians_ - pi, double_pi) + pi;
    }
  }
Exemple #7
0
 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_));
 }
Exemple #8
0
 inline
 fvar<typename stan::return_type<T1,T2>::type>
 fmod(const fvar<T1>& x1, const T2& x2) {
   using std::fmod;
   return fvar<typename stan::return_type<T1,T2>::type>(
     fmod(x1.val_, x2), x1.d_ / x2);
 }
Exemple #9
0
T repeat(T val, T min, T max)
{
	using std::fmod;
	T temp = fmod(val - min, max - min);
	if (temp < T{0}) temp += max - min;
	return temp + min;
}
Exemple #10
0
 inline
 fvar<T>
 fmod(const fvar<T>& x1, const fvar<T>& x2) {
   using std::fmod;
   using std::floor;
   return fvar<T>(fmod(x1.val_, x2.val_), 
                  x1.d_ - x2.d_ * floor(x1.val_ / x2.val_));
 }
Exemple #11
0
string td3Math::mod(vector<vector<string> > operands)
{
    bool op1 = td3Utility::isFloat(operands.at(0).at(0));
    bool op2 = td3Utility::isFloat(operands.at(1).at(0));
    return td3Utility::toString(
               fmod( td3Utility::stof(operands.at(0).at(0)),
                     td3Utility::stof(operands.at(1).at(0))), op1 || op2);
}
Exemple #12
0
TEST(AgradFwdFmod,Double_FvarVar_1stDeriv) {
  using stan::agrad::fvar;
  using stan::agrad::var;
  using std::fmod;

  double x(3.0);
  fvar<var> z(6.0,1.0);
  fvar<var> a = fmod(x,z);

  EXPECT_FLOAT_EQ(fmod(3.0,6.0), a.val_.val());
  EXPECT_FLOAT_EQ(0, a.d_.val());

  AVEC y = createAVEC(z.val_);
  VEC g;
  a.val_.grad(y,g);
  std::isnan(g[0]);
}
Exemple #13
0
 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_));
 }
Exemple #14
0
TEST(AgradFwdFmod,FvarVar_Double_2ndDeriv) {
  using stan::agrad::fvar;
  using stan::agrad::var;
  using std::fmod;

  fvar<var> x(3.0,1.3);
  double z(6.0);
  fvar<var> a = fmod(x,z);

  EXPECT_FLOAT_EQ(fmod(3.0,6.0), a.val_.val());
  EXPECT_FLOAT_EQ(13.0 / 60.0, a.d_.val());

  AVEC y = createAVEC(x.val_);
  VEC g;
  a.d_.grad(y,g);
  EXPECT_FLOAT_EQ(0,g[0]);
}
Exemple #15
0
TEST(AgradFwdFmod,FvarVar_FvarVar_2ndDeriv) {
  using stan::agrad::fvar;
  using stan::agrad::var;
  using std::fmod;

  fvar<var> x(3.0,1.3);
  fvar<var> z(6.0,1.0);
  fvar<var> a = fmod(x,z);

  EXPECT_FLOAT_EQ(fmod(3.0,6.0), a.val_.val());
  EXPECT_FLOAT_EQ(1.3, a.d_.val());

  AVEC y = createAVEC(x.val_,z.val_);
  VEC g;
  a.d_.grad(y,g);
  EXPECT_FLOAT_EQ(0,g[0]);
  std::isnan(g[1]);
}
Exemple #16
0
    // an alternate version of transit to deal with longitudes in the direct
    // problem.
    static inline int transitdirect(real lon1, real lon2) {
      // We want to compute exactly
      //   int(floor(lon2 / 360)) - int(floor(lon1 / 360))
      // Since we only need the parity of the result we can use std::remquo;
      // but this is buggy with g++ 4.8.3 (glibc version < 2.22), see
      //   https://sourceware.org/bugzilla/show_bug.cgi?id=17569
      // and requires C++11.  So instead we do
#if GEOGRAPHICLIB_CXX11_MATH && GEOGRAPHICLIB_PRECISION != 4
      using std::remainder;
      lon1 = remainder(lon1, real(720)); lon2 = remainder(lon2, real(720));
      return ( (lon2 >= 0 && lon2 < 360 ? 0 : 1) -
               (lon1 >= 0 && lon1 < 360 ? 0 : 1) );
#else
      using std::fmod;
      lon1 = fmod(lon1, real(720)); lon2 = fmod(lon2, real(720));
      return ( ((lon2 >= 0 && lon2 < 360) || lon2 < -360 ? 0 : 1) -
               ((lon1 >= 0 && lon1 < 360) || lon1 < -360 ? 0 : 1) );
#endif
    }
Exemple #17
0
TEST(AgradFwdFmod,FvarFvarDouble) {
  using stan::agrad::fvar;
  using std::fmod;

  fvar<fvar<double> > x;
  x.val_.val_ = 3.0;
  x.val_.d_ = 1.0;

  fvar<fvar<double> > y;
  y.val_.val_ = 6.0;
  y.d_.val_ = 1.0;

  fvar<fvar<double> > a = fmod(x,y);

  EXPECT_FLOAT_EQ(fmod(3.0,6.0), a.val_.val_);
  EXPECT_FLOAT_EQ(1, a.val_.d_);
  EXPECT_FLOAT_EQ(0, a.d_.val_);
  EXPECT_FLOAT_EQ(0, a.d_.d_);
}
inline
quantity<Unit, Y>
fmod(const quantity<Unit,Y>& q1, const quantity<Unit,Y>& q2)
{
    using std::fmod;
    
    typedef quantity<Unit,Y> quantity_type;

    return quantity_type::from_value(fmod(q1.value(), q2.value()));
}
Exemple #19
0
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_);
 }
Exemple #20
0
TEST(AgradFwdFmod,Double_FvarFvarVar_1stDeriv) {
  using stan::agrad::fvar;
  using stan::agrad::var;
  using std::fmod;

  double x(3.0);
  fvar<fvar<var> > y;
  y.val_.val_ = 6.0;
  y.d_.val_ = 1.0;

  fvar<fvar<var> > a = fmod(x,y);

  EXPECT_FLOAT_EQ(fmod(3.0,6.0), a.val_.val_.val());
  EXPECT_FLOAT_EQ(0, a.val_.d_.val());
  EXPECT_FLOAT_EQ(0, a.d_.val_.val());
  EXPECT_FLOAT_EQ(0, a.d_.d_.val());

  AVEC q = createAVEC(y.val_.val_);
  VEC r;
  a.val_.val_.grad(q,r);
  EXPECT_FLOAT_EQ(0, r[0]);
}
Exemple #21
0
TEST(AgradFwdFmod,FvarFvarVar_Double_1stDeriv) {
  using stan::agrad::fvar;
  using stan::agrad::var;
  using std::fmod;

  fvar<fvar<var> > x;
  x.val_.val_ = 3.0;
  x.val_.d_ = 1.0;

  double y(6.0);

  fvar<fvar<var> > a = fmod(x,y);

  EXPECT_FLOAT_EQ(fmod(3.0,6.0), a.val_.val_.val());
  EXPECT_FLOAT_EQ(1.0 / 6.0, a.val_.d_.val());
  EXPECT_FLOAT_EQ(0, a.d_.val_.val());
  EXPECT_FLOAT_EQ(0, a.d_.d_.val());

  AVEC q = createAVEC(x.val_.val_);
  VEC r;
  a.val_.val_.grad(q,r);
  EXPECT_FLOAT_EQ(1, r[0]);
}