9 template <
class T>
class TinyFad<2,T> {
23 void diff(
const size_t ith,
const size_t sz){
29 case 0 : dx0_ = T(1.);
break;
30 case 1 : dx1_ = T(1.);
break;
31 default : cout <<
"ith = " << ith <<
" out of definition set" << endl;exit(1);
35 TinyFad(
const T& ind,
const int ini) : n(ini+1), val_(ind) {
40 case 0 : dx0_ = T(1.);
break;
41 case 1 : dx1_ = T(1.);
break;
42 default : cout <<
"ini = " << ini <<
" out of definition set" << endl;exit(1);
61 int N()
const {
return n-1;}
66 const T&
d0()
const {
return dx0_;}
67 T&
d0() {
return dx0_;}
69 const T&
d1()
const {
return dx1_;}
70 T&
d1() {
return dx1_;}
76 default : cout <<
"i out of bounds" << endl;exit(1);
79 const T&
dx(
int i)
const {
83 default : cout <<
"i out of bounds" << endl;exit(1);
90 default : cout <<
"i out of bounds" << endl;exit(1);
93 const T&
d(
int i)
const {
97 default : cout <<
"i out of bounds" << endl;exit(1);
135 dx0_ = dx0_ * in.
val_ + val_ * in.
dx0_;
136 dx1_ = dx1_ * in.
val_ + val_ * in.
dx1_;
142 if (in.
val_ == 0.)
error(
"TinyFad & TinyFad::operator /= (const TinyFad & in), dividing by 0");
167 if ( in == T(0.) )
error(
"TinyFad & TinyFad::operator /= (const T & in), dividing by 0");
207 template <
class L,
class R>
inline 216 tmp.d0() = un.d0() + deux.d0();
218 tmp.d1() = un.d1() + deux.d1();
225 template <
class L,
class R>
inline 238 tmp.
val() = un.
val() + deux;
243 template <
class L,
class R>
inline 249 template <
class L,
class R>
inline 258 tmp.d0() = un.d0()*deux.
val() + un.
val() * deux.d0();
260 tmp.d1() = un.d1()*deux.
val() + un.
val() * deux.d1();
267 template <
class L,
class R>
inline 276 tmp.d0() = un.d0()*deux;
278 tmp.d1() = un.d1()*deux;
280 tmp.
val() = un.
val() * deux;
285 template <
class L,
class R>
inline 293 template <
class L,
class R>
inline 302 tmp.d0() = un.d0() - deux.d0();
304 tmp.d1() = un.d1() - deux.d1();
311 template <
class L,
class R>
inline 320 tmp.d0() -= deux.d0();
322 tmp.d1() -= deux.d1();
324 tmp.
val() = un - deux.
val();
329 template <
class L,
class R>
inline 341 tmp.
val() = un.
val() - deux;
346 template <
class L,
class R>
inline 352 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<2,L> & un, const TinyFad<2,R> & deux), dividing by 0");
356 value_type dval = deux.
val();
358 tmp.d0() = ( un.d0()* deux.
val() - un.
val() * deux.d0() ) / dval / dval ;
360 tmp.d1() = ( un.d1()* deux.
val() - un.
val() * deux.d1() ) / dval / dval ;
362 tmp.
val() = un.
val() / dval;
367 template <
class L,
class R>
inline 373 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const L & un, const TinyFad<2,R> & deux), dividing by 0");
377 value_type dval = deux.
val();
379 tmp.d0() = - un * deux.d0() / dval / dval ;
381 tmp.d1() = - un * deux.d1() / dval / dval ;
383 tmp.
val() = un / dval;
388 template <
class L,
class R>
inline 394 if (deux == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<2,L> & un, const R & deux), dividing by 0");
399 tmp.d0() = un.d0() / deux;
401 tmp.d1() = un.d1() / deux;
403 tmp.
val() = un.
val() / deux;
420 if ( in.
val() <= 0)
error(
"TinyFad log (const TinyFad& in) : zero or negative value");
431 if ( in.
val() < 0. )
error(
"TinyFad<2,T> sqrt (const TinyFad& in) : negative value");
435 if ( in.
val() == T(0.) ){
436 if ( in.
d0() != T(0.) ) test =
false;
438 if ( in.
d1() != T(0.) ) test =
false;
441 error(
"TinyFad<2,T> sqrt (const TinyFad& in) : null value");
473 if ( in.
val() == 0)
error(
"TinyFad tan (const TinyFad& in) undiefined in 0.");
476 T cosinus =
cos(in.
val());
477 tmp.
d0() = in.
d0() / cosinus / cosinus;
478 tmp.
d1() = in.
d1() / cosinus / cosinus;
495 if (un.
val() == 0)
error(
"TinyFad pow (const TinyFad& un, const TinyFad& deux), un = 0. ");
510 tmp.d0() = e*in.
d0()*
pow((
double)in.
val(), (double)e-1);
511 tmp.d1() = e*in.
d1()*
pow((
double)in.
val(), (double)e-1);
518 int sign = in.
val() > 0? 1:0;
524 template <
class T> std::ostream& operator << (std::ostream& os, const TinyFad<2,T>& a)
526 os.setf(std::ios::fixed,std::ios::scientific);
528 os << a.
val() <<
" [";
TinyFad(const TinyFad< 2, T > &in)
TinyFad< Num, T > & operator-=(const TinyFad< Num, T > &in)
TinyFad< 2, typename NumericalTraits< L, R >::promote > operator/(const TinyFad< 2, L > &un, const TinyFad< 2, R > &deux)
TinyFad< 2, T > log(const TinyFad< 2, T > &in)
TinyFad< 2, T > & operator++()
AutoPointerMutexArrayInit tmp
TinyFad< 2, T > tan(const TinyFad< 2, T > &in)
TinyFad< 2, T > & operator--()
TinyFad(const No_Initialization &)
TinyFad< 2, T > sqrt(const TinyFad< 2, T > &in)
TinyFad< Num, T > & operator=(const TinyFad< Num, T > &in)
TinyFad< Num, T > & operator+=(const TinyFad< Num, T > &in)
TinyFad< 2, T > abs(const TinyFad< 2, T > &in)
TinyFad(const T &ind, const int ini)
TinyFad< Num, T > & operator*=(const TinyFad< Num, T > &in)
TinyFad< 2, T > sin(const TinyFad< 2, T > &in)
TinyFad< 2, T > operator++(int)
TinyFad< 2, T > cos(const TinyFad< 2, T > &in)
TinyFad< Num, T > & operator/=(const TinyFad< Num, T > &in)
TinyFad< 2, T > pow(const TinyFad< 2, T > &in, double e)
TinyFad< 2, T > operator+(const TinyFad< 2, T > &in)
void diff(const size_t ith, const size_t sz)
TinyFad< 2, T > operator-(const TinyFad< 2, T > &in)
const T & dx(int i) const
TinyFad< 2, T > operator--(int)
TinyFad< 2, typename NumericalTraits< L, R >::promote > operator*(const TinyFad< 2, L > &un, const TinyFad< 2, R > &deux)
TinyFad< 2, T > exp(const TinyFad< 2, T > &in)