1 #ifndef _tinyfadseven_h_ 2 #define _tinyfadseven_h_ 9 template <
class T>
class TinyFad<7,T> {
28 void diff(
const size_t ith,
const size_t sz){
39 case 0 : dx0_ = T(1.);
break;
40 case 1 : dx1_ = T(1.);
break;
41 case 2 : dx2_ = T(1.);
break;
42 case 3 : dx3_ = T(1.);
break;
43 case 4 : dx4_ = T(1.);
break;
44 case 5 : dx5_ = T(1.);
break;
45 case 6 : dx6_ = T(1.);
break;
46 default : cout <<
"ith = " << ith <<
" out of definition set" << endl;exit(1);
50 TinyFad(
const T& ind,
const int ini) : n(ini+1), val_(ind) {
60 case 0 : dx0_ = T(1.);
break;
61 case 1 : dx1_ = T(1.);
break;
62 case 2 : dx2_ = T(1.);
break;
63 case 3 : dx3_ = T(1.);
break;
64 case 4 : dx4_ = T(1.);
break;
65 case 5 : dx5_ = T(1.);
break;
66 case 6 : dx6_ = T(1.);
break;
67 default : cout <<
"ini = " << ini <<
" out of definition set" << endl;exit(1);
101 int N()
const {
return n-1;}
106 const T&
d0()
const {
return dx0_;}
107 T&
d0() {
return dx0_;}
109 const T&
d1()
const {
return dx1_;}
110 T&
d1() {
return dx1_;}
112 const T&
d2()
const {
return dx2_;}
113 T&
d2() {
return dx2_;}
115 const T&
d3()
const {
return dx3_;}
116 T&
d3() {
return dx3_;}
118 const T&
d4()
const {
return dx4_;}
119 T&
d4() {
return dx4_;}
121 const T&
d5()
const {
return dx5_;}
122 T&
d5() {
return dx5_;}
124 const T&
d6()
const {
return dx6_;}
125 T&
d6() {
return dx6_;}
129 case 0 :
return dx0_;
130 case 1 :
return dx1_;
131 case 2 :
return dx2_;
132 case 3 :
return dx3_;
133 case 4 :
return dx4_;
134 case 5 :
return dx5_;
135 case 6 :
return dx6_;
136 default : cout <<
"i out of bounds" << endl;exit(1);
139 const T&
dx(
int i)
const {
141 case 0 :
return dx0_;
142 case 1 :
return dx1_;
143 case 2 :
return dx2_;
144 case 3 :
return dx3_;
145 case 4 :
return dx4_;
146 case 5 :
return dx5_;
147 case 6 :
return dx6_;
148 default : cout <<
"i out of bounds" << endl;exit(1);
153 case 0 :
return dx0_;
154 case 1 :
return dx1_;
155 case 2 :
return dx2_;
156 case 3 :
return dx3_;
157 case 4 :
return dx4_;
158 case 5 :
return dx5_;
159 case 6 :
return dx6_;
160 default : cout <<
"i out of bounds" << endl;exit(1);
163 const T&
d(
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 default : cout <<
"i out of bounds" << endl;exit(1);
230 dx0_ = dx0_ * in.
val_ + val_ * in.
dx0_;
231 dx1_ = dx1_ * in.
val_ + val_ * in.
dx1_;
232 dx2_ = dx2_ * in.
val_ + val_ * in.
dx2_;
233 dx3_ = dx3_ * in.
val_ + val_ * in.
dx3_;
234 dx4_ = dx4_ * in.
val_ + val_ * in.
dx4_;
235 dx5_ = dx5_ * in.
val_ + val_ * in.
dx5_;
236 dx6_ = dx6_ * in.
val_ + val_ * in.
dx6_;
242 if (in.
val_ == 0.)
error(
"TinyFad & TinyFad::operator /= (const TinyFad & in), dividing by 0");
277 if ( in == T(0.) )
error(
"TinyFad & TinyFad::operator /= (const T & in), dividing by 0");
322 template <
class L,
class R>
inline 331 tmp.d0() = un.d0() + deux.d0();
333 tmp.d1() = un.d1() + deux.d1();
335 tmp.d2() = un.d2() + deux.d2();
337 tmp.d3() = un.d3() + deux.d3();
339 tmp.d4() = un.d4() + deux.d4();
341 tmp.d5() = un.d5() + deux.d5();
343 tmp.d6() = un.d6() + deux.d6();
350 template <
class L,
class R>
inline 373 tmp.
val() = un.
val() + deux;
378 template <
class L,
class R>
inline 384 template <
class L,
class R>
inline 393 tmp.d0() = un.d0()*deux.
val() + un.
val() * deux.d0();
395 tmp.d1() = un.d1()*deux.
val() + un.
val() * deux.d1();
397 tmp.d2() = un.d2()*deux.
val() + un.
val() * deux.d2();
399 tmp.d3() = un.d3()*deux.
val() + un.
val() * deux.d3();
401 tmp.d4() = un.d4()*deux.
val() + un.
val() * deux.d4();
403 tmp.d5() = un.d5()*deux.
val() + un.
val() * deux.d5();
405 tmp.d6() = un.d6()*deux.
val() + un.
val() * deux.d6();
412 template <
class L,
class R>
inline 421 tmp.d0() = un.d0()*deux;
423 tmp.d1() = un.d1()*deux;
425 tmp.d2() = un.d2()*deux;
427 tmp.d3() = un.d3()*deux;
429 tmp.d4() = un.d4()*deux;
431 tmp.d5() = un.d5()*deux;
433 tmp.d6() = un.d6()*deux;
435 tmp.
val() = un.
val() * deux;
440 template <
class L,
class R>
inline 448 template <
class L,
class R>
inline 457 tmp.d0() = un.d0() - deux.d0();
459 tmp.d1() = un.d1() - deux.d1();
461 tmp.d2() = un.d2() - deux.d2();
463 tmp.d3() = un.d3() - deux.d3();
465 tmp.d4() = un.d4() - deux.d4();
467 tmp.d5() = un.d5() - deux.d5();
469 tmp.d6() = un.d6() - deux.d6();
476 template <
class L,
class R>
inline 485 tmp.d0() -= deux.d0();
487 tmp.d1() -= deux.d1();
489 tmp.d2() -= deux.d2();
491 tmp.d3() -= deux.d3();
493 tmp.d4() -= deux.d4();
495 tmp.d5() -= deux.d5();
497 tmp.d6() -= deux.d6();
499 tmp.
val() = un - deux.
val();
504 template <
class L,
class R>
inline 526 tmp.
val() = un.
val() - deux;
531 template <
class L,
class R>
inline 537 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<7,L> & un, const TinyFad<7,R> & deux), dividing by 0");
541 value_type dval = deux.
val();
543 tmp.d0() = ( un.d0()* deux.
val() - un.
val() * deux.d0() ) / dval / dval ;
545 tmp.d1() = ( un.d1()* deux.
val() - un.
val() * deux.d1() ) / dval / dval ;
547 tmp.d2() = ( un.d2()* deux.
val() - un.
val() * deux.d2() ) / dval / dval ;
549 tmp.d3() = ( un.d3()* deux.
val() - un.
val() * deux.d3() ) / dval / dval ;
551 tmp.d4() = ( un.d4()* deux.
val() - un.
val() * deux.d4() ) / dval / dval ;
553 tmp.d5() = ( un.d5()* deux.
val() - un.
val() * deux.d5() ) / dval / dval ;
555 tmp.d6() = ( un.d6()* deux.
val() - un.
val() * deux.d6() ) / dval / dval ;
557 tmp.
val() = un.
val() / dval;
562 template <
class L,
class R>
inline 568 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const L & un, const TinyFad<7,R> & deux), dividing by 0");
572 value_type dval = deux.
val();
574 tmp.d0() = - un * deux.d0() / dval / dval ;
576 tmp.d1() = - un * deux.d1() / dval / dval ;
578 tmp.d2() = - un * deux.d2() / dval / dval ;
580 tmp.d3() = - un * deux.d3() / dval / dval ;
582 tmp.d4() = - un * deux.d4() / dval / dval ;
584 tmp.d5() = - un * deux.d5() / dval / dval ;
586 tmp.d6() = - un * deux.d6() / dval / dval ;
588 tmp.
val() = un / dval;
593 template <
class L,
class R>
inline 599 if (deux == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<7,L> & un, const R & deux), dividing by 0");
604 tmp.d0() = un.d0() / deux;
606 tmp.d1() = un.d1() / deux;
608 tmp.d2() = un.d2() / deux;
610 tmp.d3() = un.d3() / deux;
612 tmp.d4() = un.d4() / deux;
614 tmp.d5() = un.d5() / deux;
616 tmp.d6() = un.d6() / deux;
618 tmp.
val() = un.
val() / deux;
640 if ( in.
val() <= 0)
error(
"TinyFad log (const TinyFad& in) : zero or negative value");
656 if ( in.
val() < 0. )
error(
"TinyFad<7,T> sqrt (const TinyFad& in) : negative value");
660 if ( in.
val() == T(0.) ){
661 if ( in.
d0() != T(0.) ) test =
false;
663 if ( in.
d1() != T(0.) ) test =
false;
665 if ( in.
d2() != T(0.) ) test =
false;
667 if ( in.
d3() != T(0.) ) test =
false;
669 if ( in.
d4() != T(0.) ) test =
false;
671 if ( in.
d5() != T(0.) ) test =
false;
673 if ( in.
d6() != T(0.) ) test =
false;
676 error(
"TinyFad<7,T> sqrt (const TinyFad& in) : null value");
723 if ( in.
val() == 0)
error(
"TinyFad tan (const TinyFad& in) undiefined in 0.");
726 T cosinus =
cos(in.
val());
727 tmp.
d0() = in.
d0() / cosinus / cosinus;
728 tmp.
d1() = in.
d1() / cosinus / cosinus;
729 tmp.
d2() = in.
d2() / cosinus / cosinus;
730 tmp.
d3() = in.
d3() / cosinus / cosinus;
731 tmp.
d4() = in.
d4() / cosinus / cosinus;
732 tmp.
d5() = in.
d5() / cosinus / cosinus;
733 tmp.
d6() = in.
d6() / cosinus / cosinus;
755 if (un.
val() == 0)
error(
"TinyFad pow (const TinyFad& un, const TinyFad& deux), un = 0. ");
780 tmp.d0() = e*in.
d0()*
pow((
double)in.
val(), (double)e-1);
781 tmp.d1() = e*in.
d1()*
pow((
double)in.
val(), (double)e-1);
782 tmp.d2() = e*in.
d2()*
pow((
double)in.
val(), (double)e-1);
783 tmp.d3() = e*in.
d3()*
pow((
double)in.
val(), (double)e-1);
784 tmp.d4() = e*in.
d4()*
pow((
double)in.
val(), (double)e-1);
785 tmp.d5() = e*in.
d5()*
pow((
double)in.
val(), (double)e-1);
786 tmp.d6() = e*in.
d6()*
pow((
double)in.
val(), (double)e-1);
793 int sign = in.
val() > 0? 1:0;
799 template <
class T> std::ostream& operator << (std::ostream& os, const TinyFad<7,T>& a)
801 os.setf(std::ios::fixed,std::ios::scientific);
803 os << a.
val() <<
" [";
TinyFad< 7, T > pow(const TinyFad< 7, T > &in, double e)
TinyFad< 7, T > operator--(int)
TinyFad< 7, T > operator+(const TinyFad< 7, T > &in)
TinyFad< Num, T > & operator-=(const TinyFad< Num, T > &in)
TinyFad(const T &ind, const int ini)
const T & dx(int i) const
TinyFad(const No_Initialization &)
TinyFad< 7, T > operator-(const TinyFad< 7, T > &in)
TinyFad< 7, typename NumericalTraits< L, R >::promote > operator*(const TinyFad< 7, L > &un, const TinyFad< 7, R > &deux)
TinyFad< 7, T > sqrt(const TinyFad< 7, T > &in)
TinyFad< 7, T > exp(const TinyFad< 7, T > &in)
AutoPointerMutexArrayInit tmp
TinyFad< 7, T > & operator++()
TinyFad< 7, T > log(const TinyFad< 7, T > &in)
TinyFad< 7, T > & operator--()
TinyFad< 7, T > cos(const TinyFad< 7, T > &in)
TinyFad< Num, T > & operator=(const TinyFad< Num, T > &in)
TinyFad< Num, T > & operator+=(const TinyFad< Num, T > &in)
TinyFad< Num, T > & operator*=(const TinyFad< Num, T > &in)
TinyFad< 7, T > operator++(int)
void diff(const size_t ith, const size_t sz)
TinyFad< Num, T > & operator/=(const TinyFad< Num, T > &in)
TinyFad< 7, T > abs(const TinyFad< 7, T > &in)
TinyFad< 7, typename NumericalTraits< L, R >::promote > operator/(const TinyFad< 7, L > &un, const TinyFad< 7, R > &deux)
TinyFad(const TinyFad< 7, T > &in)
TinyFad< 7, T > tan(const TinyFad< 7, T > &in)
TinyFad< 7, T > sin(const TinyFad< 7, T > &in)