1 #ifndef _tinyfadfourteen_h_ 2 #define _tinyfadfourteen_h_ 9 template <
class T>
class TinyFad<14,T> {
35 void diff(
const size_t ith,
const size_t sz){
53 case 0 : dx0_ = T(1.);
break;
54 case 1 : dx1_ = T(1.);
break;
55 case 2 : dx2_ = T(1.);
break;
56 case 3 : dx3_ = T(1.);
break;
57 case 4 : dx4_ = T(1.);
break;
58 case 5 : dx5_ = T(1.);
break;
59 case 6 : dx6_ = T(1.);
break;
60 case 7 : dx7_ = T(1.);
break;
61 case 8 : dx8_ = T(1.);
break;
62 case 9 : dx9_ = T(1.);
break;
63 case 10 : dx10_ = T(1.);
break;
64 case 11 : dx11_ = T(1.);
break;
65 case 12 : dx12_ = T(1.);
break;
66 case 13 : dx13_ = T(1.);
break;
67 default : cout <<
"ith = " << ith <<
" out of definition set" << endl;exit(1);
71 TinyFad(
const T& ind,
const int ini) : n(ini+1), val_(ind) {
88 case 0 : dx0_ = T(1.);
break;
89 case 1 : dx1_ = T(1.);
break;
90 case 2 : dx2_ = T(1.);
break;
91 case 3 : dx3_ = T(1.);
break;
92 case 4 : dx4_ = T(1.);
break;
93 case 5 : dx5_ = T(1.);
break;
94 case 6 : dx6_ = T(1.);
break;
95 case 7 : dx7_ = T(1.);
break;
96 case 8 : dx8_ = T(1.);
break;
97 case 9 : dx9_ = T(1.);
break;
98 case 10 : dx10_ = T(1.);
break;
99 case 11 : dx11_ = T(1.);
break;
100 case 12 : dx12_ = T(1.);
break;
101 case 13 : dx13_ = T(1.);
break;
102 default : cout <<
"ini = " << ini <<
" out of definition set" << endl;exit(1);
157 int N()
const {
return n-1;}
162 const T&
d0()
const {
return dx0_;}
163 T&
d0() {
return dx0_;}
165 const T&
d1()
const {
return dx1_;}
166 T&
d1() {
return dx1_;}
168 const T&
d2()
const {
return dx2_;}
169 T&
d2() {
return dx2_;}
171 const T&
d3()
const {
return dx3_;}
172 T&
d3() {
return dx3_;}
174 const T&
d4()
const {
return dx4_;}
175 T&
d4() {
return dx4_;}
177 const T&
d5()
const {
return dx5_;}
178 T&
d5() {
return dx5_;}
180 const T&
d6()
const {
return dx6_;}
181 T&
d6() {
return dx6_;}
183 const T&
d7()
const {
return dx7_;}
184 T&
d7() {
return dx7_;}
186 const T&
d8()
const {
return dx8_;}
187 T&
d8() {
return dx8_;}
189 const T&
d9()
const {
return dx9_;}
190 T&
d9() {
return dx9_;}
192 const T&
d10()
const {
return dx10_;}
195 const T&
d11()
const {
return dx11_;}
198 const T&
d12()
const {
return dx12_;}
201 const T&
d13()
const {
return dx13_;}
206 case 0 :
return dx0_;
207 case 1 :
return dx1_;
208 case 2 :
return dx2_;
209 case 3 :
return dx3_;
210 case 4 :
return dx4_;
211 case 5 :
return dx5_;
212 case 6 :
return dx6_;
213 case 7 :
return dx7_;
214 case 8 :
return dx8_;
215 case 9 :
return dx9_;
216 case 10 :
return dx10_;
217 case 11 :
return dx11_;
218 case 12 :
return dx12_;
219 case 13 :
return dx13_;
220 default : cout <<
"i out of bounds" << endl;exit(1);
223 const T&
dx(
int i)
const {
225 case 0 :
return dx0_;
226 case 1 :
return dx1_;
227 case 2 :
return dx2_;
228 case 3 :
return dx3_;
229 case 4 :
return dx4_;
230 case 5 :
return dx5_;
231 case 6 :
return dx6_;
232 case 7 :
return dx7_;
233 case 8 :
return dx8_;
234 case 9 :
return dx9_;
235 case 10 :
return dx10_;
236 case 11 :
return dx11_;
237 case 12 :
return dx12_;
238 case 13 :
return dx13_;
239 default : cout <<
"i out of bounds" << endl;exit(1);
244 case 0 :
return dx0_;
245 case 1 :
return dx1_;
246 case 2 :
return dx2_;
247 case 3 :
return dx3_;
248 case 4 :
return dx4_;
249 case 5 :
return dx5_;
250 case 6 :
return dx6_;
251 case 7 :
return dx7_;
252 case 8 :
return dx8_;
253 case 9 :
return dx9_;
254 case 10 :
return dx10_;
255 case 11 :
return dx11_;
256 case 12 :
return dx12_;
257 case 13 :
return dx13_;
258 default : cout <<
"i out of bounds" << endl;exit(1);
261 const T&
d(
int i)
const {
263 case 0 :
return dx0_;
264 case 1 :
return dx1_;
265 case 2 :
return dx2_;
266 case 3 :
return dx3_;
267 case 4 :
return dx4_;
268 case 5 :
return dx5_;
269 case 6 :
return dx6_;
270 case 7 :
return dx7_;
271 case 8 :
return dx8_;
272 case 9 :
return dx9_;
273 case 10 :
return dx10_;
274 case 11 :
return dx11_;
275 case 12 :
return dx12_;
276 case 13 :
return dx13_;
277 default : cout <<
"i out of bounds" << endl;exit(1);
363 dx0_ = dx0_ * in.
val_ + val_ * in.
dx0_;
364 dx1_ = dx1_ * in.
val_ + val_ * in.
dx1_;
365 dx2_ = dx2_ * in.
val_ + val_ * in.
dx2_;
366 dx3_ = dx3_ * in.
val_ + val_ * in.
dx3_;
367 dx4_ = dx4_ * in.
val_ + val_ * in.
dx4_;
368 dx5_ = dx5_ * in.
val_ + val_ * in.
dx5_;
369 dx6_ = dx6_ * in.
val_ + val_ * in.
dx6_;
370 dx7_ = dx7_ * in.
val_ + val_ * in.
dx7_;
371 dx8_ = dx8_ * in.
val_ + val_ * in.
dx8_;
372 dx9_ = dx9_ * in.
val_ + val_ * in.
dx9_;
373 dx10_ = dx10_ * in.
val_ + val_ * in.
dx10_;
374 dx11_ = dx11_ * in.
val_ + val_ * in.
dx11_;
375 dx12_ = dx12_ * in.
val_ + val_ * in.
dx12_;
376 dx13_ = dx13_ * in.
val_ + val_ * in.
dx13_;
382 if (in.
val_ == 0.)
error(
"TinyFad & TinyFad::operator /= (const TinyFad & in), dividing by 0");
431 if ( in == T(0.) )
error(
"TinyFad & TinyFad::operator /= (const T & in), dividing by 0");
483 template <
class L,
class R>
inline 492 tmp.d0() = un.d0() + deux.d0();
494 tmp.d1() = un.d1() + deux.d1();
496 tmp.d2() = un.d2() + deux.d2();
498 tmp.d3() = un.d3() + deux.d3();
500 tmp.d4() = un.d4() + deux.d4();
502 tmp.d5() = un.d5() + deux.d5();
504 tmp.d6() = un.d6() + deux.d6();
506 tmp.d7() = un.d7() + deux.d7();
508 tmp.d8() = un.d8() + deux.d8();
510 tmp.d9() = un.d9() + deux.d9();
512 tmp.d10() = un.d10() + deux.d10();
514 tmp.d11() = un.d11() + deux.d11();
516 tmp.d12() = un.d12() + deux.d12();
518 tmp.d13() = un.d13() + deux.d13();
525 template <
class L,
class R>
inline 554 tmp.d10() = un.d10();
556 tmp.d11() = un.d11();
558 tmp.d12() = un.d12();
560 tmp.d13() = un.d13();
562 tmp.
val() = un.
val() + deux;
567 template <
class L,
class R>
inline 573 template <
class L,
class R>
inline 582 tmp.d0() = un.d0()*deux.
val() + un.
val() * deux.d0();
584 tmp.d1() = un.d1()*deux.
val() + un.
val() * deux.d1();
586 tmp.d2() = un.d2()*deux.
val() + un.
val() * deux.d2();
588 tmp.d3() = un.d3()*deux.
val() + un.
val() * deux.d3();
590 tmp.d4() = un.d4()*deux.
val() + un.
val() * deux.d4();
592 tmp.d5() = un.d5()*deux.
val() + un.
val() * deux.d5();
594 tmp.d6() = un.d6()*deux.
val() + un.
val() * deux.d6();
596 tmp.d7() = un.d7()*deux.
val() + un.
val() * deux.d7();
598 tmp.d8() = un.d8()*deux.
val() + un.
val() * deux.d8();
600 tmp.d9() = un.d9()*deux.
val() + un.
val() * deux.d9();
602 tmp.d10() = un.d10()*deux.
val() + un.
val() * deux.d10();
604 tmp.d11() = un.d11()*deux.
val() + un.
val() * deux.d11();
606 tmp.d12() = un.d12()*deux.
val() + un.
val() * deux.d12();
608 tmp.d13() = un.d13()*deux.
val() + un.
val() * deux.d13();
615 template <
class L,
class R>
inline 624 tmp.d0() = un.d0()*deux;
626 tmp.d1() = un.d1()*deux;
628 tmp.d2() = un.d2()*deux;
630 tmp.d3() = un.d3()*deux;
632 tmp.d4() = un.d4()*deux;
634 tmp.d5() = un.d5()*deux;
636 tmp.d6() = un.d6()*deux;
638 tmp.d7() = un.d7()*deux;
640 tmp.d8() = un.d8()*deux;
642 tmp.d9() = un.d9()*deux;
644 tmp.d10() = un.d10()*deux;
646 tmp.d11() = un.d11()*deux;
648 tmp.d12() = un.d12()*deux;
650 tmp.d13() = un.d13()*deux;
652 tmp.
val() = un.
val() * deux;
657 template <
class L,
class R>
inline 665 template <
class L,
class R>
inline 674 tmp.d0() = un.d0() - deux.d0();
676 tmp.d1() = un.d1() - deux.d1();
678 tmp.d2() = un.d2() - deux.d2();
680 tmp.d3() = un.d3() - deux.d3();
682 tmp.d4() = un.d4() - deux.d4();
684 tmp.d5() = un.d5() - deux.d5();
686 tmp.d6() = un.d6() - deux.d6();
688 tmp.d7() = un.d7() - deux.d7();
690 tmp.d8() = un.d8() - deux.d8();
692 tmp.d9() = un.d9() - deux.d9();
694 tmp.d10() = un.d10() - deux.d10();
696 tmp.d11() = un.d11() - deux.d11();
698 tmp.d12() = un.d12() - deux.d12();
700 tmp.d13() = un.d13() - deux.d13();
707 template <
class L,
class R>
inline 716 tmp.d0() -= deux.d0();
718 tmp.d1() -= deux.d1();
720 tmp.d2() -= deux.d2();
722 tmp.d3() -= deux.d3();
724 tmp.d4() -= deux.d4();
726 tmp.d5() -= deux.d5();
728 tmp.d6() -= deux.d6();
730 tmp.d7() -= deux.d7();
732 tmp.d8() -= deux.d8();
734 tmp.d9() -= deux.d9();
736 tmp.d10() -= deux.d10();
738 tmp.d11() -= deux.d11();
740 tmp.d12() -= deux.d12();
742 tmp.d13() -= deux.d13();
744 tmp.
val() = un - deux.
val();
749 template <
class L,
class R>
inline 777 tmp.d10() = un.d10();
779 tmp.d11() = un.d11();
781 tmp.d12() = un.d12();
783 tmp.d13() = un.d13();
785 tmp.
val() = un.
val() - deux;
790 template <
class L,
class R>
inline 796 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<14,L> & un, const TinyFad<14,R> & deux), dividing by 0");
800 value_type dval = deux.
val();
802 tmp.d0() = ( un.d0()* deux.
val() - un.
val() * deux.d0() ) / dval / dval ;
804 tmp.d1() = ( un.d1()* deux.
val() - un.
val() * deux.d1() ) / dval / dval ;
806 tmp.d2() = ( un.d2()* deux.
val() - un.
val() * deux.d2() ) / dval / dval ;
808 tmp.d3() = ( un.d3()* deux.
val() - un.
val() * deux.d3() ) / dval / dval ;
810 tmp.d4() = ( un.d4()* deux.
val() - un.
val() * deux.d4() ) / dval / dval ;
812 tmp.d5() = ( un.d5()* deux.
val() - un.
val() * deux.d5() ) / dval / dval ;
814 tmp.d6() = ( un.d6()* deux.
val() - un.
val() * deux.d6() ) / dval / dval ;
816 tmp.d7() = ( un.d7()* deux.
val() - un.
val() * deux.d7() ) / dval / dval ;
818 tmp.d8() = ( un.d8()* deux.
val() - un.
val() * deux.d8() ) / dval / dval ;
820 tmp.d9() = ( un.d9()* deux.
val() - un.
val() * deux.d9() ) / dval / dval ;
822 tmp.d10() = ( un.d10()* deux.
val() - un.
val() * deux.d10() ) / dval / dval ;
824 tmp.d11() = ( un.d11()* deux.
val() - un.
val() * deux.d11() ) / dval / dval ;
826 tmp.d12() = ( un.d12()* deux.
val() - un.
val() * deux.d12() ) / dval / dval ;
828 tmp.d13() = ( un.d13()* deux.
val() - un.
val() * deux.d13() ) / dval / dval ;
830 tmp.
val() = un.
val() / dval;
835 template <
class L,
class R>
inline 841 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const L & un, const TinyFad<14,R> & deux), dividing by 0");
845 value_type dval = deux.
val();
847 tmp.d0() = - un * deux.d0() / dval / dval ;
849 tmp.d1() = - un * deux.d1() / dval / dval ;
851 tmp.d2() = - un * deux.d2() / dval / dval ;
853 tmp.d3() = - un * deux.d3() / dval / dval ;
855 tmp.d4() = - un * deux.d4() / dval / dval ;
857 tmp.d5() = - un * deux.d5() / dval / dval ;
859 tmp.d6() = - un * deux.d6() / dval / dval ;
861 tmp.d7() = - un * deux.d7() / dval / dval ;
863 tmp.d8() = - un * deux.d8() / dval / dval ;
865 tmp.d9() = - un * deux.d9() / dval / dval ;
867 tmp.d10() = - un * deux.d10() / dval / dval ;
869 tmp.d11() = - un * deux.d11() / dval / dval ;
871 tmp.d12() = - un * deux.d12() / dval / dval ;
873 tmp.d13() = - un * deux.d13() / dval / dval ;
875 tmp.
val() = un / dval;
880 template <
class L,
class R>
inline 886 if (deux == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<14,L> & un, const R & deux), dividing by 0");
891 tmp.d0() = un.d0() / deux;
893 tmp.d1() = un.d1() / deux;
895 tmp.d2() = un.d2() / deux;
897 tmp.d3() = un.d3() / deux;
899 tmp.d4() = un.d4() / deux;
901 tmp.d5() = un.d5() / deux;
903 tmp.d6() = un.d6() / deux;
905 tmp.d7() = un.d7() / deux;
907 tmp.d8() = un.d8() / deux;
909 tmp.d9() = un.d9() / deux;
911 tmp.d10() = un.d10() / deux;
913 tmp.d11() = un.d11() / deux;
915 tmp.d12() = un.d12() / deux;
917 tmp.d13() = un.d13() / deux;
919 tmp.
val() = un.
val() / deux;
948 if ( in.
val() <= 0)
error(
"TinyFad log (const TinyFad& in) : zero or negative value");
971 if ( in.
val() < 0. )
error(
"TinyFad<14,T> sqrt (const TinyFad& in) : negative value");
975 if ( in.
val() == T(0.) ){
976 if ( in.
d0() != T(0.) ) test =
false;
978 if ( in.
d1() != T(0.) ) test =
false;
980 if ( in.
d2() != T(0.) ) test =
false;
982 if ( in.
d3() != T(0.) ) test =
false;
984 if ( in.
d4() != T(0.) ) test =
false;
986 if ( in.
d5() != T(0.) ) test =
false;
988 if ( in.
d6() != T(0.) ) test =
false;
990 if ( in.
d7() != T(0.) ) test =
false;
992 if ( in.
d8() != T(0.) ) test =
false;
994 if ( in.
d9() != T(0.) ) test =
false;
996 if ( in.
d10() != T(0.) ) test =
false;
998 if ( in.
d11() != T(0.) ) test =
false;
1000 if ( in.
d12() != T(0.) ) test =
false;
1002 if ( in.
d13() != T(0.) ) test =
false;
1005 error(
"TinyFad<14,T> sqrt (const TinyFad& in) : null value");
1073 if ( in.
val() == 0)
error(
"TinyFad tan (const TinyFad& in) undiefined in 0.");
1076 T cosinus =
cos(in.
val());
1077 tmp.
d0() = in.
d0() / cosinus / cosinus;
1078 tmp.
d1() = in.
d1() / cosinus / cosinus;
1079 tmp.
d2() = in.
d2() / cosinus / cosinus;
1080 tmp.
d3() = in.
d3() / cosinus / cosinus;
1081 tmp.
d4() = in.
d4() / cosinus / cosinus;
1082 tmp.
d5() = in.
d5() / cosinus / cosinus;
1083 tmp.
d6() = in.
d6() / cosinus / cosinus;
1084 tmp.
d7() = in.
d7() / cosinus / cosinus;
1085 tmp.
d8() = in.
d8() / cosinus / cosinus;
1086 tmp.
d9() = in.
d9() / cosinus / cosinus;
1087 tmp.
d10() = in.
d10() / cosinus / cosinus;
1088 tmp.
d11() = in.
d11() / cosinus / cosinus;
1089 tmp.
d12() = in.
d12() / cosinus / cosinus;
1090 tmp.
d13() = in.
d13() / cosinus / cosinus;
1119 if (un.
val() == 0)
error(
"TinyFad pow (const TinyFad& un, const TinyFad& deux), un = 0. ");
1158 tmp.d0() = e*in.
d0()*
pow((
double)in.
val(), (double)e-1);
1159 tmp.d1() = e*in.
d1()*
pow((
double)in.
val(), (double)e-1);
1160 tmp.d2() = e*in.
d2()*
pow((
double)in.
val(), (double)e-1);
1161 tmp.d3() = e*in.
d3()*
pow((
double)in.
val(), (double)e-1);
1162 tmp.d4() = e*in.
d4()*
pow((
double)in.
val(), (double)e-1);
1163 tmp.d5() = e*in.
d5()*
pow((
double)in.
val(), (double)e-1);
1164 tmp.d6() = e*in.
d6()*
pow((
double)in.
val(), (double)e-1);
1165 tmp.d7() = e*in.
d7()*
pow((
double)in.
val(), (double)e-1);
1166 tmp.d8() = e*in.
d8()*
pow((
double)in.
val(), (double)e-1);
1167 tmp.d9() = e*in.
d9()*
pow((
double)in.
val(), (double)e-1);
1168 tmp.d10() = e*in.
d10()*
pow((
double)in.
val(), (double)e-1);
1169 tmp.d11() = e*in.
d11()*
pow((
double)in.
val(), (double)e-1);
1170 tmp.d12() = e*in.
d12()*
pow((
double)in.
val(), (double)e-1);
1171 tmp.d13() = e*in.
d13()*
pow((
double)in.
val(), (double)e-1);
1178 int sign = in.
val() > 0? 1:0;
1180 if (sign)
return in;
1184 template <
class T> std::ostream& operator << (std::ostream& os, const TinyFad<14,T>& a)
1186 os.setf(std::ios::fixed,std::ios::scientific);
1188 os << a.
val() <<
" [";
void diff(const size_t ith, const size_t sz)
TinyFad< 14, T > pow(const TinyFad< 14, T > &in, double e)
TinyFad< Num, T > & operator-=(const TinyFad< Num, T > &in)
TinyFad(const No_Initialization &)
TinyFad< 14, T > log(const TinyFad< 14, T > &in)
TinyFad< 14, T > operator--(int)
AutoPointerMutexArrayInit tmp
TinyFad< 14, typename NumericalTraits< L, R >::promote > operator*(const TinyFad< 14, L > &un, const TinyFad< 14, R > &deux)
TinyFad< 14, T > cos(const TinyFad< 14, T > &in)
TinyFad< 14, T > sin(const TinyFad< 14, T > &in)
TinyFad< 14, T > sqrt(const TinyFad< 14, T > &in)
TinyFad< Num, T > & operator=(const TinyFad< Num, T > &in)
TinyFad< Num, T > & operator+=(const TinyFad< Num, T > &in)
TinyFad< 14, typename NumericalTraits< L, R >::promote > operator/(const TinyFad< 14, L > &un, const TinyFad< 14, R > &deux)
TinyFad(const TinyFad< 14, T > &in)
TinyFad< Num, T > & operator*=(const TinyFad< Num, T > &in)
const T & dx(int i) const
TinyFad< 14, T > operator+(const TinyFad< 14, T > &in)
TinyFad< 14, T > abs(const TinyFad< 14, T > &in)
TinyFad< 14, T > operator++(int)
TinyFad< Num, T > & operator/=(const TinyFad< Num, T > &in)
TinyFad< 14, T > operator-(const TinyFad< 14, T > &in)
TinyFad< 14, T > exp(const TinyFad< 14, T > &in)
TinyFad< 14, T > & operator--()
TinyFad< 14, T > tan(const TinyFad< 14, T > &in)
TinyFad< 14, T > & operator++()
TinyFad(const T &ind, const int ini)