1 #ifndef _tinyfadfive_h_ 2 #define _tinyfadfive_h_ 9 template <
class T>
class TinyFad<5,T> {
26 void diff(
const size_t ith,
const size_t sz){
35 case 0 : dx0_ = T(1.);
break;
36 case 1 : dx1_ = T(1.);
break;
37 case 2 : dx2_ = T(1.);
break;
38 case 3 : dx3_ = T(1.);
break;
39 case 4 : dx4_ = T(1.);
break;
40 default : cout <<
"ith = " << ith <<
" out of definition set" << endl;exit(1);
44 TinyFad(
const T& ind,
const int ini) : n(ini+1), val_(ind) {
52 case 0 : dx0_ = T(1.);
break;
53 case 1 : dx1_ = T(1.);
break;
54 case 2 : dx2_ = T(1.);
break;
55 case 3 : dx3_ = T(1.);
break;
56 case 4 : dx4_ = T(1.);
break;
57 default : cout <<
"ini = " << ini <<
" out of definition set" << endl;exit(1);
85 int N()
const {
return n-1;}
90 const T&
d0()
const {
return dx0_;}
91 T&
d0() {
return dx0_;}
93 const T&
d1()
const {
return dx1_;}
94 T&
d1() {
return dx1_;}
96 const T&
d2()
const {
return dx2_;}
97 T&
d2() {
return dx2_;}
99 const T&
d3()
const {
return dx3_;}
100 T&
d3() {
return dx3_;}
102 const T&
d4()
const {
return dx4_;}
103 T&
d4() {
return dx4_;}
107 case 0 :
return dx0_;
108 case 1 :
return dx1_;
109 case 2 :
return dx2_;
110 case 3 :
return dx3_;
111 case 4 :
return dx4_;
112 default : cout <<
"i out of bounds" << endl;exit(1);
115 const T&
dx(
int i)
const {
117 case 0 :
return dx0_;
118 case 1 :
return dx1_;
119 case 2 :
return dx2_;
120 case 3 :
return dx3_;
121 case 4 :
return dx4_;
122 default : cout <<
"i out of bounds" << endl;exit(1);
127 case 0 :
return dx0_;
128 case 1 :
return dx1_;
129 case 2 :
return dx2_;
130 case 3 :
return dx3_;
131 case 4 :
return dx4_;
132 default : cout <<
"i out of bounds" << endl;exit(1);
135 const T&
d(
int i)
const {
137 case 0 :
return dx0_;
138 case 1 :
return dx1_;
139 case 2 :
return dx2_;
140 case 3 :
return dx3_;
141 case 4 :
return dx4_;
142 default : cout <<
"i out of bounds" << endl;exit(1);
192 dx0_ = dx0_ * in.
val_ + val_ * in.
dx0_;
193 dx1_ = dx1_ * in.
val_ + val_ * in.
dx1_;
194 dx2_ = dx2_ * in.
val_ + val_ * in.
dx2_;
195 dx3_ = dx3_ * in.
val_ + val_ * in.
dx3_;
196 dx4_ = dx4_ * in.
val_ + val_ * in.
dx4_;
202 if (in.
val_ == 0.)
error(
"TinyFad & TinyFad::operator /= (const TinyFad & in), dividing by 0");
233 if ( in == T(0.) )
error(
"TinyFad & TinyFad::operator /= (const T & in), dividing by 0");
276 template <
class L,
class R>
inline 285 tmp.d0() = un.d0() + deux.d0();
287 tmp.d1() = un.d1() + deux.d1();
289 tmp.d2() = un.d2() + deux.d2();
291 tmp.d3() = un.d3() + deux.d3();
293 tmp.d4() = un.d4() + deux.d4();
300 template <
class L,
class R>
inline 319 tmp.
val() = un.
val() + deux;
324 template <
class L,
class R>
inline 330 template <
class L,
class R>
inline 339 tmp.d0() = un.d0()*deux.
val() + un.
val() * deux.d0();
341 tmp.d1() = un.d1()*deux.
val() + un.
val() * deux.d1();
343 tmp.d2() = un.d2()*deux.
val() + un.
val() * deux.d2();
345 tmp.d3() = un.d3()*deux.
val() + un.
val() * deux.d3();
347 tmp.d4() = un.d4()*deux.
val() + un.
val() * deux.d4();
354 template <
class L,
class R>
inline 363 tmp.d0() = un.d0()*deux;
365 tmp.d1() = un.d1()*deux;
367 tmp.d2() = un.d2()*deux;
369 tmp.d3() = un.d3()*deux;
371 tmp.d4() = un.d4()*deux;
373 tmp.
val() = un.
val() * deux;
378 template <
class L,
class R>
inline 386 template <
class L,
class R>
inline 395 tmp.d0() = un.d0() - deux.d0();
397 tmp.d1() = un.d1() - deux.d1();
399 tmp.d2() = un.d2() - deux.d2();
401 tmp.d3() = un.d3() - deux.d3();
403 tmp.d4() = un.d4() - deux.d4();
410 template <
class L,
class R>
inline 419 tmp.d0() -= deux.d0();
421 tmp.d1() -= deux.d1();
423 tmp.d2() -= deux.d2();
425 tmp.d3() -= deux.d3();
427 tmp.d4() -= deux.d4();
429 tmp.
val() = un - deux.
val();
434 template <
class L,
class R>
inline 452 tmp.
val() = un.
val() - deux;
457 template <
class L,
class R>
inline 463 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<5,L> & un, const TinyFad<5,R> & deux), dividing by 0");
467 value_type dval = deux.
val();
469 tmp.d0() = ( un.d0()* deux.
val() - un.
val() * deux.d0() ) / dval / dval ;
471 tmp.d1() = ( un.d1()* deux.
val() - un.
val() * deux.d1() ) / dval / dval ;
473 tmp.d2() = ( un.d2()* deux.
val() - un.
val() * deux.d2() ) / dval / dval ;
475 tmp.d3() = ( un.d3()* deux.
val() - un.
val() * deux.d3() ) / dval / dval ;
477 tmp.d4() = ( un.d4()* deux.
val() - un.
val() * deux.d4() ) / dval / dval ;
479 tmp.
val() = un.
val() / dval;
484 template <
class L,
class R>
inline 490 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const L & un, const TinyFad<5,R> & deux), dividing by 0");
494 value_type dval = deux.
val();
496 tmp.d0() = - un * deux.d0() / dval / dval ;
498 tmp.d1() = - un * deux.d1() / dval / dval ;
500 tmp.d2() = - un * deux.d2() / dval / dval ;
502 tmp.d3() = - un * deux.d3() / dval / dval ;
504 tmp.d4() = - un * deux.d4() / dval / dval ;
506 tmp.
val() = un / dval;
511 template <
class L,
class R>
inline 517 if (deux == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<5,L> & un, const R & deux), dividing by 0");
522 tmp.d0() = un.d0() / deux;
524 tmp.d1() = un.d1() / deux;
526 tmp.d2() = un.d2() / deux;
528 tmp.d3() = un.d3() / deux;
530 tmp.d4() = un.d4() / deux;
532 tmp.
val() = un.
val() / deux;
552 if ( in.
val() <= 0)
error(
"TinyFad log (const TinyFad& in) : zero or negative value");
566 if ( in.
val() < 0. )
error(
"TinyFad<5,T> sqrt (const TinyFad& in) : negative value");
570 if ( in.
val() == T(0.) ){
571 if ( in.
d0() != T(0.) ) test =
false;
573 if ( in.
d1() != T(0.) ) test =
false;
575 if ( in.
d2() != T(0.) ) test =
false;
577 if ( in.
d3() != T(0.) ) test =
false;
579 if ( in.
d4() != T(0.) ) test =
false;
582 error(
"TinyFad<5,T> sqrt (const TinyFad& in) : null value");
623 if ( in.
val() == 0)
error(
"TinyFad tan (const TinyFad& in) undiefined in 0.");
626 T cosinus =
cos(in.
val());
627 tmp.
d0() = in.
d0() / cosinus / cosinus;
628 tmp.
d1() = in.
d1() / cosinus / cosinus;
629 tmp.
d2() = in.
d2() / cosinus / cosinus;
630 tmp.
d3() = in.
d3() / cosinus / cosinus;
631 tmp.
d4() = in.
d4() / cosinus / cosinus;
651 if (un.
val() == 0)
error(
"TinyFad pow (const TinyFad& un, const TinyFad& deux), un = 0. ");
672 tmp.d0() = e*in.
d0()*
pow((
double)in.
val(), (double)e-1);
673 tmp.d1() = e*in.
d1()*
pow((
double)in.
val(), (double)e-1);
674 tmp.d2() = e*in.
d2()*
pow((
double)in.
val(), (double)e-1);
675 tmp.d3() = e*in.
d3()*
pow((
double)in.
val(), (double)e-1);
676 tmp.d4() = e*in.
d4()*
pow((
double)in.
val(), (double)e-1);
683 int sign = in.
val() > 0? 1:0;
689 template <
class T> std::ostream& operator << (std::ostream& os, const TinyFad<5,T>& a)
691 os.setf(std::ios::fixed,std::ios::scientific);
693 os << a.
val() <<
" [";
TinyFad< 5, typename NumericalTraits< L, R >::promote > operator/(const TinyFad< 5, L > &un, const TinyFad< 5, R > &deux)
TinyFad< 5, T > operator++(int)
TinyFad< 5, T > operator--(int)
const T & dx(int i) const
TinyFad< 5, typename NumericalTraits< L, R >::promote > operator*(const TinyFad< 5, L > &un, const TinyFad< 5, R > &deux)
TinyFad< Num, T > & operator-=(const TinyFad< Num, T > &in)
TinyFad< 5, T > abs(const TinyFad< 5, T > &in)
void diff(const size_t ith, const size_t sz)
TinyFad(const No_Initialization &)
TinyFad< 5, T > & operator--()
TinyFad< 5, T > tan(const TinyFad< 5, T > &in)
AutoPointerMutexArrayInit tmp
TinyFad< 5, T > cos(const TinyFad< 5, T > &in)
TinyFad< 5, T > operator-(const TinyFad< 5, T > &in)
TinyFad< 5, T > sqrt(const TinyFad< 5, T > &in)
TinyFad< 5, T > & operator++()
TinyFad< Num, T > & operator=(const TinyFad< Num, T > &in)
TinyFad< 5, T > log(const TinyFad< 5, T > &in)
TinyFad(const TinyFad< 5, T > &in)
TinyFad< Num, T > & operator+=(const TinyFad< Num, T > &in)
TinyFad< 5, T > operator+(const TinyFad< 5, T > &in)
TinyFad< 5, T > pow(const TinyFad< 5, T > &in, double e)
TinyFad< Num, T > & operator*=(const TinyFad< Num, T > &in)
TinyFad(const T &ind, const int ini)
TinyFad< 5, T > sin(const TinyFad< 5, T > &in)
TinyFad< Num, T > & operator/=(const TinyFad< Num, T > &in)
TinyFad< 5, T > exp(const TinyFad< 5, T > &in)