1 #ifndef _tinyfadtwelve_h_ 2 #define _tinyfadtwelve_h_ 9 template <
class T>
class TinyFad<12,T> {
33 void diff(
const size_t ith,
const size_t sz){
49 case 0 : dx0_ = T(1.);
break;
50 case 1 : dx1_ = T(1.);
break;
51 case 2 : dx2_ = T(1.);
break;
52 case 3 : dx3_ = T(1.);
break;
53 case 4 : dx4_ = T(1.);
break;
54 case 5 : dx5_ = T(1.);
break;
55 case 6 : dx6_ = T(1.);
break;
56 case 7 : dx7_ = T(1.);
break;
57 case 8 : dx8_ = T(1.);
break;
58 case 9 : dx9_ = T(1.);
break;
59 case 10 : dx10_ = T(1.);
break;
60 case 11 : dx11_ = T(1.);
break;
61 default : cout <<
"ith = " << ith <<
" out of definition set" << endl;exit(1);
65 TinyFad(
const T& ind,
const int ini) : n(ini+1), val_(ind) {
80 case 0 : dx0_ = T(1.);
break;
81 case 1 : dx1_ = T(1.);
break;
82 case 2 : dx2_ = T(1.);
break;
83 case 3 : dx3_ = T(1.);
break;
84 case 4 : dx4_ = T(1.);
break;
85 case 5 : dx5_ = T(1.);
break;
86 case 6 : dx6_ = T(1.);
break;
87 case 7 : dx7_ = T(1.);
break;
88 case 8 : dx8_ = T(1.);
break;
89 case 9 : dx9_ = T(1.);
break;
90 case 10 : dx10_ = T(1.);
break;
91 case 11 : dx11_ = T(1.);
break;
92 default : cout <<
"ini = " << ini <<
" out of definition set" << endl;exit(1);
141 int N()
const {
return n-1;}
146 const T&
d0()
const {
return dx0_;}
147 T&
d0() {
return dx0_;}
149 const T&
d1()
const {
return dx1_;}
150 T&
d1() {
return dx1_;}
152 const T&
d2()
const {
return dx2_;}
153 T&
d2() {
return dx2_;}
155 const T&
d3()
const {
return dx3_;}
156 T&
d3() {
return dx3_;}
158 const T&
d4()
const {
return dx4_;}
159 T&
d4() {
return dx4_;}
161 const T&
d5()
const {
return dx5_;}
162 T&
d5() {
return dx5_;}
164 const T&
d6()
const {
return dx6_;}
165 T&
d6() {
return dx6_;}
167 const T&
d7()
const {
return dx7_;}
168 T&
d7() {
return dx7_;}
170 const T&
d8()
const {
return dx8_;}
171 T&
d8() {
return dx8_;}
173 const T&
d9()
const {
return dx9_;}
174 T&
d9() {
return dx9_;}
176 const T&
d10()
const {
return dx10_;}
179 const T&
d11()
const {
return dx11_;}
184 case 0 :
return dx0_;
185 case 1 :
return dx1_;
186 case 2 :
return dx2_;
187 case 3 :
return dx3_;
188 case 4 :
return dx4_;
189 case 5 :
return dx5_;
190 case 6 :
return dx6_;
191 case 7 :
return dx7_;
192 case 8 :
return dx8_;
193 case 9 :
return dx9_;
194 case 10 :
return dx10_;
195 case 11 :
return dx11_;
196 default : cout <<
"i out of bounds" << endl;exit(1);
199 const T&
dx(
int i)
const {
201 case 0 :
return dx0_;
202 case 1 :
return dx1_;
203 case 2 :
return dx2_;
204 case 3 :
return dx3_;
205 case 4 :
return dx4_;
206 case 5 :
return dx5_;
207 case 6 :
return dx6_;
208 case 7 :
return dx7_;
209 case 8 :
return dx8_;
210 case 9 :
return dx9_;
211 case 10 :
return dx10_;
212 case 11 :
return dx11_;
213 default : cout <<
"i out of bounds" << endl;exit(1);
218 case 0 :
return dx0_;
219 case 1 :
return dx1_;
220 case 2 :
return dx2_;
221 case 3 :
return dx3_;
222 case 4 :
return dx4_;
223 case 5 :
return dx5_;
224 case 6 :
return dx6_;
225 case 7 :
return dx7_;
226 case 8 :
return dx8_;
227 case 9 :
return dx9_;
228 case 10 :
return dx10_;
229 case 11 :
return dx11_;
230 default : cout <<
"i out of bounds" << endl;exit(1);
233 const T&
d(
int i)
const {
235 case 0 :
return dx0_;
236 case 1 :
return dx1_;
237 case 2 :
return dx2_;
238 case 3 :
return dx3_;
239 case 4 :
return dx4_;
240 case 5 :
return dx5_;
241 case 6 :
return dx6_;
242 case 7 :
return dx7_;
243 case 8 :
return dx8_;
244 case 9 :
return dx9_;
245 case 10 :
return dx10_;
246 case 11 :
return dx11_;
247 default : cout <<
"i out of bounds" << endl;exit(1);
325 dx0_ = dx0_ * in.
val_ + val_ * in.
dx0_;
326 dx1_ = dx1_ * in.
val_ + val_ * in.
dx1_;
327 dx2_ = dx2_ * in.
val_ + val_ * in.
dx2_;
328 dx3_ = dx3_ * in.
val_ + val_ * in.
dx3_;
329 dx4_ = dx4_ * in.
val_ + val_ * in.
dx4_;
330 dx5_ = dx5_ * in.
val_ + val_ * in.
dx5_;
331 dx6_ = dx6_ * in.
val_ + val_ * in.
dx6_;
332 dx7_ = dx7_ * in.
val_ + val_ * in.
dx7_;
333 dx8_ = dx8_ * in.
val_ + val_ * in.
dx8_;
334 dx9_ = dx9_ * in.
val_ + val_ * in.
dx9_;
335 dx10_ = dx10_ * in.
val_ + val_ * in.
dx10_;
336 dx11_ = dx11_ * in.
val_ + val_ * in.
dx11_;
342 if (in.
val_ == 0.)
error(
"TinyFad & TinyFad::operator /= (const TinyFad & in), dividing by 0");
387 if ( in == T(0.) )
error(
"TinyFad & TinyFad::operator /= (const T & in), dividing by 0");
437 template <
class L,
class R>
inline 446 tmp.d0() = un.d0() + deux.d0();
448 tmp.d1() = un.d1() + deux.d1();
450 tmp.d2() = un.d2() + deux.d2();
452 tmp.d3() = un.d3() + deux.d3();
454 tmp.d4() = un.d4() + deux.d4();
456 tmp.d5() = un.d5() + deux.d5();
458 tmp.d6() = un.d6() + deux.d6();
460 tmp.d7() = un.d7() + deux.d7();
462 tmp.d8() = un.d8() + deux.d8();
464 tmp.d9() = un.d9() + deux.d9();
466 tmp.d10() = un.d10() + deux.d10();
468 tmp.d11() = un.d11() + deux.d11();
475 template <
class L,
class R>
inline 504 tmp.d10() = un.d10();
506 tmp.d11() = un.d11();
508 tmp.
val() = un.
val() + deux;
513 template <
class L,
class R>
inline 519 template <
class L,
class R>
inline 528 tmp.d0() = un.d0()*deux.
val() + un.
val() * deux.d0();
530 tmp.d1() = un.d1()*deux.
val() + un.
val() * deux.d1();
532 tmp.d2() = un.d2()*deux.
val() + un.
val() * deux.d2();
534 tmp.d3() = un.d3()*deux.
val() + un.
val() * deux.d3();
536 tmp.d4() = un.d4()*deux.
val() + un.
val() * deux.d4();
538 tmp.d5() = un.d5()*deux.
val() + un.
val() * deux.d5();
540 tmp.d6() = un.d6()*deux.
val() + un.
val() * deux.d6();
542 tmp.d7() = un.d7()*deux.
val() + un.
val() * deux.d7();
544 tmp.d8() = un.d8()*deux.
val() + un.
val() * deux.d8();
546 tmp.d9() = un.d9()*deux.
val() + un.
val() * deux.d9();
548 tmp.d10() = un.d10()*deux.
val() + un.
val() * deux.d10();
550 tmp.d11() = un.d11()*deux.
val() + un.
val() * deux.d11();
557 template <
class L,
class R>
inline 566 tmp.d0() = un.d0()*deux;
568 tmp.d1() = un.d1()*deux;
570 tmp.d2() = un.d2()*deux;
572 tmp.d3() = un.d3()*deux;
574 tmp.d4() = un.d4()*deux;
576 tmp.d5() = un.d5()*deux;
578 tmp.d6() = un.d6()*deux;
580 tmp.d7() = un.d7()*deux;
582 tmp.d8() = un.d8()*deux;
584 tmp.d9() = un.d9()*deux;
586 tmp.d10() = un.d10()*deux;
588 tmp.d11() = un.d11()*deux;
590 tmp.
val() = un.
val() * deux;
595 template <
class L,
class R>
inline 603 template <
class L,
class R>
inline 612 tmp.d0() = un.d0() - deux.d0();
614 tmp.d1() = un.d1() - deux.d1();
616 tmp.d2() = un.d2() - deux.d2();
618 tmp.d3() = un.d3() - deux.d3();
620 tmp.d4() = un.d4() - deux.d4();
622 tmp.d5() = un.d5() - deux.d5();
624 tmp.d6() = un.d6() - deux.d6();
626 tmp.d7() = un.d7() - deux.d7();
628 tmp.d8() = un.d8() - deux.d8();
630 tmp.d9() = un.d9() - deux.d9();
632 tmp.d10() = un.d10() - deux.d10();
634 tmp.d11() = un.d11() - deux.d11();
641 template <
class L,
class R>
inline 650 tmp.d0() -= deux.d0();
652 tmp.d1() -= deux.d1();
654 tmp.d2() -= deux.d2();
656 tmp.d3() -= deux.d3();
658 tmp.d4() -= deux.d4();
660 tmp.d5() -= deux.d5();
662 tmp.d6() -= deux.d6();
664 tmp.d7() -= deux.d7();
666 tmp.d8() -= deux.d8();
668 tmp.d9() -= deux.d9();
670 tmp.d10() -= deux.d10();
672 tmp.d11() -= deux.d11();
674 tmp.
val() = un - deux.
val();
679 template <
class L,
class R>
inline 707 tmp.d10() = un.d10();
709 tmp.d11() = un.d11();
711 tmp.
val() = un.
val() - deux;
716 template <
class L,
class R>
inline 722 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<12,L> & un, const TinyFad<12,R> & deux), dividing by 0");
726 value_type dval = deux.
val();
728 tmp.d0() = ( un.d0()* deux.
val() - un.
val() * deux.d0() ) / dval / dval ;
730 tmp.d1() = ( un.d1()* deux.
val() - un.
val() * deux.d1() ) / dval / dval ;
732 tmp.d2() = ( un.d2()* deux.
val() - un.
val() * deux.d2() ) / dval / dval ;
734 tmp.d3() = ( un.d3()* deux.
val() - un.
val() * deux.d3() ) / dval / dval ;
736 tmp.d4() = ( un.d4()* deux.
val() - un.
val() * deux.d4() ) / dval / dval ;
738 tmp.d5() = ( un.d5()* deux.
val() - un.
val() * deux.d5() ) / dval / dval ;
740 tmp.d6() = ( un.d6()* deux.
val() - un.
val() * deux.d6() ) / dval / dval ;
742 tmp.d7() = ( un.d7()* deux.
val() - un.
val() * deux.d7() ) / dval / dval ;
744 tmp.d8() = ( un.d8()* deux.
val() - un.
val() * deux.d8() ) / dval / dval ;
746 tmp.d9() = ( un.d9()* deux.
val() - un.
val() * deux.d9() ) / dval / dval ;
748 tmp.d10() = ( un.d10()* deux.
val() - un.
val() * deux.d10() ) / dval / dval ;
750 tmp.d11() = ( un.d11()* deux.
val() - un.
val() * deux.d11() ) / dval / dval ;
752 tmp.
val() = un.
val() / dval;
757 template <
class L,
class R>
inline 763 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const L & un, const TinyFad<12,R> & deux), dividing by 0");
767 value_type dval = deux.
val();
769 tmp.d0() = - un * deux.d0() / dval / dval ;
771 tmp.d1() = - un * deux.d1() / dval / dval ;
773 tmp.d2() = - un * deux.d2() / dval / dval ;
775 tmp.d3() = - un * deux.d3() / dval / dval ;
777 tmp.d4() = - un * deux.d4() / dval / dval ;
779 tmp.d5() = - un * deux.d5() / dval / dval ;
781 tmp.d6() = - un * deux.d6() / dval / dval ;
783 tmp.d7() = - un * deux.d7() / dval / dval ;
785 tmp.d8() = - un * deux.d8() / dval / dval ;
787 tmp.d9() = - un * deux.d9() / dval / dval ;
789 tmp.d10() = - un * deux.d10() / dval / dval ;
791 tmp.d11() = - un * deux.d11() / dval / dval ;
793 tmp.
val() = un / dval;
798 template <
class L,
class R>
inline 804 if (deux == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<12,L> & un, const R & deux), dividing by 0");
809 tmp.d0() = un.d0() / deux;
811 tmp.d1() = un.d1() / deux;
813 tmp.d2() = un.d2() / deux;
815 tmp.d3() = un.d3() / deux;
817 tmp.d4() = un.d4() / deux;
819 tmp.d5() = un.d5() / deux;
821 tmp.d6() = un.d6() / deux;
823 tmp.d7() = un.d7() / deux;
825 tmp.d8() = un.d8() / deux;
827 tmp.d9() = un.d9() / deux;
829 tmp.d10() = un.d10() / deux;
831 tmp.d11() = un.d11() / deux;
833 tmp.
val() = un.
val() / deux;
860 if ( in.
val() <= 0)
error(
"TinyFad log (const TinyFad& in) : zero or negative value");
881 if ( in.
val() < 0. )
error(
"TinyFad<12,T> sqrt (const TinyFad& in) : negative value");
885 if ( in.
val() == T(0.) ){
886 if ( in.
d0() != T(0.) ) test =
false;
888 if ( in.
d1() != T(0.) ) test =
false;
890 if ( in.
d2() != T(0.) ) test =
false;
892 if ( in.
d3() != T(0.) ) test =
false;
894 if ( in.
d4() != T(0.) ) test =
false;
896 if ( in.
d5() != T(0.) ) test =
false;
898 if ( in.
d6() != T(0.) ) test =
false;
900 if ( in.
d7() != T(0.) ) test =
false;
902 if ( in.
d8() != T(0.) ) test =
false;
904 if ( in.
d9() != T(0.) ) test =
false;
906 if ( in.
d10() != T(0.) ) test =
false;
908 if ( in.
d11() != T(0.) ) test =
false;
911 error(
"TinyFad<12,T> sqrt (const TinyFad& in) : null value");
973 if ( in.
val() == 0)
error(
"TinyFad tan (const TinyFad& in) undiefined in 0.");
976 T cosinus =
cos(in.
val());
977 tmp.
d0() = in.
d0() / cosinus / cosinus;
978 tmp.
d1() = in.
d1() / cosinus / cosinus;
979 tmp.
d2() = in.
d2() / cosinus / cosinus;
980 tmp.
d3() = in.
d3() / cosinus / cosinus;
981 tmp.
d4() = in.
d4() / cosinus / cosinus;
982 tmp.
d5() = in.
d5() / cosinus / cosinus;
983 tmp.
d6() = in.
d6() / cosinus / cosinus;
984 tmp.
d7() = in.
d7() / cosinus / cosinus;
985 tmp.
d8() = in.
d8() / cosinus / cosinus;
986 tmp.
d9() = in.
d9() / cosinus / cosinus;
987 tmp.
d10() = in.
d10() / cosinus / cosinus;
988 tmp.
d11() = in.
d11() / cosinus / cosinus;
1015 if (un.
val() == 0)
error(
"TinyFad pow (const TinyFad& un, const TinyFad& deux), un = 0. ");
1050 tmp.d0() = e*in.
d0()*
pow((
double)in.
val(), (double)e-1);
1051 tmp.d1() = e*in.
d1()*
pow((
double)in.
val(), (double)e-1);
1052 tmp.d2() = e*in.
d2()*
pow((
double)in.
val(), (double)e-1);
1053 tmp.d3() = e*in.
d3()*
pow((
double)in.
val(), (double)e-1);
1054 tmp.d4() = e*in.
d4()*
pow((
double)in.
val(), (double)e-1);
1055 tmp.d5() = e*in.
d5()*
pow((
double)in.
val(), (double)e-1);
1056 tmp.d6() = e*in.
d6()*
pow((
double)in.
val(), (double)e-1);
1057 tmp.d7() = e*in.
d7()*
pow((
double)in.
val(), (double)e-1);
1058 tmp.d8() = e*in.
d8()*
pow((
double)in.
val(), (double)e-1);
1059 tmp.d9() = e*in.
d9()*
pow((
double)in.
val(), (double)e-1);
1060 tmp.d10() = e*in.
d10()*
pow((
double)in.
val(), (double)e-1);
1061 tmp.d11() = e*in.
d11()*
pow((
double)in.
val(), (double)e-1);
1068 int sign = in.
val() > 0? 1:0;
1070 if (sign)
return in;
1074 template <
class T> std::ostream& operator << (std::ostream& os, const TinyFad<12,T>& a)
1076 os.setf(std::ios::fixed,std::ios::scientific);
1078 os << a.
val() <<
" [";
TinyFad< 12, T > & operator++()
TinyFad< 12, T > exp(const TinyFad< 12, T > &in)
TinyFad< Num, T > & operator-=(const TinyFad< Num, T > &in)
AutoPointerMutexArrayInit tmp
TinyFad< 12, T > sqrt(const TinyFad< 12, T > &in)
TinyFad< 12, T > operator--(int)
TinyFad< 12, T > abs(const TinyFad< 12, T > &in)
TinyFad< 12, T > tan(const TinyFad< 12, T > &in)
TinyFad< 12, T > cos(const TinyFad< 12, T > &in)
TinyFad< 12, T > operator-(const TinyFad< 12, T > &in)
TinyFad< 12, T > log(const TinyFad< 12, T > &in)
TinyFad< Num, T > & operator=(const TinyFad< Num, T > &in)
TinyFad< 12, T > operator++(int)
TinyFad< 12, typename NumericalTraits< L, R >::promote > operator*(const TinyFad< 12, L > &un, const TinyFad< 12, R > &deux)
TinyFad< 12, T > operator+(const TinyFad< 12, T > &in)
TinyFad< Num, T > & operator+=(const TinyFad< Num, T > &in)
TinyFad< Num, T > & operator*=(const TinyFad< Num, T > &in)
TinyFad< 12, T > pow(const TinyFad< 12, T > &in, double e)
TinyFad< 12, T > & operator--()
TinyFad< 12, T > sin(const TinyFad< 12, T > &in)
TinyFad(const T &ind, const int ini)
const T & dx(int i) const
TinyFad< Num, T > & operator/=(const TinyFad< Num, T > &in)
TinyFad(const No_Initialization &)
void diff(const size_t ith, const size_t sz)
TinyFad(const TinyFad< 12, T > &in)
TinyFad< 12, typename NumericalTraits< L, R >::promote > operator/(const TinyFad< 12, L > &un, const TinyFad< 12, R > &deux)