1 #ifndef _tinyfadnine_h_ 2 #define _tinyfadnine_h_ 9 template <
class T>
class TinyFad<9,T> {
30 void diff(
const size_t ith,
const size_t sz){
43 case 0 : dx0_ = T(1.);
break;
44 case 1 : dx1_ = T(1.);
break;
45 case 2 : dx2_ = T(1.);
break;
46 case 3 : dx3_ = T(1.);
break;
47 case 4 : dx4_ = T(1.);
break;
48 case 5 : dx5_ = T(1.);
break;
49 case 6 : dx6_ = T(1.);
break;
50 case 7 : dx7_ = T(1.);
break;
51 case 8 : dx8_ = T(1.);
break;
52 default : cout <<
"ith = " << ith <<
" out of definition set" << endl;exit(1);
56 TinyFad(
const T& ind,
const int ini) : n(ini+1), val_(ind) {
68 case 0 : dx0_ = T(1.);
break;
69 case 1 : dx1_ = T(1.);
break;
70 case 2 : dx2_ = T(1.);
break;
71 case 3 : dx3_ = T(1.);
break;
72 case 4 : dx4_ = T(1.);
break;
73 case 5 : dx5_ = T(1.);
break;
74 case 6 : dx6_ = T(1.);
break;
75 case 7 : dx7_ = T(1.);
break;
76 case 8 : dx8_ = T(1.);
break;
77 default : cout <<
"ini = " << ini <<
" out of definition set" << endl;exit(1);
117 int N()
const {
return n-1;}
122 const T&
d0()
const {
return dx0_;}
123 T&
d0() {
return dx0_;}
125 const T&
d1()
const {
return dx1_;}
126 T&
d1() {
return dx1_;}
128 const T&
d2()
const {
return dx2_;}
129 T&
d2() {
return dx2_;}
131 const T&
d3()
const {
return dx3_;}
132 T&
d3() {
return dx3_;}
134 const T&
d4()
const {
return dx4_;}
135 T&
d4() {
return dx4_;}
137 const T&
d5()
const {
return dx5_;}
138 T&
d5() {
return dx5_;}
140 const T&
d6()
const {
return dx6_;}
141 T&
d6() {
return dx6_;}
143 const T&
d7()
const {
return dx7_;}
144 T&
d7() {
return dx7_;}
146 const T&
d8()
const {
return dx8_;}
147 T&
d8() {
return dx8_;}
151 case 0 :
return dx0_;
152 case 1 :
return dx1_;
153 case 2 :
return dx2_;
154 case 3 :
return dx3_;
155 case 4 :
return dx4_;
156 case 5 :
return dx5_;
157 case 6 :
return dx6_;
158 case 7 :
return dx7_;
159 case 8 :
return dx8_;
160 default : cout <<
"i out of bounds" << endl;exit(1);
163 const T&
dx(
int i)
const {
165 case 0 :
return dx0_;
166 case 1 :
return dx1_;
167 case 2 :
return dx2_;
168 case 3 :
return dx3_;
169 case 4 :
return dx4_;
170 case 5 :
return dx5_;
171 case 6 :
return dx6_;
172 case 7 :
return dx7_;
173 case 8 :
return dx8_;
174 default : cout <<
"i out of bounds" << endl;exit(1);
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 case 8 :
return dx8_;
188 default : cout <<
"i out of bounds" << endl;exit(1);
191 const T&
d(
int i)
const {
193 case 0 :
return dx0_;
194 case 1 :
return dx1_;
195 case 2 :
return dx2_;
196 case 3 :
return dx3_;
197 case 4 :
return dx4_;
198 case 5 :
return dx5_;
199 case 6 :
return dx6_;
200 case 7 :
return dx7_;
201 case 8 :
return dx8_;
202 default : cout <<
"i out of bounds" << endl;exit(1);
268 dx0_ = dx0_ * in.
val_ + val_ * in.
dx0_;
269 dx1_ = dx1_ * in.
val_ + val_ * in.
dx1_;
270 dx2_ = dx2_ * in.
val_ + val_ * in.
dx2_;
271 dx3_ = dx3_ * in.
val_ + val_ * in.
dx3_;
272 dx4_ = dx4_ * in.
val_ + val_ * in.
dx4_;
273 dx5_ = dx5_ * in.
val_ + val_ * in.
dx5_;
274 dx6_ = dx6_ * in.
val_ + val_ * in.
dx6_;
275 dx7_ = dx7_ * in.
val_ + val_ * in.
dx7_;
276 dx8_ = dx8_ * in.
val_ + val_ * in.
dx8_;
282 if (in.
val_ == 0.)
error(
"TinyFad & TinyFad::operator /= (const TinyFad & in), dividing by 0");
321 if ( in == T(0.) )
error(
"TinyFad & TinyFad::operator /= (const T & in), dividing by 0");
368 template <
class L,
class R>
inline 377 tmp.d0() = un.d0() + deux.d0();
379 tmp.d1() = un.d1() + deux.d1();
381 tmp.d2() = un.d2() + deux.d2();
383 tmp.d3() = un.d3() + deux.d3();
385 tmp.d4() = un.d4() + deux.d4();
387 tmp.d5() = un.d5() + deux.d5();
389 tmp.d6() = un.d6() + deux.d6();
391 tmp.d7() = un.d7() + deux.d7();
393 tmp.d8() = un.d8() + deux.d8();
400 template <
class L,
class R>
inline 427 tmp.
val() = un.
val() + deux;
432 template <
class L,
class R>
inline 438 template <
class L,
class R>
inline 447 tmp.d0() = un.d0()*deux.
val() + un.
val() * deux.d0();
449 tmp.d1() = un.d1()*deux.
val() + un.
val() * deux.d1();
451 tmp.d2() = un.d2()*deux.
val() + un.
val() * deux.d2();
453 tmp.d3() = un.d3()*deux.
val() + un.
val() * deux.d3();
455 tmp.d4() = un.d4()*deux.
val() + un.
val() * deux.d4();
457 tmp.d5() = un.d5()*deux.
val() + un.
val() * deux.d5();
459 tmp.d6() = un.d6()*deux.
val() + un.
val() * deux.d6();
461 tmp.d7() = un.d7()*deux.
val() + un.
val() * deux.d7();
463 tmp.d8() = un.d8()*deux.
val() + un.
val() * deux.d8();
470 template <
class L,
class R>
inline 479 tmp.d0() = un.d0()*deux;
481 tmp.d1() = un.d1()*deux;
483 tmp.d2() = un.d2()*deux;
485 tmp.d3() = un.d3()*deux;
487 tmp.d4() = un.d4()*deux;
489 tmp.d5() = un.d5()*deux;
491 tmp.d6() = un.d6()*deux;
493 tmp.d7() = un.d7()*deux;
495 tmp.d8() = un.d8()*deux;
497 tmp.
val() = un.
val() * deux;
502 template <
class L,
class R>
inline 510 template <
class L,
class R>
inline 519 tmp.d0() = un.d0() - deux.d0();
521 tmp.d1() = un.d1() - deux.d1();
523 tmp.d2() = un.d2() - deux.d2();
525 tmp.d3() = un.d3() - deux.d3();
527 tmp.d4() = un.d4() - deux.d4();
529 tmp.d5() = un.d5() - deux.d5();
531 tmp.d6() = un.d6() - deux.d6();
533 tmp.d7() = un.d7() - deux.d7();
535 tmp.d8() = un.d8() - deux.d8();
542 template <
class L,
class R>
inline 551 tmp.d0() -= deux.d0();
553 tmp.d1() -= deux.d1();
555 tmp.d2() -= deux.d2();
557 tmp.d3() -= deux.d3();
559 tmp.d4() -= deux.d4();
561 tmp.d5() -= deux.d5();
563 tmp.d6() -= deux.d6();
565 tmp.d7() -= deux.d7();
567 tmp.d8() -= deux.d8();
569 tmp.
val() = un - deux.
val();
574 template <
class L,
class R>
inline 600 tmp.
val() = un.
val() - deux;
605 template <
class L,
class R>
inline 611 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<9,L> & un, const TinyFad<9,R> & deux), dividing by 0");
615 value_type dval = deux.
val();
617 tmp.d0() = ( un.d0()* deux.
val() - un.
val() * deux.d0() ) / dval / dval ;
619 tmp.d1() = ( un.d1()* deux.
val() - un.
val() * deux.d1() ) / dval / dval ;
621 tmp.d2() = ( un.d2()* deux.
val() - un.
val() * deux.d2() ) / dval / dval ;
623 tmp.d3() = ( un.d3()* deux.
val() - un.
val() * deux.d3() ) / dval / dval ;
625 tmp.d4() = ( un.d4()* deux.
val() - un.
val() * deux.d4() ) / dval / dval ;
627 tmp.d5() = ( un.d5()* deux.
val() - un.
val() * deux.d5() ) / dval / dval ;
629 tmp.d6() = ( un.d6()* deux.
val() - un.
val() * deux.d6() ) / dval / dval ;
631 tmp.d7() = ( un.d7()* deux.
val() - un.
val() * deux.d7() ) / dval / dval ;
633 tmp.d8() = ( un.d8()* deux.
val() - un.
val() * deux.d8() ) / dval / dval ;
635 tmp.
val() = un.
val() / dval;
640 template <
class L,
class R>
inline 646 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const L & un, const TinyFad<9,R> & deux), dividing by 0");
650 value_type dval = deux.
val();
652 tmp.d0() = - un * deux.d0() / dval / dval ;
654 tmp.d1() = - un * deux.d1() / dval / dval ;
656 tmp.d2() = - un * deux.d2() / dval / dval ;
658 tmp.d3() = - un * deux.d3() / dval / dval ;
660 tmp.d4() = - un * deux.d4() / dval / dval ;
662 tmp.d5() = - un * deux.d5() / dval / dval ;
664 tmp.d6() = - un * deux.d6() / dval / dval ;
666 tmp.d7() = - un * deux.d7() / dval / dval ;
668 tmp.d8() = - un * deux.d8() / dval / dval ;
670 tmp.
val() = un / dval;
675 template <
class L,
class R>
inline 681 if (deux == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<9,L> & un, const R & deux), dividing by 0");
686 tmp.d0() = un.d0() / deux;
688 tmp.d1() = un.d1() / deux;
690 tmp.d2() = un.d2() / deux;
692 tmp.d3() = un.d3() / deux;
694 tmp.d4() = un.d4() / deux;
696 tmp.d5() = un.d5() / deux;
698 tmp.d6() = un.d6() / deux;
700 tmp.d7() = un.d7() / deux;
702 tmp.d8() = un.d8() / deux;
704 tmp.
val() = un.
val() / deux;
728 if ( in.
val() <= 0)
error(
"TinyFad log (const TinyFad& in) : zero or negative value");
746 if ( in.
val() < 0. )
error(
"TinyFad<9,T> sqrt (const TinyFad& in) : negative value");
750 if ( in.
val() == T(0.) ){
751 if ( in.
d0() != T(0.) ) test =
false;
753 if ( in.
d1() != T(0.) ) test =
false;
755 if ( in.
d2() != T(0.) ) test =
false;
757 if ( in.
d3() != T(0.) ) test =
false;
759 if ( in.
d4() != T(0.) ) test =
false;
761 if ( in.
d5() != T(0.) ) test =
false;
763 if ( in.
d6() != T(0.) ) test =
false;
765 if ( in.
d7() != T(0.) ) test =
false;
767 if ( in.
d8() != T(0.) ) test =
false;
770 error(
"TinyFad<9,T> sqrt (const TinyFad& in) : null value");
823 if ( in.
val() == 0)
error(
"TinyFad tan (const TinyFad& in) undiefined in 0.");
826 T cosinus =
cos(in.
val());
827 tmp.
d0() = in.
d0() / cosinus / cosinus;
828 tmp.
d1() = in.
d1() / cosinus / cosinus;
829 tmp.
d2() = in.
d2() / cosinus / cosinus;
830 tmp.
d3() = in.
d3() / cosinus / cosinus;
831 tmp.
d4() = in.
d4() / cosinus / cosinus;
832 tmp.
d5() = in.
d5() / cosinus / cosinus;
833 tmp.
d6() = in.
d6() / cosinus / cosinus;
834 tmp.
d7() = in.
d7() / cosinus / cosinus;
835 tmp.
d8() = in.
d8() / cosinus / cosinus;
859 if (un.
val() == 0)
error(
"TinyFad pow (const TinyFad& un, const TinyFad& deux), un = 0. ");
888 tmp.d0() = e*in.
d0()*
pow((
double)in.
val(), (double)e-1);
889 tmp.d1() = e*in.
d1()*
pow((
double)in.
val(), (double)e-1);
890 tmp.d2() = e*in.
d2()*
pow((
double)in.
val(), (double)e-1);
891 tmp.d3() = e*in.
d3()*
pow((
double)in.
val(), (double)e-1);
892 tmp.d4() = e*in.
d4()*
pow((
double)in.
val(), (double)e-1);
893 tmp.d5() = e*in.
d5()*
pow((
double)in.
val(), (double)e-1);
894 tmp.d6() = e*in.
d6()*
pow((
double)in.
val(), (double)e-1);
895 tmp.d7() = e*in.
d7()*
pow((
double)in.
val(), (double)e-1);
896 tmp.d8() = e*in.
d8()*
pow((
double)in.
val(), (double)e-1);
903 int sign = in.
val() > 0? 1:0;
909 template <
class T> std::ostream& operator << (std::ostream& os, const TinyFad<9,T>& a)
911 os.setf(std::ios::fixed,std::ios::scientific);
913 os << a.
val() <<
" [";
TinyFad< 9, typename NumericalTraits< L, R >::promote > operator*(const TinyFad< 9, L > &un, const TinyFad< 9, R > &deux)
TinyFad< 9, T > log(const TinyFad< 9, T > &in)
TinyFad(const T &ind, const int ini)
TinyFad< 9, T > sqrt(const TinyFad< 9, T > &in)
TinyFad< Num, T > & operator-=(const TinyFad< Num, T > &in)
TinyFad< 9, T > tan(const TinyFad< 9, T > &in)
const T & dx(int i) const
TinyFad< 9, T > abs(const TinyFad< 9, T > &in)
TinyFad< 9, T > operator+(const TinyFad< 9, T > &in)
AutoPointerMutexArrayInit tmp
TinyFad< 9, T > pow(const TinyFad< 9, T > &in, double e)
TinyFad< 9, T > & operator--()
TinyFad< 9, typename NumericalTraits< L, R >::promote > operator/(const TinyFad< 9, L > &un, const TinyFad< 9, R > &deux)
TinyFad< 9, T > & operator++()
TinyFad< Num, T > & operator=(const TinyFad< Num, T > &in)
TinyFad< 9, T > operator++(int)
TinyFad(const TinyFad< 9, T > &in)
TinyFad< Num, T > & operator+=(const TinyFad< Num, T > &in)
TinyFad< Num, T > & operator*=(const TinyFad< Num, T > &in)
TinyFad< 9, T > cos(const TinyFad< 9, T > &in)
TinyFad< 9, T > operator-(const TinyFad< 9, T > &in)
TinyFad< 9, T > operator--(int)
TinyFad(const No_Initialization &)
TinyFad< Num, T > & operator/=(const TinyFad< Num, T > &in)
TinyFad< 9, T > exp(const TinyFad< 9, T > &in)
TinyFad< 9, T > sin(const TinyFad< 9, T > &in)
void diff(const size_t ith, const size_t sz)