9 template <
class T>
class TinyFad<10,T> {
31 void diff(
const size_t ith,
const size_t sz){
45 case 0 : dx0_ = T(1.);
break;
46 case 1 : dx1_ = T(1.);
break;
47 case 2 : dx2_ = T(1.);
break;
48 case 3 : dx3_ = T(1.);
break;
49 case 4 : dx4_ = T(1.);
break;
50 case 5 : dx5_ = T(1.);
break;
51 case 6 : dx6_ = T(1.);
break;
52 case 7 : dx7_ = T(1.);
break;
53 case 8 : dx8_ = T(1.);
break;
54 case 9 : dx9_ = T(1.);
break;
55 default : cout <<
"ith = " << ith <<
" out of definition set" << endl;exit(1);
59 TinyFad(
const T& ind,
const int ini) : n(ini+1), val_(ind) {
72 case 0 : dx0_ = T(1.);
break;
73 case 1 : dx1_ = T(1.);
break;
74 case 2 : dx2_ = T(1.);
break;
75 case 3 : dx3_ = T(1.);
break;
76 case 4 : dx4_ = T(1.);
break;
77 case 5 : dx5_ = T(1.);
break;
78 case 6 : dx6_ = T(1.);
break;
79 case 7 : dx7_ = T(1.);
break;
80 case 8 : dx8_ = T(1.);
break;
81 case 9 : dx9_ = T(1.);
break;
82 default : cout <<
"ini = " << ini <<
" out of definition set" << endl;exit(1);
125 int N()
const {
return n-1;}
130 const T&
d0()
const {
return dx0_;}
131 T&
d0() {
return dx0_;}
133 const T&
d1()
const {
return dx1_;}
134 T&
d1() {
return dx1_;}
136 const T&
d2()
const {
return dx2_;}
137 T&
d2() {
return dx2_;}
139 const T&
d3()
const {
return dx3_;}
140 T&
d3() {
return dx3_;}
142 const T&
d4()
const {
return dx4_;}
143 T&
d4() {
return dx4_;}
145 const T&
d5()
const {
return dx5_;}
146 T&
d5() {
return dx5_;}
148 const T&
d6()
const {
return dx6_;}
149 T&
d6() {
return dx6_;}
151 const T&
d7()
const {
return dx7_;}
152 T&
d7() {
return dx7_;}
154 const T&
d8()
const {
return dx8_;}
155 T&
d8() {
return dx8_;}
157 const T&
d9()
const {
return dx9_;}
158 T&
d9() {
return dx9_;}
162 case 0 :
return dx0_;
163 case 1 :
return dx1_;
164 case 2 :
return dx2_;
165 case 3 :
return dx3_;
166 case 4 :
return dx4_;
167 case 5 :
return dx5_;
168 case 6 :
return dx6_;
169 case 7 :
return dx7_;
170 case 8 :
return dx8_;
171 case 9 :
return dx9_;
172 default : cout <<
"i out of bounds" << endl;exit(1);
175 const T&
dx(
int i)
const {
177 case 0 :
return dx0_;
178 case 1 :
return dx1_;
179 case 2 :
return dx2_;
180 case 3 :
return dx3_;
181 case 4 :
return dx4_;
182 case 5 :
return dx5_;
183 case 6 :
return dx6_;
184 case 7 :
return dx7_;
185 case 8 :
return dx8_;
186 case 9 :
return dx9_;
187 default : cout <<
"i out of bounds" << endl;exit(1);
192 case 0 :
return dx0_;
193 case 1 :
return dx1_;
194 case 2 :
return dx2_;
195 case 3 :
return dx3_;
196 case 4 :
return dx4_;
197 case 5 :
return dx5_;
198 case 6 :
return dx6_;
199 case 7 :
return dx7_;
200 case 8 :
return dx8_;
201 case 9 :
return dx9_;
202 default : cout <<
"i out of bounds" << endl;exit(1);
205 const T&
d(
int i)
const {
207 case 0 :
return dx0_;
208 case 1 :
return dx1_;
209 case 2 :
return dx2_;
210 case 3 :
return dx3_;
211 case 4 :
return dx4_;
212 case 5 :
return dx5_;
213 case 6 :
return dx6_;
214 case 7 :
return dx7_;
215 case 8 :
return dx8_;
216 case 9 :
return dx9_;
217 default : cout <<
"i out of bounds" << endl;exit(1);
287 dx0_ = dx0_ * in.
val_ + val_ * in.
dx0_;
288 dx1_ = dx1_ * in.
val_ + val_ * in.
dx1_;
289 dx2_ = dx2_ * in.
val_ + val_ * in.
dx2_;
290 dx3_ = dx3_ * in.
val_ + val_ * in.
dx3_;
291 dx4_ = dx4_ * in.
val_ + val_ * in.
dx4_;
292 dx5_ = dx5_ * in.
val_ + val_ * in.
dx5_;
293 dx6_ = dx6_ * in.
val_ + val_ * in.
dx6_;
294 dx7_ = dx7_ * in.
val_ + val_ * in.
dx7_;
295 dx8_ = dx8_ * in.
val_ + val_ * in.
dx8_;
296 dx9_ = dx9_ * in.
val_ + val_ * in.
dx9_;
302 if (in.
val_ == 0.)
error(
"TinyFad & TinyFad::operator /= (const TinyFad & in), dividing by 0");
343 if ( in == T(0.) )
error(
"TinyFad & TinyFad::operator /= (const T & in), dividing by 0");
391 template <
class L,
class R>
inline 400 tmp.d0() = un.d0() + deux.d0();
402 tmp.d1() = un.d1() + deux.d1();
404 tmp.d2() = un.d2() + deux.d2();
406 tmp.d3() = un.d3() + deux.d3();
408 tmp.d4() = un.d4() + deux.d4();
410 tmp.d5() = un.d5() + deux.d5();
412 tmp.d6() = un.d6() + deux.d6();
414 tmp.d7() = un.d7() + deux.d7();
416 tmp.d8() = un.d8() + deux.d8();
418 tmp.d9() = un.d9() + deux.d9();
425 template <
class L,
class R>
inline 454 tmp.
val() = un.
val() + deux;
459 template <
class L,
class R>
inline 465 template <
class L,
class R>
inline 474 tmp.d0() = un.d0()*deux.
val() + un.
val() * deux.d0();
476 tmp.d1() = un.d1()*deux.
val() + un.
val() * deux.d1();
478 tmp.d2() = un.d2()*deux.
val() + un.
val() * deux.d2();
480 tmp.d3() = un.d3()*deux.
val() + un.
val() * deux.d3();
482 tmp.d4() = un.d4()*deux.
val() + un.
val() * deux.d4();
484 tmp.d5() = un.d5()*deux.
val() + un.
val() * deux.d5();
486 tmp.d6() = un.d6()*deux.
val() + un.
val() * deux.d6();
488 tmp.d7() = un.d7()*deux.
val() + un.
val() * deux.d7();
490 tmp.d8() = un.d8()*deux.
val() + un.
val() * deux.d8();
492 tmp.d9() = un.d9()*deux.
val() + un.
val() * deux.d9();
499 template <
class L,
class R>
inline 508 tmp.d0() = un.d0()*deux;
510 tmp.d1() = un.d1()*deux;
512 tmp.d2() = un.d2()*deux;
514 tmp.d3() = un.d3()*deux;
516 tmp.d4() = un.d4()*deux;
518 tmp.d5() = un.d5()*deux;
520 tmp.d6() = un.d6()*deux;
522 tmp.d7() = un.d7()*deux;
524 tmp.d8() = un.d8()*deux;
526 tmp.d9() = un.d9()*deux;
528 tmp.
val() = un.
val() * deux;
533 template <
class L,
class R>
inline 541 template <
class L,
class R>
inline 550 tmp.d0() = un.d0() - deux.d0();
552 tmp.d1() = un.d1() - deux.d1();
554 tmp.d2() = un.d2() - deux.d2();
556 tmp.d3() = un.d3() - deux.d3();
558 tmp.d4() = un.d4() - deux.d4();
560 tmp.d5() = un.d5() - deux.d5();
562 tmp.d6() = un.d6() - deux.d6();
564 tmp.d7() = un.d7() - deux.d7();
566 tmp.d8() = un.d8() - deux.d8();
568 tmp.d9() = un.d9() - deux.d9();
575 template <
class L,
class R>
inline 584 tmp.d0() -= deux.d0();
586 tmp.d1() -= deux.d1();
588 tmp.d2() -= deux.d2();
590 tmp.d3() -= deux.d3();
592 tmp.d4() -= deux.d4();
594 tmp.d5() -= deux.d5();
596 tmp.d6() -= deux.d6();
598 tmp.d7() -= deux.d7();
600 tmp.d8() -= deux.d8();
602 tmp.d9() -= deux.d9();
604 tmp.
val() = un - deux.
val();
609 template <
class L,
class R>
inline 637 tmp.
val() = un.
val() - deux;
642 template <
class L,
class R>
inline 648 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<10,L> & un, const TinyFad<10,R> & deux), dividing by 0");
652 value_type dval = deux.
val();
654 tmp.d0() = ( un.d0()* deux.
val() - un.
val() * deux.d0() ) / dval / dval ;
656 tmp.d1() = ( un.d1()* deux.
val() - un.
val() * deux.d1() ) / dval / dval ;
658 tmp.d2() = ( un.d2()* deux.
val() - un.
val() * deux.d2() ) / dval / dval ;
660 tmp.d3() = ( un.d3()* deux.
val() - un.
val() * deux.d3() ) / dval / dval ;
662 tmp.d4() = ( un.d4()* deux.
val() - un.
val() * deux.d4() ) / dval / dval ;
664 tmp.d5() = ( un.d5()* deux.
val() - un.
val() * deux.d5() ) / dval / dval ;
666 tmp.d6() = ( un.d6()* deux.
val() - un.
val() * deux.d6() ) / dval / dval ;
668 tmp.d7() = ( un.d7()* deux.
val() - un.
val() * deux.d7() ) / dval / dval ;
670 tmp.d8() = ( un.d8()* deux.
val() - un.
val() * deux.d8() ) / dval / dval ;
672 tmp.d9() = ( un.d9()* deux.
val() - un.
val() * deux.d9() ) / dval / dval ;
674 tmp.
val() = un.
val() / dval;
679 template <
class L,
class R>
inline 685 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const L & un, const TinyFad<10,R> & deux), dividing by 0");
689 value_type dval = deux.
val();
691 tmp.d0() = - un * deux.d0() / dval / dval ;
693 tmp.d1() = - un * deux.d1() / dval / dval ;
695 tmp.d2() = - un * deux.d2() / dval / dval ;
697 tmp.d3() = - un * deux.d3() / dval / dval ;
699 tmp.d4() = - un * deux.d4() / dval / dval ;
701 tmp.d5() = - un * deux.d5() / dval / dval ;
703 tmp.d6() = - un * deux.d6() / dval / dval ;
705 tmp.d7() = - un * deux.d7() / dval / dval ;
707 tmp.d8() = - un * deux.d8() / dval / dval ;
709 tmp.d9() = - un * deux.d9() / dval / dval ;
711 tmp.
val() = un / dval;
716 template <
class L,
class R>
inline 722 if (deux == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<10,L> & un, const R & deux), dividing by 0");
727 tmp.d0() = un.d0() / deux;
729 tmp.d1() = un.d1() / deux;
731 tmp.d2() = un.d2() / deux;
733 tmp.d3() = un.d3() / deux;
735 tmp.d4() = un.d4() / deux;
737 tmp.d5() = un.d5() / deux;
739 tmp.d6() = un.d6() / deux;
741 tmp.d7() = un.d7() / deux;
743 tmp.d8() = un.d8() / deux;
745 tmp.d9() = un.d9() / deux;
747 tmp.
val() = un.
val() / deux;
772 if ( in.
val() <= 0)
error(
"TinyFad log (const TinyFad& in) : zero or negative value");
791 if ( in.
val() < 0. )
error(
"TinyFad<10,T> sqrt (const TinyFad& in) : negative value");
795 if ( in.
val() == T(0.) ){
796 if ( in.
d0() != T(0.) ) test =
false;
798 if ( in.
d1() != T(0.) ) test =
false;
800 if ( in.
d2() != T(0.) ) test =
false;
802 if ( in.
d3() != T(0.) ) test =
false;
804 if ( in.
d4() != T(0.) ) test =
false;
806 if ( in.
d5() != T(0.) ) test =
false;
808 if ( in.
d6() != T(0.) ) test =
false;
810 if ( in.
d7() != T(0.) ) test =
false;
812 if ( in.
d8() != T(0.) ) test =
false;
814 if ( in.
d9() != T(0.) ) test =
false;
817 error(
"TinyFad<10,T> sqrt (const TinyFad& in) : null value");
873 if ( in.
val() == 0)
error(
"TinyFad tan (const TinyFad& in) undiefined in 0.");
876 T cosinus =
cos(in.
val());
877 tmp.
d0() = in.
d0() / cosinus / cosinus;
878 tmp.
d1() = in.
d1() / cosinus / cosinus;
879 tmp.
d2() = in.
d2() / cosinus / cosinus;
880 tmp.
d3() = in.
d3() / cosinus / cosinus;
881 tmp.
d4() = in.
d4() / cosinus / cosinus;
882 tmp.
d5() = in.
d5() / cosinus / cosinus;
883 tmp.
d6() = in.
d6() / cosinus / cosinus;
884 tmp.
d7() = in.
d7() / cosinus / cosinus;
885 tmp.
d8() = in.
d8() / cosinus / cosinus;
886 tmp.
d9() = in.
d9() / cosinus / cosinus;
911 if (un.
val() == 0)
error(
"TinyFad pow (const TinyFad& un, const TinyFad& deux), un = 0. ");
942 tmp.d0() = e*in.
d0()*
pow((
double)in.
val(), (double)e-1);
943 tmp.d1() = e*in.
d1()*
pow((
double)in.
val(), (double)e-1);
944 tmp.d2() = e*in.
d2()*
pow((
double)in.
val(), (double)e-1);
945 tmp.d3() = e*in.
d3()*
pow((
double)in.
val(), (double)e-1);
946 tmp.d4() = e*in.
d4()*
pow((
double)in.
val(), (double)e-1);
947 tmp.d5() = e*in.
d5()*
pow((
double)in.
val(), (double)e-1);
948 tmp.d6() = e*in.
d6()*
pow((
double)in.
val(), (double)e-1);
949 tmp.d7() = e*in.
d7()*
pow((
double)in.
val(), (double)e-1);
950 tmp.d8() = e*in.
d8()*
pow((
double)in.
val(), (double)e-1);
951 tmp.d9() = e*in.
d9()*
pow((
double)in.
val(), (double)e-1);
958 int sign = in.
val() > 0? 1:0;
964 template <
class T> std::ostream& operator << (std::ostream& os, const TinyFad<10,T>& a)
966 os.setf(std::ios::fixed,std::ios::scientific);
968 os << a.
val() <<
" [";
const T & dx(int i) const
TinyFad(const T &ind, const int ini)
TinyFad< 10, T > operator-(const TinyFad< 10, T > &in)
TinyFad< 10, T > operator+(const TinyFad< 10, T > &in)
TinyFad< 10, T > sin(const TinyFad< 10, T > &in)
TinyFad< Num, T > & operator-=(const TinyFad< Num, T > &in)
TinyFad< 10, typename NumericalTraits< L, R >::promote > operator*(const TinyFad< 10, L > &un, const TinyFad< 10, R > &deux)
TinyFad(const TinyFad< 10, T > &in)
AutoPointerMutexArrayInit tmp
TinyFad< 10, T > abs(const TinyFad< 10, T > &in)
void diff(const size_t ith, const size_t sz)
TinyFad(const No_Initialization &)
TinyFad< 10, T > operator--(int)
TinyFad< 10, T > & operator++()
TinyFad< 10, T > & operator--()
TinyFad< 10, T > cos(const TinyFad< 10, T > &in)
TinyFad< 10, T > operator++(int)
TinyFad< 10, typename NumericalTraits< L, R >::promote > operator/(const TinyFad< 10, L > &un, const TinyFad< 10, R > &deux)
TinyFad< Num, T > & operator=(const TinyFad< Num, T > &in)
TinyFad< 10, T > sqrt(const TinyFad< 10, T > &in)
TinyFad< Num, T > & operator+=(const TinyFad< Num, T > &in)
TinyFad< Num, T > & operator*=(const TinyFad< Num, T > &in)
TinyFad< 10, T > tan(const TinyFad< 10, T > &in)
TinyFad< Num, T > & operator/=(const TinyFad< Num, T > &in)
TinyFad< 10, T > log(const TinyFad< 10, T > &in)
TinyFad< 10, T > pow(const TinyFad< 10, T > &in, double e)
TinyFad< 10, T > exp(const TinyFad< 10, T > &in)