1 #ifndef _tinyfadeight_h_ 2 #define _tinyfadeight_h_ 9 template <
class T>
class TinyFad<8,T> {
29 void diff(
const size_t ith,
const size_t sz){
41 case 0 : dx0_ = T(1.);
break;
42 case 1 : dx1_ = T(1.);
break;
43 case 2 : dx2_ = T(1.);
break;
44 case 3 : dx3_ = T(1.);
break;
45 case 4 : dx4_ = T(1.);
break;
46 case 5 : dx5_ = T(1.);
break;
47 case 6 : dx6_ = T(1.);
break;
48 case 7 : dx7_ = T(1.);
break;
49 default : cout <<
"ith = " << ith <<
" out of definition set" << endl;exit(1);
53 TinyFad(
const T& ind,
const int ini) : n(ini+1), val_(ind) {
64 case 0 : dx0_ = T(1.);
break;
65 case 1 : dx1_ = T(1.);
break;
66 case 2 : dx2_ = T(1.);
break;
67 case 3 : dx3_ = T(1.);
break;
68 case 4 : dx4_ = T(1.);
break;
69 case 5 : dx5_ = T(1.);
break;
70 case 6 : dx6_ = T(1.);
break;
71 case 7 : dx7_ = T(1.);
break;
72 default : cout <<
"ini = " << ini <<
" out of definition set" << endl;exit(1);
109 int N()
const {
return n-1;}
114 const T&
d0()
const {
return dx0_;}
115 T&
d0() {
return dx0_;}
117 const T&
d1()
const {
return dx1_;}
118 T&
d1() {
return dx1_;}
120 const T&
d2()
const {
return dx2_;}
121 T&
d2() {
return dx2_;}
123 const T&
d3()
const {
return dx3_;}
124 T&
d3() {
return dx3_;}
126 const T&
d4()
const {
return dx4_;}
127 T&
d4() {
return dx4_;}
129 const T&
d5()
const {
return dx5_;}
130 T&
d5() {
return dx5_;}
132 const T&
d6()
const {
return dx6_;}
133 T&
d6() {
return dx6_;}
135 const T&
d7()
const {
return dx7_;}
136 T&
d7() {
return dx7_;}
140 case 0 :
return dx0_;
141 case 1 :
return dx1_;
142 case 2 :
return dx2_;
143 case 3 :
return dx3_;
144 case 4 :
return dx4_;
145 case 5 :
return dx5_;
146 case 6 :
return dx6_;
147 case 7 :
return dx7_;
148 default : cout <<
"i out of bounds" << endl;exit(1);
151 const T&
dx(
int i)
const {
153 case 0 :
return dx0_;
154 case 1 :
return dx1_;
155 case 2 :
return dx2_;
156 case 3 :
return dx3_;
157 case 4 :
return dx4_;
158 case 5 :
return dx5_;
159 case 6 :
return dx6_;
160 case 7 :
return dx7_;
161 default : cout <<
"i out of bounds" << endl;exit(1);
166 case 0 :
return dx0_;
167 case 1 :
return dx1_;
168 case 2 :
return dx2_;
169 case 3 :
return dx3_;
170 case 4 :
return dx4_;
171 case 5 :
return dx5_;
172 case 6 :
return dx6_;
173 case 7 :
return dx7_;
174 default : cout <<
"i out of bounds" << endl;exit(1);
177 const T&
d(
int i)
const {
179 case 0 :
return dx0_;
180 case 1 :
return dx1_;
181 case 2 :
return dx2_;
182 case 3 :
return dx3_;
183 case 4 :
return dx4_;
184 case 5 :
return dx5_;
185 case 6 :
return dx6_;
186 case 7 :
return dx7_;
187 default : cout <<
"i out of bounds" << endl;exit(1);
249 dx0_ = dx0_ * in.
val_ + val_ * in.
dx0_;
250 dx1_ = dx1_ * in.
val_ + val_ * in.
dx1_;
251 dx2_ = dx2_ * in.
val_ + val_ * in.
dx2_;
252 dx3_ = dx3_ * in.
val_ + val_ * in.
dx3_;
253 dx4_ = dx4_ * in.
val_ + val_ * in.
dx4_;
254 dx5_ = dx5_ * in.
val_ + val_ * in.
dx5_;
255 dx6_ = dx6_ * in.
val_ + val_ * in.
dx6_;
256 dx7_ = dx7_ * in.
val_ + val_ * in.
dx7_;
262 if (in.
val_ == 0.)
error(
"TinyFad & TinyFad::operator /= (const TinyFad & in), dividing by 0");
299 if ( in == T(0.) )
error(
"TinyFad & TinyFad::operator /= (const T & in), dividing by 0");
345 template <
class L,
class R>
inline 354 tmp.d0() = un.d0() + deux.d0();
356 tmp.d1() = un.d1() + deux.d1();
358 tmp.d2() = un.d2() + deux.d2();
360 tmp.d3() = un.d3() + deux.d3();
362 tmp.d4() = un.d4() + deux.d4();
364 tmp.d5() = un.d5() + deux.d5();
366 tmp.d6() = un.d6() + deux.d6();
368 tmp.d7() = un.d7() + deux.d7();
375 template <
class L,
class R>
inline 400 tmp.
val() = un.
val() + deux;
405 template <
class L,
class R>
inline 411 template <
class L,
class R>
inline 420 tmp.d0() = un.d0()*deux.
val() + un.
val() * deux.d0();
422 tmp.d1() = un.d1()*deux.
val() + un.
val() * deux.d1();
424 tmp.d2() = un.d2()*deux.
val() + un.
val() * deux.d2();
426 tmp.d3() = un.d3()*deux.
val() + un.
val() * deux.d3();
428 tmp.d4() = un.d4()*deux.
val() + un.
val() * deux.d4();
430 tmp.d5() = un.d5()*deux.
val() + un.
val() * deux.d5();
432 tmp.d6() = un.d6()*deux.
val() + un.
val() * deux.d6();
434 tmp.d7() = un.d7()*deux.
val() + un.
val() * deux.d7();
441 template <
class L,
class R>
inline 450 tmp.d0() = un.d0()*deux;
452 tmp.d1() = un.d1()*deux;
454 tmp.d2() = un.d2()*deux;
456 tmp.d3() = un.d3()*deux;
458 tmp.d4() = un.d4()*deux;
460 tmp.d5() = un.d5()*deux;
462 tmp.d6() = un.d6()*deux;
464 tmp.d7() = un.d7()*deux;
466 tmp.
val() = un.
val() * deux;
471 template <
class L,
class R>
inline 479 template <
class L,
class R>
inline 488 tmp.d0() = un.d0() - deux.d0();
490 tmp.d1() = un.d1() - deux.d1();
492 tmp.d2() = un.d2() - deux.d2();
494 tmp.d3() = un.d3() - deux.d3();
496 tmp.d4() = un.d4() - deux.d4();
498 tmp.d5() = un.d5() - deux.d5();
500 tmp.d6() = un.d6() - deux.d6();
502 tmp.d7() = un.d7() - deux.d7();
509 template <
class L,
class R>
inline 518 tmp.d0() -= deux.d0();
520 tmp.d1() -= deux.d1();
522 tmp.d2() -= deux.d2();
524 tmp.d3() -= deux.d3();
526 tmp.d4() -= deux.d4();
528 tmp.d5() -= deux.d5();
530 tmp.d6() -= deux.d6();
532 tmp.d7() -= deux.d7();
534 tmp.
val() = un - deux.
val();
539 template <
class L,
class R>
inline 563 tmp.
val() = un.
val() - deux;
568 template <
class L,
class R>
inline 574 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<8,L> & un, const TinyFad<8,R> & deux), dividing by 0");
578 value_type dval = deux.
val();
580 tmp.d0() = ( un.d0()* deux.
val() - un.
val() * deux.d0() ) / dval / dval ;
582 tmp.d1() = ( un.d1()* deux.
val() - un.
val() * deux.d1() ) / dval / dval ;
584 tmp.d2() = ( un.d2()* deux.
val() - un.
val() * deux.d2() ) / dval / dval ;
586 tmp.d3() = ( un.d3()* deux.
val() - un.
val() * deux.d3() ) / dval / dval ;
588 tmp.d4() = ( un.d4()* deux.
val() - un.
val() * deux.d4() ) / dval / dval ;
590 tmp.d5() = ( un.d5()* deux.
val() - un.
val() * deux.d5() ) / dval / dval ;
592 tmp.d6() = ( un.d6()* deux.
val() - un.
val() * deux.d6() ) / dval / dval ;
594 tmp.d7() = ( un.d7()* deux.
val() - un.
val() * deux.d7() ) / dval / dval ;
596 tmp.
val() = un.
val() / dval;
601 template <
class L,
class R>
inline 607 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const L & un, const TinyFad<8,R> & deux), dividing by 0");
611 value_type dval = deux.
val();
613 tmp.d0() = - un * deux.d0() / dval / dval ;
615 tmp.d1() = - un * deux.d1() / dval / dval ;
617 tmp.d2() = - un * deux.d2() / dval / dval ;
619 tmp.d3() = - un * deux.d3() / dval / dval ;
621 tmp.d4() = - un * deux.d4() / dval / dval ;
623 tmp.d5() = - un * deux.d5() / dval / dval ;
625 tmp.d6() = - un * deux.d6() / dval / dval ;
627 tmp.d7() = - un * deux.d7() / dval / dval ;
629 tmp.
val() = un / dval;
634 template <
class L,
class R>
inline 640 if (deux == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<8,L> & un, const R & deux), dividing by 0");
645 tmp.d0() = un.d0() / deux;
647 tmp.d1() = un.d1() / deux;
649 tmp.d2() = un.d2() / deux;
651 tmp.d3() = un.d3() / deux;
653 tmp.d4() = un.d4() / deux;
655 tmp.d5() = un.d5() / deux;
657 tmp.d6() = un.d6() / deux;
659 tmp.d7() = un.d7() / deux;
661 tmp.
val() = un.
val() / deux;
684 if ( in.
val() <= 0)
error(
"TinyFad log (const TinyFad& in) : zero or negative value");
701 if ( in.
val() < 0. )
error(
"TinyFad<8,T> sqrt (const TinyFad& in) : negative value");
705 if ( in.
val() == T(0.) ){
706 if ( in.
d0() != T(0.) ) test =
false;
708 if ( in.
d1() != T(0.) ) test =
false;
710 if ( in.
d2() != T(0.) ) test =
false;
712 if ( in.
d3() != T(0.) ) test =
false;
714 if ( in.
d4() != T(0.) ) test =
false;
716 if ( in.
d5() != T(0.) ) test =
false;
718 if ( in.
d6() != T(0.) ) test =
false;
720 if ( in.
d7() != T(0.) ) test =
false;
723 error(
"TinyFad<8,T> sqrt (const TinyFad& in) : null value");
773 if ( in.
val() == 0)
error(
"TinyFad tan (const TinyFad& in) undiefined in 0.");
776 T cosinus =
cos(in.
val());
777 tmp.
d0() = in.
d0() / cosinus / cosinus;
778 tmp.
d1() = in.
d1() / cosinus / cosinus;
779 tmp.
d2() = in.
d2() / cosinus / cosinus;
780 tmp.
d3() = in.
d3() / cosinus / cosinus;
781 tmp.
d4() = in.
d4() / cosinus / cosinus;
782 tmp.
d5() = in.
d5() / cosinus / cosinus;
783 tmp.
d6() = in.
d6() / cosinus / cosinus;
784 tmp.
d7() = in.
d7() / cosinus / cosinus;
807 if (un.
val() == 0)
error(
"TinyFad pow (const TinyFad& un, const TinyFad& deux), un = 0. ");
834 tmp.d0() = e*in.
d0()*
pow((
double)in.
val(), (double)e-1);
835 tmp.d1() = e*in.
d1()*
pow((
double)in.
val(), (double)e-1);
836 tmp.d2() = e*in.
d2()*
pow((
double)in.
val(), (double)e-1);
837 tmp.d3() = e*in.
d3()*
pow((
double)in.
val(), (double)e-1);
838 tmp.d4() = e*in.
d4()*
pow((
double)in.
val(), (double)e-1);
839 tmp.d5() = e*in.
d5()*
pow((
double)in.
val(), (double)e-1);
840 tmp.d6() = e*in.
d6()*
pow((
double)in.
val(), (double)e-1);
841 tmp.d7() = e*in.
d7()*
pow((
double)in.
val(), (double)e-1);
848 int sign = in.
val() > 0? 1:0;
854 template <
class T> std::ostream& operator << (std::ostream& os, const TinyFad<8,T>& a)
856 os.setf(std::ios::fixed,std::ios::scientific);
858 os << a.
val() <<
" [";
TinyFad< 8, T > operator+(const TinyFad< 8, T > &in)
TinyFad< Num, T > & operator-=(const TinyFad< Num, T > &in)
TinyFad< 8, typename NumericalTraits< L, R >::promote > operator*(const TinyFad< 8, L > &un, const TinyFad< 8, R > &deux)
TinyFad< 8, T > operator--(int)
TinyFad< 8, T > log(const TinyFad< 8, T > &in)
TinyFad(const TinyFad< 8, T > &in)
TinyFad< 8, T > abs(const TinyFad< 8, T > &in)
TinyFad< 8, T > operator++(int)
AutoPointerMutexArrayInit tmp
TinyFad< 8, T > cos(const TinyFad< 8, T > &in)
TinyFad< 8, T > & operator++()
TinyFad(const T &ind, const int ini)
const T & dx(int i) const
TinyFad(const No_Initialization &)
TinyFad< Num, T > & operator=(const TinyFad< Num, T > &in)
TinyFad< 8, typename NumericalTraits< L, R >::promote > operator/(const TinyFad< 8, L > &un, const TinyFad< 8, R > &deux)
TinyFad< Num, T > & operator+=(const TinyFad< Num, T > &in)
TinyFad< 8, T > pow(const TinyFad< 8, T > &in, double e)
TinyFad< 8, T > sqrt(const TinyFad< 8, T > &in)
TinyFad< Num, T > & operator*=(const TinyFad< Num, T > &in)
TinyFad< 8, T > operator-(const TinyFad< 8, T > &in)
TinyFad< 8, T > tan(const TinyFad< 8, T > &in)
TinyFad< Num, T > & operator/=(const TinyFad< Num, T > &in)
void diff(const size_t ith, const size_t sz)
TinyFad< 8, T > & operator--()
TinyFad< 8, T > sin(const TinyFad< 8, T > &in)
TinyFad< 8, T > exp(const TinyFad< 8, T > &in)