1 #ifndef _tinyfadfour_h_ 2 #define _tinyfadfour_h_ 9 template <
class T>
class TinyFad<4,T> {
25 void diff(
const size_t ith,
const size_t sz){
33 case 0 : dx0_ = T(1.);
break;
34 case 1 : dx1_ = T(1.);
break;
35 case 2 : dx2_ = T(1.);
break;
36 case 3 : dx3_ = T(1.);
break;
37 default : cout <<
"ith = " << ith <<
" out of definition set" << endl;exit(1);
41 TinyFad(
const T& ind,
const int ini) : n(ini+1), val_(ind) {
48 case 0 : dx0_ = T(1.);
break;
49 case 1 : dx1_ = T(1.);
break;
50 case 2 : dx2_ = T(1.);
break;
51 case 3 : dx3_ = T(1.);
break;
52 default : cout <<
"ini = " << ini <<
" out of definition set" << endl;exit(1);
77 int N()
const {
return n-1;}
82 const T&
d0()
const {
return dx0_;}
83 T&
d0() {
return dx0_;}
85 const T&
d1()
const {
return dx1_;}
86 T&
d1() {
return dx1_;}
88 const T&
d2()
const {
return dx2_;}
89 T&
d2() {
return dx2_;}
91 const T&
d3()
const {
return dx3_;}
92 T&
d3() {
return dx3_;}
100 default : cout <<
"i out of bounds" << endl;exit(1);
103 const T&
dx(
int i)
const {
105 case 0 :
return dx0_;
106 case 1 :
return dx1_;
107 case 2 :
return dx2_;
108 case 3 :
return dx3_;
109 default : cout <<
"i out of bounds" << endl;exit(1);
114 case 0 :
return dx0_;
115 case 1 :
return dx1_;
116 case 2 :
return dx2_;
117 case 3 :
return dx3_;
118 default : cout <<
"i out of bounds" << endl;exit(1);
121 const T&
d(
int i)
const {
123 case 0 :
return dx0_;
124 case 1 :
return dx1_;
125 case 2 :
return dx2_;
126 case 3 :
return dx3_;
127 default : cout <<
"i out of bounds" << endl;exit(1);
173 dx0_ = dx0_ * in.
val_ + val_ * in.
dx0_;
174 dx1_ = dx1_ * in.
val_ + val_ * in.
dx1_;
175 dx2_ = dx2_ * in.
val_ + val_ * in.
dx2_;
176 dx3_ = dx3_ * in.
val_ + val_ * in.
dx3_;
182 if (in.
val_ == 0.)
error(
"TinyFad & TinyFad::operator /= (const TinyFad & in), dividing by 0");
211 if ( in == T(0.) )
error(
"TinyFad & TinyFad::operator /= (const T & in), dividing by 0");
253 template <
class L,
class R>
inline 262 tmp.d0() = un.d0() + deux.d0();
264 tmp.d1() = un.d1() + deux.d1();
266 tmp.d2() = un.d2() + deux.d2();
268 tmp.d3() = un.d3() + deux.d3();
275 template <
class L,
class R>
inline 292 tmp.
val() = un.
val() + deux;
297 template <
class L,
class R>
inline 303 template <
class L,
class R>
inline 312 tmp.d0() = un.d0()*deux.
val() + un.
val() * deux.d0();
314 tmp.d1() = un.d1()*deux.
val() + un.
val() * deux.d1();
316 tmp.d2() = un.d2()*deux.
val() + un.
val() * deux.d2();
318 tmp.d3() = un.d3()*deux.
val() + un.
val() * deux.d3();
325 template <
class L,
class R>
inline 334 tmp.d0() = un.d0()*deux;
336 tmp.d1() = un.d1()*deux;
338 tmp.d2() = un.d2()*deux;
340 tmp.d3() = un.d3()*deux;
342 tmp.
val() = un.
val() * deux;
347 template <
class L,
class R>
inline 355 template <
class L,
class R>
inline 364 tmp.d0() = un.d0() - deux.d0();
366 tmp.d1() = un.d1() - deux.d1();
368 tmp.d2() = un.d2() - deux.d2();
370 tmp.d3() = un.d3() - deux.d3();
377 template <
class L,
class R>
inline 386 tmp.d0() -= deux.d0();
388 tmp.d1() -= deux.d1();
390 tmp.d2() -= deux.d2();
392 tmp.d3() -= deux.d3();
394 tmp.
val() = un - deux.
val();
399 template <
class L,
class R>
inline 415 tmp.
val() = un.
val() - deux;
420 template <
class L,
class R>
inline 426 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<4,L> & un, const TinyFad<4,R> & deux), dividing by 0");
430 value_type dval = deux.
val();
432 tmp.d0() = ( un.d0()* deux.
val() - un.
val() * deux.d0() ) / dval / dval ;
434 tmp.d1() = ( un.d1()* deux.
val() - un.
val() * deux.d1() ) / dval / dval ;
436 tmp.d2() = ( un.d2()* deux.
val() - un.
val() * deux.d2() ) / dval / dval ;
438 tmp.d3() = ( un.d3()* deux.
val() - un.
val() * deux.d3() ) / dval / dval ;
440 tmp.
val() = un.
val() / dval;
445 template <
class L,
class R>
inline 451 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const L & un, const TinyFad<4,R> & deux), dividing by 0");
455 value_type dval = deux.
val();
457 tmp.d0() = - un * deux.d0() / dval / dval ;
459 tmp.d1() = - un * deux.d1() / dval / dval ;
461 tmp.d2() = - un * deux.d2() / dval / dval ;
463 tmp.d3() = - un * deux.d3() / dval / dval ;
465 tmp.
val() = un / dval;
470 template <
class L,
class R>
inline 476 if (deux == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<4,L> & un, const R & deux), dividing by 0");
481 tmp.d0() = un.d0() / deux;
483 tmp.d1() = un.d1() / deux;
485 tmp.d2() = un.d2() / deux;
487 tmp.d3() = un.d3() / deux;
489 tmp.
val() = un.
val() / deux;
508 if ( in.
val() <= 0)
error(
"TinyFad log (const TinyFad& in) : zero or negative value");
521 if ( in.
val() < 0. )
error(
"TinyFad<4,T> sqrt (const TinyFad& in) : negative value");
525 if ( in.
val() == T(0.) ){
526 if ( in.
d0() != T(0.) ) test =
false;
528 if ( in.
d1() != T(0.) ) test =
false;
530 if ( in.
d2() != T(0.) ) test =
false;
532 if ( in.
d3() != T(0.) ) test =
false;
535 error(
"TinyFad<4,T> sqrt (const TinyFad& in) : null value");
573 if ( in.
val() == 0)
error(
"TinyFad tan (const TinyFad& in) undiefined in 0.");
576 T cosinus =
cos(in.
val());
577 tmp.
d0() = in.
d0() / cosinus / cosinus;
578 tmp.
d1() = in.
d1() / cosinus / cosinus;
579 tmp.
d2() = in.
d2() / cosinus / cosinus;
580 tmp.
d3() = in.
d3() / cosinus / cosinus;
599 if (un.
val() == 0)
error(
"TinyFad pow (const TinyFad& un, const TinyFad& deux), un = 0. ");
618 tmp.d0() = e*in.
d0()*
pow((
double)in.
val(), (double)e-1);
619 tmp.d1() = e*in.
d1()*
pow((
double)in.
val(), (double)e-1);
620 tmp.d2() = e*in.
d2()*
pow((
double)in.
val(), (double)e-1);
621 tmp.d3() = e*in.
d3()*
pow((
double)in.
val(), (double)e-1);
628 int sign = in.
val() > 0? 1:0;
634 template <
class T> std::ostream& operator << (std::ostream& os, const TinyFad<4,T>& a)
636 os.setf(std::ios::fixed,std::ios::scientific);
638 os << a.
val() <<
" [";
TinyFad< 4, T > operator+(const TinyFad< 4, T > &in)
TinyFad< 4, T > tan(const TinyFad< 4, T > &in)
TinyFad< Num, T > & operator-=(const TinyFad< Num, T > &in)
TinyFad< 4, T > exp(const TinyFad< 4, T > &in)
TinyFad< 4, T > abs(const TinyFad< 4, T > &in)
TinyFad< 4, T > & operator++()
TinyFad< 4, T > operator--(int)
AutoPointerMutexArrayInit tmp
TinyFad< 4, T > sqrt(const TinyFad< 4, T > &in)
TinyFad< 4, T > pow(const TinyFad< 4, T > &in, double e)
TinyFad< Num, T > & operator=(const TinyFad< Num, T > &in)
TinyFad< 4, T > sin(const TinyFad< 4, T > &in)
TinyFad< 4, T > operator++(int)
TinyFad< Num, T > & operator+=(const TinyFad< Num, T > &in)
const T & dx(int i) const
TinyFad< Num, T > & operator*=(const TinyFad< Num, T > &in)
TinyFad(const No_Initialization &)
TinyFad(const TinyFad< 4, T > &in)
TinyFad< 4, typename NumericalTraits< L, R >::promote > operator/(const TinyFad< 4, L > &un, const TinyFad< 4, R > &deux)
TinyFad< 4, T > cos(const TinyFad< 4, T > &in)
TinyFad< Num, T > & operator/=(const TinyFad< Num, T > &in)
TinyFad< 4, T > & operator--()
TinyFad(const T &ind, const int ini)
TinyFad< 4, T > log(const TinyFad< 4, T > &in)
TinyFad< 4, T > operator-(const TinyFad< 4, T > &in)
TinyFad< 4, typename NumericalTraits< L, R >::promote > operator*(const TinyFad< 4, L > &un, const TinyFad< 4, R > &deux)
void diff(const size_t ith, const size_t sz)