Rename members to better reflect purpose.

Specifically,

  - x_  -> val_
  - dx_ -> der_
This commit is contained in:
Bård Skaflestad 2013-04-30 09:25:37 +02:00
parent e17447d6cd
commit 0ff3b721ee

View File

@ -43,17 +43,17 @@ namespace AutoDiff {
class Forward { class Forward {
public: public:
explicit Forward(const Scalar& x) explicit Forward(const Scalar& x)
: x_(x), dx_(Scalar(1)) : val_(x), der_(Scalar(1))
{} {}
Forward(const Scalar x, const Scalar dx) Forward(const Scalar x, const Scalar dx)
: x_(x), dx_(dx) : val_(x), der_(dx)
{} {}
Forward& Forward&
operator +=(const Scalar& rhs) operator +=(const Scalar& rhs)
{ {
x_ += rhs; val_ += rhs;
return *this; return *this;
} }
@ -61,8 +61,8 @@ namespace AutoDiff {
Forward& Forward&
operator +=(const Forward& rhs) operator +=(const Forward& rhs)
{ {
x_ += rhs.x_; val_ += rhs.val_;
dx_ += rhs.dx_; der_ += rhs.der_;
return *this; return *this;
} }
@ -70,7 +70,7 @@ namespace AutoDiff {
Forward& Forward&
operator -=(const Scalar& rhs) operator -=(const Scalar& rhs)
{ {
x_ -= rhs; val_ -= rhs;
return *this; return *this;
} }
@ -78,8 +78,8 @@ namespace AutoDiff {
Forward& Forward&
operator -=(const Forward& rhs) operator -=(const Forward& rhs)
{ {
x_ -= rhs.x_; val_ -= rhs.val_;
dx_ -= rhs.dx_; der_ -= rhs.der_;
return *this; return *this;
} }
@ -87,8 +87,8 @@ namespace AutoDiff {
Forward& Forward&
operator *=(const Scalar& rhs) operator *=(const Scalar& rhs)
{ {
x_ *= rhs; val_ *= rhs;
dx_ *= rhs; der_ *= rhs;
return *this; return *this;
} }
@ -96,8 +96,8 @@ namespace AutoDiff {
Forward& Forward&
operator *=(const Forward& rhs) operator *=(const Forward& rhs)
{ {
dx_ = dx_*rhs.x_ + x_*rhs.dx_; der_ = der_*rhs.val_ + val_*rhs.der_;
x_ *= rhs.x_; val_ *= rhs.val_;
return *this; return *this;
} }
@ -105,8 +105,8 @@ namespace AutoDiff {
Forward& Forward&
operator /=(const Scalar& rhs) operator /=(const Scalar& rhs)
{ {
x_ /= rhs; val_ /= rhs;
dx_ /= rhs; der_ /= rhs;
return *this; return *this;
} }
@ -114,8 +114,8 @@ namespace AutoDiff {
Forward& Forward&
operator /=(const Forward& rhs) operator /=(const Forward& rhs)
{ {
dx_ = (dx_*rhs.x_ - x_*rhs.dx_) / (rhs.x_ * rhs.x_); der_ = (der_*rhs.val_ - val_*rhs.der_) / (rhs.val_ * rhs.val_);
x_ /= rhs.x_; val_ /= rhs.val_;
return *this; return *this;
} }
@ -124,17 +124,17 @@ namespace AutoDiff {
Ostream& Ostream&
print(Ostream& os) const print(Ostream& os) const
{ {
os << "(x,dx) = (" << x_ << ',' << dx_ << ")"; os << "(x,dx) = (" << val_ << ',' << der_ << ")";
return os; return os;
} }
const Scalar val() const { return x_ ; } const Scalar val() const { return val_; }
const Scalar der() const { return dx_; } const Scalar der() const { return der_; }
private: private:
Scalar x_ ; Scalar val_ ;
Scalar dx_; Scalar der_;
}; };