1 #ifndef _tinyfadeleven_h_ 2 #define _tinyfadeleven_h_ 9 template <
class T>
class TinyFad<11,T> {
32 void diff(
const size_t ith,
const size_t sz){
47 case 0 : dx0_ = T(1.);
break;
48 case 1 : dx1_ = T(1.);
break;
49 case 2 : dx2_ = T(1.);
break;
50 case 3 : dx3_ = T(1.);
break;
51 case 4 : dx4_ = T(1.);
break;
52 case 5 : dx5_ = T(1.);
break;
53 case 6 : dx6_ = T(1.);
break;
54 case 7 : dx7_ = T(1.);
break;
55 case 8 : dx8_ = T(1.);
break;
56 case 9 : dx9_ = T(1.);
break;
57 case 10 : dx10_ = T(1.);
break;
58 default : cout <<
"ith = " << ith <<
" out of definition set" << endl;exit(1);
62 TinyFad(
const T& ind,
const int ini) : n(ini+1), val_(ind) {
76 case 0 : dx0_ = T(1.);
break;
77 case 1 : dx1_ = T(1.);
break;
78 case 2 : dx2_ = T(1.);
break;
79 case 3 : dx3_ = T(1.);
break;
80 case 4 : dx4_ = T(1.);
break;
81 case 5 : dx5_ = T(1.);
break;
82 case 6 : dx6_ = T(1.);
break;
83 case 7 : dx7_ = T(1.);
break;
84 case 8 : dx8_ = T(1.);
break;
85 case 9 : dx9_ = T(1.);
break;
86 case 10 : dx10_ = T(1.);
break;
87 default : cout <<
"ini = " << ini <<
" out of definition set" << endl;exit(1);
133 int N()
const {
return n-1;}
138 const T&
d0()
const {
return dx0_;}
139 T&
d0() {
return dx0_;}
141 const T&
d1()
const {
return dx1_;}
142 T&
d1() {
return dx1_;}
144 const T&
d2()
const {
return dx2_;}
145 T&
d2() {
return dx2_;}
147 const T&
d3()
const {
return dx3_;}
148 T&
d3() {
return dx3_;}
150 const T&
d4()
const {
return dx4_;}
151 T&
d4() {
return dx4_;}
153 const T&
d5()
const {
return dx5_;}
154 T&
d5() {
return dx5_;}
156 const T&
d6()
const {
return dx6_;}
157 T&
d6() {
return dx6_;}
159 const T&
d7()
const {
return dx7_;}
160 T&
d7() {
return dx7_;}
162 const T&
d8()
const {
return dx8_;}
163 T&
d8() {
return dx8_;}
165 const T&
d9()
const {
return dx9_;}
166 T&
d9() {
return dx9_;}
168 const T&
d10()
const {
return dx10_;}
173 case 0 :
return dx0_;
174 case 1 :
return dx1_;
175 case 2 :
return dx2_;
176 case 3 :
return dx3_;
177 case 4 :
return dx4_;
178 case 5 :
return dx5_;
179 case 6 :
return dx6_;
180 case 7 :
return dx7_;
181 case 8 :
return dx8_;
182 case 9 :
return dx9_;
183 case 10 :
return dx10_;
184 default : cout <<
"i out of bounds" << endl;exit(1);
187 const T&
dx(
int i)
const {
189 case 0 :
return dx0_;
190 case 1 :
return dx1_;
191 case 2 :
return dx2_;
192 case 3 :
return dx3_;
193 case 4 :
return dx4_;
194 case 5 :
return dx5_;
195 case 6 :
return dx6_;
196 case 7 :
return dx7_;
197 case 8 :
return dx8_;
198 case 9 :
return dx9_;
199 case 10 :
return dx10_;
200 default : cout <<
"i out of bounds" << endl;exit(1);
205 case 0 :
return dx0_;
206 case 1 :
return dx1_;
207 case 2 :
return dx2_;
208 case 3 :
return dx3_;
209 case 4 :
return dx4_;
210 case 5 :
return dx5_;
211 case 6 :
return dx6_;
212 case 7 :
return dx7_;
213 case 8 :
return dx8_;
214 case 9 :
return dx9_;
215 case 10 :
return dx10_;
216 default : cout <<
"i out of bounds" << endl;exit(1);
219 const T&
d(
int i)
const {
221 case 0 :
return dx0_;
222 case 1 :
return dx1_;
223 case 2 :
return dx2_;
224 case 3 :
return dx3_;
225 case 4 :
return dx4_;
226 case 5 :
return dx5_;
227 case 6 :
return dx6_;
228 case 7 :
return dx7_;
229 case 8 :
return dx8_;
230 case 9 :
return dx9_;
231 case 10 :
return dx10_;
232 default : cout <<
"i out of bounds" << endl;exit(1);
306 dx0_ = dx0_ * in.
val_ + val_ * in.
dx0_;
307 dx1_ = dx1_ * in.
val_ + val_ * in.
dx1_;
308 dx2_ = dx2_ * in.
val_ + val_ * in.
dx2_;
309 dx3_ = dx3_ * in.
val_ + val_ * in.
dx3_;
310 dx4_ = dx4_ * in.
val_ + val_ * in.
dx4_;
311 dx5_ = dx5_ * in.
val_ + val_ * in.
dx5_;
312 dx6_ = dx6_ * in.
val_ + val_ * in.
dx6_;
313 dx7_ = dx7_ * in.
val_ + val_ * in.
dx7_;
314 dx8_ = dx8_ * in.
val_ + val_ * in.
dx8_;
315 dx9_ = dx9_ * in.
val_ + val_ * in.
dx9_;
316 dx10_ = dx10_ * in.
val_ + val_ * in.
dx10_;
322 if (in.
val_ == 0.)
error(
"TinyFad & TinyFad::operator /= (const TinyFad & in), dividing by 0");
365 if ( in == T(0.) )
error(
"TinyFad & TinyFad::operator /= (const T & in), dividing by 0");
414 template <
class L,
class R>
inline 423 tmp.d0() = un.d0() + deux.d0();
425 tmp.d1() = un.d1() + deux.d1();
427 tmp.d2() = un.d2() + deux.d2();
429 tmp.d3() = un.d3() + deux.d3();
431 tmp.d4() = un.d4() + deux.d4();
433 tmp.d5() = un.d5() + deux.d5();
435 tmp.d6() = un.d6() + deux.d6();
437 tmp.d7() = un.d7() + deux.d7();
439 tmp.d8() = un.d8() + deux.d8();
441 tmp.d9() = un.d9() + deux.d9();
443 tmp.d10() = un.d10() + deux.d10();
450 template <
class L,
class R>
inline 479 tmp.d10() = un.d10();
481 tmp.
val() = un.
val() + deux;
486 template <
class L,
class R>
inline 492 template <
class L,
class R>
inline 501 tmp.d0() = un.d0()*deux.
val() + un.
val() * deux.d0();
503 tmp.d1() = un.d1()*deux.
val() + un.
val() * deux.d1();
505 tmp.d2() = un.d2()*deux.
val() + un.
val() * deux.d2();
507 tmp.d3() = un.d3()*deux.
val() + un.
val() * deux.d3();
509 tmp.d4() = un.d4()*deux.
val() + un.
val() * deux.d4();
511 tmp.d5() = un.d5()*deux.
val() + un.
val() * deux.d5();
513 tmp.d6() = un.d6()*deux.
val() + un.
val() * deux.d6();
515 tmp.d7() = un.d7()*deux.
val() + un.
val() * deux.d7();
517 tmp.d8() = un.d8()*deux.
val() + un.
val() * deux.d8();
519 tmp.d9() = un.d9()*deux.
val() + un.
val() * deux.d9();
521 tmp.d10() = un.d10()*deux.
val() + un.
val() * deux.d10();
528 template <
class L,
class R>
inline 537 tmp.d0() = un.d0()*deux;
539 tmp.d1() = un.d1()*deux;
541 tmp.d2() = un.d2()*deux;
543 tmp.d3() = un.d3()*deux;
545 tmp.d4() = un.d4()*deux;
547 tmp.d5() = un.d5()*deux;
549 tmp.d6() = un.d6()*deux;
551 tmp.d7() = un.d7()*deux;
553 tmp.d8() = un.d8()*deux;
555 tmp.d9() = un.d9()*deux;
557 tmp.d10() = un.d10()*deux;
559 tmp.
val() = un.
val() * deux;
564 template <
class L,
class R>
inline 572 template <
class L,
class R>
inline 581 tmp.d0() = un.d0() - deux.d0();
583 tmp.d1() = un.d1() - deux.d1();
585 tmp.d2() = un.d2() - deux.d2();
587 tmp.d3() = un.d3() - deux.d3();
589 tmp.d4() = un.d4() - deux.d4();
591 tmp.d5() = un.d5() - deux.d5();
593 tmp.d6() = un.d6() - deux.d6();
595 tmp.d7() = un.d7() - deux.d7();
597 tmp.d8() = un.d8() - deux.d8();
599 tmp.d9() = un.d9() - deux.d9();
601 tmp.d10() = un.d10() - deux.d10();
608 template <
class L,
class R>
inline 617 tmp.d0() -= deux.d0();
619 tmp.d1() -= deux.d1();
621 tmp.d2() -= deux.d2();
623 tmp.d3() -= deux.d3();
625 tmp.d4() -= deux.d4();
627 tmp.d5() -= deux.d5();
629 tmp.d6() -= deux.d6();
631 tmp.d7() -= deux.d7();
633 tmp.d8() -= deux.d8();
635 tmp.d9() -= deux.d9();
637 tmp.d10() -= deux.d10();
639 tmp.
val() = un - deux.
val();
644 template <
class L,
class R>
inline 672 tmp.d10() = un.d10();
674 tmp.
val() = un.
val() - deux;
679 template <
class L,
class R>
inline 685 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<11,L> & un, const TinyFad<11,R> & deux), dividing by 0");
689 value_type dval = deux.
val();
691 tmp.d0() = ( un.d0()* deux.
val() - un.
val() * deux.d0() ) / dval / dval ;
693 tmp.d1() = ( un.d1()* deux.
val() - un.
val() * deux.d1() ) / dval / dval ;
695 tmp.d2() = ( un.d2()* deux.
val() - un.
val() * deux.d2() ) / dval / dval ;
697 tmp.d3() = ( un.d3()* deux.
val() - un.
val() * deux.d3() ) / dval / dval ;
699 tmp.d4() = ( un.d4()* deux.
val() - un.
val() * deux.d4() ) / dval / dval ;
701 tmp.d5() = ( un.d5()* deux.
val() - un.
val() * deux.d5() ) / dval / dval ;
703 tmp.d6() = ( un.d6()* deux.
val() - un.
val() * deux.d6() ) / dval / dval ;
705 tmp.d7() = ( un.d7()* deux.
val() - un.
val() * deux.d7() ) / dval / dval ;
707 tmp.d8() = ( un.d8()* deux.
val() - un.
val() * deux.d8() ) / dval / dval ;
709 tmp.d9() = ( un.d9()* deux.
val() - un.
val() * deux.d9() ) / dval / dval ;
711 tmp.d10() = ( un.d10()* deux.
val() - un.
val() * deux.d10() ) / dval / dval ;
713 tmp.
val() = un.
val() / dval;
718 template <
class L,
class R>
inline 724 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const L & un, const TinyFad<11,R> & deux), dividing by 0");
728 value_type dval = deux.
val();
730 tmp.d0() = - un * deux.d0() / dval / dval ;
732 tmp.d1() = - un * deux.d1() / dval / dval ;
734 tmp.d2() = - un * deux.d2() / dval / dval ;
736 tmp.d3() = - un * deux.d3() / dval / dval ;
738 tmp.d4() = - un * deux.d4() / dval / dval ;
740 tmp.d5() = - un * deux.d5() / dval / dval ;
742 tmp.d6() = - un * deux.d6() / dval / dval ;
744 tmp.d7() = - un * deux.d7() / dval / dval ;
746 tmp.d8() = - un * deux.d8() / dval / dval ;
748 tmp.d9() = - un * deux.d9() / dval / dval ;
750 tmp.d10() = - un * deux.d10() / dval / dval ;
752 tmp.
val() = un / dval;
757 template <
class L,
class R>
inline 763 if (deux == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<11,L> & un, const R & deux), dividing by 0");
768 tmp.d0() = un.d0() / deux;
770 tmp.d1() = un.d1() / deux;
772 tmp.d2() = un.d2() / deux;
774 tmp.d3() = un.d3() / deux;
776 tmp.d4() = un.d4() / deux;
778 tmp.d5() = un.d5() / deux;
780 tmp.d6() = un.d6() / deux;
782 tmp.d7() = un.d7() / deux;
784 tmp.d8() = un.d8() / deux;
786 tmp.d9() = un.d9() / deux;
788 tmp.d10() = un.d10() / deux;
790 tmp.
val() = un.
val() / deux;
816 if ( in.
val() <= 0)
error(
"TinyFad log (const TinyFad& in) : zero or negative value");
836 if ( in.
val() < 0. )
error(
"TinyFad<11,T> sqrt (const TinyFad& in) : negative value");
840 if ( in.
val() == T(0.) ){
841 if ( in.
d0() != T(0.) ) test =
false;
843 if ( in.
d1() != T(0.) ) test =
false;
845 if ( in.
d2() != T(0.) ) test =
false;
847 if ( in.
d3() != T(0.) ) test =
false;
849 if ( in.
d4() != T(0.) ) test =
false;
851 if ( in.
d5() != T(0.) ) test =
false;
853 if ( in.
d6() != T(0.) ) test =
false;
855 if ( in.
d7() != T(0.) ) test =
false;
857 if ( in.
d8() != T(0.) ) test =
false;
859 if ( in.
d9() != T(0.) ) test =
false;
861 if ( in.
d10() != T(0.) ) test =
false;
864 error(
"TinyFad<11,T> sqrt (const TinyFad& in) : null value");
923 if ( in.
val() == 0)
error(
"TinyFad tan (const TinyFad& in) undiefined in 0.");
926 T cosinus =
cos(in.
val());
927 tmp.
d0() = in.
d0() / cosinus / cosinus;
928 tmp.
d1() = in.
d1() / cosinus / cosinus;
929 tmp.
d2() = in.
d2() / cosinus / cosinus;
930 tmp.
d3() = in.
d3() / cosinus / cosinus;
931 tmp.
d4() = in.
d4() / cosinus / cosinus;
932 tmp.
d5() = in.
d5() / cosinus / cosinus;
933 tmp.
d6() = in.
d6() / cosinus / cosinus;
934 tmp.
d7() = in.
d7() / cosinus / cosinus;
935 tmp.
d8() = in.
d8() / cosinus / cosinus;
936 tmp.
d9() = in.
d9() / cosinus / cosinus;
937 tmp.
d10() = in.
d10() / cosinus / cosinus;
963 if (un.
val() == 0)
error(
"TinyFad pow (const TinyFad& un, const TinyFad& deux), un = 0. ");
996 tmp.d0() = e*in.
d0()*
pow((
double)in.
val(), (double)e-1);
997 tmp.d1() = e*in.
d1()*
pow((
double)in.
val(), (double)e-1);
998 tmp.d2() = e*in.
d2()*
pow((
double)in.
val(), (double)e-1);
999 tmp.d3() = e*in.
d3()*
pow((
double)in.
val(), (double)e-1);
1000 tmp.d4() = e*in.
d4()*
pow((
double)in.
val(), (double)e-1);
1001 tmp.d5() = e*in.
d5()*
pow((
double)in.
val(), (double)e-1);
1002 tmp.d6() = e*in.
d6()*
pow((
double)in.
val(), (double)e-1);
1003 tmp.d7() = e*in.
d7()*
pow((
double)in.
val(), (double)e-1);
1004 tmp.d8() = e*in.
d8()*
pow((
double)in.
val(), (double)e-1);
1005 tmp.d9() = e*in.
d9()*
pow((
double)in.
val(), (double)e-1);
1006 tmp.d10() = e*in.
d10()*
pow((
double)in.
val(), (double)e-1);
1013 int sign = in.
val() > 0? 1:0;
1015 if (sign)
return in;
1019 template <
class T> std::ostream& operator << (std::ostream& os, const TinyFad<11,T>& a)
1021 os.setf(std::ios::fixed,std::ios::scientific);
1023 os << a.
val() <<
" [";
TinyFad< 11, T > & operator++()
TinyFad< 11, T > exp(const TinyFad< 11, T > &in)
void diff(const size_t ith, const size_t sz)
TinyFad< 11, typename NumericalTraits< L, R >::promote > operator/(const TinyFad< 11, L > &un, const TinyFad< 11, R > &deux)
TinyFad< Num, T > & operator-=(const TinyFad< Num, T > &in)
TinyFad(const T &ind, const int ini)
TinyFad< 11, T > & operator--()
AutoPointerMutexArrayInit tmp
const T & dx(int i) const
TinyFad< 11, T > tan(const TinyFad< 11, T > &in)
TinyFad< 11, T > log(const TinyFad< 11, T > &in)
TinyFad< 11, T > operator--(int)
TinyFad(const TinyFad< 11, T > &in)
TinyFad< 11, typename NumericalTraits< L, R >::promote > operator*(const TinyFad< 11, L > &un, const TinyFad< 11, R > &deux)
TinyFad< 11, T > operator+(const TinyFad< 11, T > &in)
TinyFad< Num, T > & operator=(const TinyFad< Num, T > &in)
TinyFad(const No_Initialization &)
TinyFad< Num, T > & operator+=(const TinyFad< Num, T > &in)
TinyFad< 11, T > operator++(int)
TinyFad< 11, T > abs(const TinyFad< 11, T > &in)
TinyFad< Num, T > & operator*=(const TinyFad< Num, T > &in)
TinyFad< 11, T > pow(const TinyFad< 11, T > &in, double e)
TinyFad< Num, T > & operator/=(const TinyFad< Num, T > &in)
TinyFad< 11, T > sqrt(const TinyFad< 11, T > &in)
TinyFad< 11, T > sin(const TinyFad< 11, T > &in)
TinyFad< 11, T > cos(const TinyFad< 11, T > &in)
TinyFad< 11, T > operator-(const TinyFad< 11, T > &in)