NeoPZ
tinyfadeight.h
Go to the documentation of this file.
1 #ifndef _tinyfadeight_h_
2 #define _tinyfadeight_h_
3 
4 //*********************************************************
5 // This file is generated by generate.cc.
6 // Use this file for any modification
7 //*********************************************************
8 
9 template <class T> class TinyFad<8,T> {
10 public:
11  typedef T value_type;
12  typedef T grad_type;
13 protected:
14 
15  int n;
16  T val_;
17 
18  T dx0_;
19  T dx1_;
20  T dx2_;
21  T dx3_;
22  T dx4_;
23  T dx5_;
24  T dx6_;
25  T dx7_;
26 
27 
28 public:
29  void diff(const size_t ith, const size_t sz){
30  n = ith+1;
31  dx0_ = T(0.);
32  dx1_ = T(0.);
33  dx2_ = T(0.);
34  dx3_ = T(0.);
35  dx4_ = T(0.);
36  dx5_ = T(0.);
37  dx6_ = T(0.);
38  dx7_ = T(0.);
39 
40  switch(ith){
41  case 0 : dx0_ = T(1.);break;
42  case 1 : dx1_ = T(1.);break;
43  case 2 : dx2_ = T(1.);break;
44  case 3 : dx3_ = T(1.);break;
45  case 4 : dx4_ = T(1.);break;
46  case 5 : dx5_ = T(1.);break;
47  case 6 : dx6_ = T(1.);break;
48  case 7 : dx7_ = T(1.);break;
49  default : cout << "ith = " << ith << " out of definition set" << endl;exit(1);
50  }
51  }
52 
53  TinyFad(const T& ind, const int ini) : n(ini+1), val_(ind) {
54  dx0_ = T(0.);
55  dx1_ = T(0.);
56  dx2_ = T(0.);
57  dx3_ = T(0.);
58  dx4_ = T(0.);
59  dx5_ = T(0.);
60  dx6_ = T(0.);
61  dx7_ = T(0.);
62 
63  switch(ini){
64  case 0 : dx0_ = T(1.);break;
65  case 1 : dx1_ = T(1.);break;
66  case 2 : dx2_ = T(1.);break;
67  case 3 : dx3_ = T(1.);break;
68  case 4 : dx4_ = T(1.);break;
69  case 5 : dx5_ = T(1.);break;
70  case 6 : dx6_ = T(1.);break;
71  case 7 : dx7_ = T(1.);break;
72  default : cout << "ini = " << ini << " out of definition set" << endl;exit(1);
73  }
74  }
75  TinyFad() : n(0), val_(0.) {
76  dx0_ = T(0.);
77  dx1_ = T(0.);
78  dx2_ = T(0.);
79  dx3_ = T(0.);
80  dx4_ = T(0.);
81  dx5_ = T(0.);
82  dx6_ = T(0.);
83  dx7_ = T(0.);
84  }
85  TinyFad(const No_Initialization &): n(0) {}
86  TinyFad(const T& in) : n(0), val_(in) {
87  dx0_ = T(0.);
88  dx1_ = T(0.);
89  dx2_ = T(0.);
90  dx3_ = T(0.);
91  dx4_ = T(0.);
92  dx5_ = T(0.);
93  dx6_ = T(0.);
94  dx7_ = T(0.);
95  }
96  TinyFad(const TinyFad<8,T> & in) : n(0), val_(in.val_) {
97  dx0_ = in.dx0_;
98  dx1_ = in.dx1_;
99  dx2_ = in.dx2_;
100  dx3_ = in.dx3_;
101  dx4_ = in.dx4_;
102  dx5_ = in.dx5_;
103  dx6_ = in.dx6_;
104  dx7_ = in.dx7_;
105  }
106 
107  ~TinyFad() {}
108 
109  int N() const {return n-1;}
110 
111  const T& val() const { return val_;}
112  T& val() { return val_;}
113 
114  const T& d0() const { return dx0_;}
115  T& d0() { return dx0_;}
116 
117  const T& d1() const { return dx1_;}
118  T& d1() { return dx1_;}
119 
120  const T& d2() const { return dx2_;}
121  T& d2() { return dx2_;}
122 
123  const T& d3() const { return dx3_;}
124  T& d3() { return dx3_;}
125 
126  const T& d4() const { return dx4_;}
127  T& d4() { return dx4_;}
128 
129  const T& d5() const { return dx5_;}
130  T& d5() { return dx5_;}
131 
132  const T& d6() const { return dx6_;}
133  T& d6() { return dx6_;}
134 
135  const T& d7() const { return dx7_;}
136  T& d7() { return dx7_;}
137 
138  T& dx(int i){
139  switch(i){
140  case 0 : return dx0_;
141  case 1 : return dx1_;
142  case 2 : return dx2_;
143  case 3 : return dx3_;
144  case 4 : return dx4_;
145  case 5 : return dx5_;
146  case 6 : return dx6_;
147  case 7 : return dx7_;
148  default : cout << "i out of bounds" << endl;exit(1);
149  }
150  }
151  const T& dx(int i) const {
152  switch(i){
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  case 7 : return dx7_;
161  default : cout << "i out of bounds" << endl;exit(1);
162  }
163  }
164  T& d(int i){
165  switch(i){
166  case 0 : return dx0_;
167  case 1 : return dx1_;
168  case 2 : return dx2_;
169  case 3 : return dx3_;
170  case 4 : return dx4_;
171  case 5 : return dx5_;
172  case 6 : return dx6_;
173  case 7 : return dx7_;
174  default : cout << "i out of bounds" << endl;exit(1);
175  }
176  }
177  const T& d(int i) const {
178  switch(i){
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  default : cout << "i out of bounds" << endl;exit(1);
188  }
189  }
190 
192  val_ = in.val_;
193 
194  dx0_ = in.dx0_;
195  dx1_ = in.dx1_;
196  dx2_ = in.dx2_;
197  dx3_ = in.dx3_;
198  dx4_ = in.dx4_;
199  dx5_ = in.dx5_;
200  dx6_ = in.dx6_;
201  dx7_ = in.dx7_;
202 
203  return *this;
204  }
205 
206  TinyFad<8,T> & operator = (const T & in){
207  val_ = in;
208 
209  dx0_ = T(0.);
210  dx1_ = T(0.);
211  dx2_ = T(0.);
212  dx3_ = T(0.);
213  dx4_ = T(0.);
214  dx5_ = T(0.);
215  dx6_ = T(0.);
216  dx7_ = T(0.);
217 
218  return *this;
219  }
220 
222  dx0_ += in.dx0_;
223  dx1_ += in.dx1_;
224  dx2_ += in.dx2_;
225  dx3_ += in.dx3_;
226  dx4_ += in.dx4_;
227  dx5_ += in.dx5_;
228  dx6_ += in.dx6_;
229  dx7_ += in.dx7_;
230  val_ += in.val_;
231 
232 
233  return *this;
234  }
236  dx0_ -= in.dx0_;
237  dx1_ -= in.dx1_;
238  dx2_ -= in.dx2_;
239  dx3_ -= in.dx3_;
240  dx4_ -= in.dx4_;
241  dx5_ -= in.dx5_;
242  dx6_ -= in.dx6_;
243  dx7_ -= in.dx7_;
244  val_ -= in.val_;
245 
246  return *this;
247  }
249  dx0_ = dx0_ * in.val_ + val_ * in.dx0_;
250  dx1_ = dx1_ * in.val_ + val_ * in.dx1_;
251  dx2_ = dx2_ * in.val_ + val_ * in.dx2_;
252  dx3_ = dx3_ * in.val_ + val_ * in.dx3_;
253  dx4_ = dx4_ * in.val_ + val_ * in.dx4_;
254  dx5_ = dx5_ * in.val_ + val_ * in.dx5_;
255  dx6_ = dx6_ * in.val_ + val_ * in.dx6_;
256  dx7_ = dx7_ * in.val_ + val_ * in.dx7_;
257  val_ *= in.val_;
258 
259  return *this;
260  }
262  if (in.val_ == 0.) error("TinyFad & TinyFad::operator /= (const TinyFad & in), dividing by 0");
263  dx0_ = ( dx0_ * in.val_ - val_ * in.dx0_ ) / in.val_ / in.val_ ;
264  dx1_ = ( dx1_ * in.val_ - val_ * in.dx1_ ) / in.val_ / in.val_ ;
265  dx2_ = ( dx2_ * in.val_ - val_ * in.dx2_ ) / in.val_ / in.val_ ;
266  dx3_ = ( dx3_ * in.val_ - val_ * in.dx3_ ) / in.val_ / in.val_ ;
267  dx4_ = ( dx4_ * in.val_ - val_ * in.dx4_ ) / in.val_ / in.val_ ;
268  dx5_ = ( dx5_ * in.val_ - val_ * in.dx5_ ) / in.val_ / in.val_ ;
269  dx6_ = ( dx6_ * in.val_ - val_ * in.dx6_ ) / in.val_ / in.val_ ;
270  dx7_ = ( dx7_ * in.val_ - val_ * in.dx7_ ) / in.val_ / in.val_ ;
271  val_ /= in.val_;
272 
273  return *this;
274  }
275 
276  TinyFad<8,T> & operator += (const T & in){ val_ += in;
277 
278  return *this;
279  }
280  TinyFad<8,T> & operator -= (const T & in){ val_ -= in;
281 
282  return *this;
283  }
284  TinyFad<8,T> & operator *= (const T & in){
285  val_ *= in;
286 
287  dx0_ *= in;
288  dx1_ *= in;
289  dx2_ *= in;
290  dx3_ *= in;
291  dx4_ *= in;
292  dx5_ *= in;
293  dx6_ *= in;
294  dx7_ *= in;
295 
296  return *this;
297  }
298  TinyFad<8,T> & operator /= (const T & in){
299  if ( in == T(0.) ) error("TinyFad & TinyFad::operator /= (const T & in), dividing by 0");
300  val_ /= in;
301 
302  dx0_ /= in;
303  dx1_ /= in;
304  dx2_ /= in;
305  dx3_ /= in;
306  dx4_ /= in;
307  dx5_ /= in;
308  dx6_ /= in;
309  dx7_ /= in;
310 
311  return *this;
312  }
313 
315  TinyFad<8,T> tmp(*this);
316  tmp.val_++;
317  return tmp;
318  };
320  TinyFad<8,T> tmp(*this);
321  tmp.val_--;
322  return tmp;
323  };
325  return *this;
326  }
328  return *this;
329  }
330 };
331 
332 
333 template <class T> inline TinyFad<8,T> operator + (const TinyFad<8,T>& in)
334 {
335  return TinyFad<8,T>(in);
336 }
337 
338 template <class T> inline TinyFad<8,T> operator - (const TinyFad<8,T>& in)
339 {
341  tmp -= in;
342  return tmp;
343 }
344 
345 template <class L, class R> inline
347 operator +(const TinyFad<8,L>& un, const TinyFad<8,R>& deux) {
348 
349  typedef typename NumericalTraits<L,R>::promote value_type;
350 
351  No_Initialization nothing;
352  TinyFad<8,value_type> tmp( nothing );
353 
354  tmp.d0() = un.d0() + deux.d0();
355 
356  tmp.d1() = un.d1() + deux.d1();
357 
358  tmp.d2() = un.d2() + deux.d2();
359 
360  tmp.d3() = un.d3() + deux.d3();
361 
362  tmp.d4() = un.d4() + deux.d4();
363 
364  tmp.d5() = un.d5() + deux.d5();
365 
366  tmp.d6() = un.d6() + deux.d6();
367 
368  tmp.d7() = un.d7() + deux.d7();
369 
370  tmp.val() = un.val() + deux.val();
371 
372  return tmp;
373 }
374 
375 template <class L, class R> inline
377 operator +(const TinyFad<8,L>& un, const R& deux) {
378 
379  typedef typename NumericalTraits<L,R>::promote value_type;
380 
381  No_Initialization nothing;
382  TinyFad<8,value_type> tmp( nothing );
383 
384  tmp.d0() = un.d0();
385 
386  tmp.d1() = un.d1();
387 
388  tmp.d2() = un.d2();
389 
390  tmp.d3() = un.d3();
391 
392  tmp.d4() = un.d4();
393 
394  tmp.d5() = un.d5();
395 
396  tmp.d6() = un.d6();
397 
398  tmp.d7() = un.d7();
399 
400  tmp.val() = un.val() + deux;
401 
402  return tmp;
403 }
404 
405 template <class L, class R> inline
407 operator +(const L& un, const TinyFad<8,R>& deux) {
408  return operator +(deux,un);
409 }
410 
411 template <class L, class R> inline
413 operator *(const TinyFad<8,L>& un, const TinyFad<8,R>& deux) {
414 
415  typedef typename NumericalTraits<L,R>::promote value_type;
416 
417  No_Initialization nothing;
418  TinyFad<8,value_type> tmp( nothing );
419 
420  tmp.d0() = un.d0()*deux.val() + un.val() * deux.d0();
421 
422  tmp.d1() = un.d1()*deux.val() + un.val() * deux.d1();
423 
424  tmp.d2() = un.d2()*deux.val() + un.val() * deux.d2();
425 
426  tmp.d3() = un.d3()*deux.val() + un.val() * deux.d3();
427 
428  tmp.d4() = un.d4()*deux.val() + un.val() * deux.d4();
429 
430  tmp.d5() = un.d5()*deux.val() + un.val() * deux.d5();
431 
432  tmp.d6() = un.d6()*deux.val() + un.val() * deux.d6();
433 
434  tmp.d7() = un.d7()*deux.val() + un.val() * deux.d7();
435 
436  tmp.val() = un.val() * deux.val();
437 
438  return tmp;
439 }
440 
441 template <class L, class R> inline
443 operator *(const TinyFad<8,L>& un, const R& deux) {
444 
445  typedef typename NumericalTraits<L,R>::promote value_type;
446 
447  No_Initialization nothing;
448  TinyFad<8,value_type> tmp( nothing );
449 
450  tmp.d0() = un.d0()*deux;
451 
452  tmp.d1() = un.d1()*deux;
453 
454  tmp.d2() = un.d2()*deux;
455 
456  tmp.d3() = un.d3()*deux;
457 
458  tmp.d4() = un.d4()*deux;
459 
460  tmp.d5() = un.d5()*deux;
461 
462  tmp.d6() = un.d6()*deux;
463 
464  tmp.d7() = un.d7()*deux;
465 
466  tmp.val() = un.val() * deux;
467 
468  return tmp;
469 }
470 
471 template <class L, class R> inline
473 operator *(const L& un, const TinyFad<8,R>& deux) {
474 
475  return operator *(deux,un);
476 }
477 
478 
479 template <class L, class R> inline
481 operator -(const TinyFad<8,L> & un, const TinyFad<8,R> & deux) {
482 
483  typedef typename NumericalTraits<L,R>::promote value_type;
484 
485  No_Initialization nothing;
486  TinyFad<8,value_type> tmp( nothing );
487 
488  tmp.d0() = un.d0() - deux.d0();
489 
490  tmp.d1() = un.d1() - deux.d1();
491 
492  tmp.d2() = un.d2() - deux.d2();
493 
494  tmp.d3() = un.d3() - deux.d3();
495 
496  tmp.d4() = un.d4() - deux.d4();
497 
498  tmp.d5() = un.d5() - deux.d5();
499 
500  tmp.d6() = un.d6() - deux.d6();
501 
502  tmp.d7() = un.d7() - deux.d7();
503 
504  tmp.val() = un.val() - deux.val();
505 
506  return tmp;
507 }
508 
509 template <class L, class R> inline
511 operator -(const L & un, const TinyFad<8,R> & deux) {
512 
513  typedef typename NumericalTraits<L,R>::promote value_type;
514 
515  No_Initialization nothing;
516  TinyFad<8,value_type> tmp( nothing );
517 
518  tmp.d0() -= deux.d0();
519 
520  tmp.d1() -= deux.d1();
521 
522  tmp.d2() -= deux.d2();
523 
524  tmp.d3() -= deux.d3();
525 
526  tmp.d4() -= deux.d4();
527 
528  tmp.d5() -= deux.d5();
529 
530  tmp.d6() -= deux.d6();
531 
532  tmp.d7() -= deux.d7();
533 
534  tmp.val() = un - deux.val();
535 
536  return tmp;
537 }
538 
539 template <class L, class R> inline
541 operator -(const TinyFad<8,L> & un, const R & deux) {
542  typedef typename NumericalTraits<L,R>::promote value_type;
543 
544  No_Initialization nothing;
545  TinyFad<8,value_type> tmp( nothing );
546 
547  tmp.d0() = un.d0();
548 
549  tmp.d1() = un.d1();
550 
551  tmp.d2() = un.d2();
552 
553  tmp.d3() = un.d3();
554 
555  tmp.d4() = un.d4();
556 
557  tmp.d5() = un.d5();
558 
559  tmp.d6() = un.d6();
560 
561  tmp.d7() = un.d7();
562 
563  tmp.val() = un.val() - deux;
564 
565  return tmp;
566 }
567 
568 template <class L, class R> inline
570 operator /(const TinyFad<8,L> & un, const TinyFad<8,R> & deux) {
571 
572  typedef typename NumericalTraits<L,R>::promote value_type;
573 
574  if (deux.val() == 0.) error("TinyFad & TinyFad::operator /(const TinyFad<8,L> & un, const TinyFad<8,R> & deux), dividing by 0");
575 
576  No_Initialization nothing;
577  TinyFad<8,value_type> tmp( nothing );
578  value_type dval = deux.val();
579 
580  tmp.d0() = ( un.d0()* deux.val() - un.val() * deux.d0() ) / dval / dval ;
581 
582  tmp.d1() = ( un.d1()* deux.val() - un.val() * deux.d1() ) / dval / dval ;
583 
584  tmp.d2() = ( un.d2()* deux.val() - un.val() * deux.d2() ) / dval / dval ;
585 
586  tmp.d3() = ( un.d3()* deux.val() - un.val() * deux.d3() ) / dval / dval ;
587 
588  tmp.d4() = ( un.d4()* deux.val() - un.val() * deux.d4() ) / dval / dval ;
589 
590  tmp.d5() = ( un.d5()* deux.val() - un.val() * deux.d5() ) / dval / dval ;
591 
592  tmp.d6() = ( un.d6()* deux.val() - un.val() * deux.d6() ) / dval / dval ;
593 
594  tmp.d7() = ( un.d7()* deux.val() - un.val() * deux.d7() ) / dval / dval ;
595 
596  tmp.val() = un.val() / dval;
597 
598  return tmp;
599 }
600 
601 template <class L, class R> inline
603 operator /(const L & un, const TinyFad<8,R> & deux) {
604 
605  typedef typename NumericalTraits<L,R>::promote value_type;
606 
607  if (deux.val() == 0.) error("TinyFad & TinyFad::operator /(const L & un, const TinyFad<8,R> & deux), dividing by 0");
608 
609  No_Initialization nothing;
610  TinyFad<8,value_type> tmp( nothing );
611  value_type dval = deux.val();
612 
613  tmp.d0() = - un * deux.d0() / dval / dval ;
614 
615  tmp.d1() = - un * deux.d1() / dval / dval ;
616 
617  tmp.d2() = - un * deux.d2() / dval / dval ;
618 
619  tmp.d3() = - un * deux.d3() / dval / dval ;
620 
621  tmp.d4() = - un * deux.d4() / dval / dval ;
622 
623  tmp.d5() = - un * deux.d5() / dval / dval ;
624 
625  tmp.d6() = - un * deux.d6() / dval / dval ;
626 
627  tmp.d7() = - un * deux.d7() / dval / dval ;
628 
629  tmp.val() = un / dval;
630 
631  return tmp;
632 }
633 
634 template <class L, class R> inline
636 operator /(const TinyFad<8,L> & un, const R & deux) {
637 
638  typedef typename NumericalTraits<L,R>::promote value_type;
639 
640  if (deux == 0.) error("TinyFad & TinyFad::operator /(const TinyFad<8,L> & un, const R & deux), dividing by 0");
641 
642  No_Initialization nothing;
643  TinyFad<8,value_type> tmp( nothing );
644 
645  tmp.d0() = un.d0() / deux;
646 
647  tmp.d1() = un.d1() / deux;
648 
649  tmp.d2() = un.d2() / deux;
650 
651  tmp.d3() = un.d3() / deux;
652 
653  tmp.d4() = un.d4() / deux;
654 
655  tmp.d5() = un.d5() / deux;
656 
657  tmp.d6() = un.d6() / deux;
658 
659  tmp.d7() = un.d7() / deux;
660 
661  tmp.val() = un.val() / deux;
662 
663  return tmp;
664 }
665 
666 template <class T> TinyFad<8,T> exp (const TinyFad<8,T>& in)
667 {
668  TinyFad<8,T> tmp(exp(in.val()));
669 
670  tmp.d0() = in.d0()*exp(in.val());
671  tmp.d1() = in.d1()*exp(in.val());
672  tmp.d2() = in.d2()*exp(in.val());
673  tmp.d3() = in.d3()*exp(in.val());
674  tmp.d4() = in.d4()*exp(in.val());
675  tmp.d5() = in.d5()*exp(in.val());
676  tmp.d6() = in.d6()*exp(in.val());
677  tmp.d7() = in.d7()*exp(in.val());
678 
679  return tmp;
680 }
681 
682 template <class T> TinyFad<8,T> log (const TinyFad<8,T>& in)
683 {
684  if ( in.val() <= 0) error("TinyFad log (const TinyFad& in) : zero or negative value");
685  TinyFad<8,T> tmp(log(in.val()));
686 
687  tmp.d0() = in.d0() / in.val();
688  tmp.d1() = in.d1() / in.val();
689  tmp.d2() = in.d2() / in.val();
690  tmp.d3() = in.d3() / in.val();
691  tmp.d4() = in.d4() / in.val();
692  tmp.d5() = in.d5() / in.val();
693  tmp.d6() = in.d6() / in.val();
694  tmp.d7() = in.d7() / in.val();
695 
696  return tmp;
697 }
698 
699 template <class T> TinyFad<8,T> sqrt (const TinyFad<8,T>& in)
700 {
701  if ( in.val() < 0. ) error("TinyFad<8,T> sqrt (const TinyFad& in) : negative value");
702  TinyFad<8,T> tmp(sqrt(in.val()));
703 
704  bool test=true;
705  if ( in.val() == T(0.) ){
706  if ( in.d0() != T(0.) ) test = false;
707 
708  if ( in.d1() != T(0.) ) test = false;
709 
710  if ( in.d2() != T(0.) ) test = false;
711 
712  if ( in.d3() != T(0.) ) test = false;
713 
714  if ( in.d4() != T(0.) ) test = false;
715 
716  if ( in.d5() != T(0.) ) test = false;
717 
718  if ( in.d6() != T(0.) ) test = false;
719 
720  if ( in.d7() != T(0.) ) test = false;
721 
722  if ( !test )
723  error("TinyFad<8,T> sqrt (const TinyFad& in) : null value");
724  }
725  else {
726  tmp.d0() = in.d0() / sqrt(in.val()) / 2.;
727  tmp.d1() = in.d1() / sqrt(in.val()) / 2.;
728  tmp.d2() = in.d2() / sqrt(in.val()) / 2.;
729  tmp.d3() = in.d3() / sqrt(in.val()) / 2.;
730  tmp.d4() = in.d4() / sqrt(in.val()) / 2.;
731  tmp.d5() = in.d5() / sqrt(in.val()) / 2.;
732  tmp.d6() = in.d6() / sqrt(in.val()) / 2.;
733  tmp.d7() = in.d7() / sqrt(in.val()) / 2.;
734  }
735 
736  return tmp;
737 }
738 
739 template <class T> TinyFad<8,T> sin (const TinyFad<8,T>& in)
740 {
741  TinyFad<8,T> tmp( sin(in.val()) );
742 
743  tmp.d0() = in.d0() * cos( in.val() );
744  tmp.d1() = in.d1() * cos( in.val() );
745  tmp.d2() = in.d2() * cos( in.val() );
746  tmp.d3() = in.d3() * cos( in.val() );
747  tmp.d4() = in.d4() * cos( in.val() );
748  tmp.d5() = in.d5() * cos( in.val() );
749  tmp.d6() = in.d6() * cos( in.val() );
750  tmp.d7() = in.d7() * cos( in.val() );
751 
752  return tmp;
753 }
754 
755 template <class T> TinyFad<8,T> cos (const TinyFad<8,T>& in)
756 {
757  TinyFad<8,T> tmp(cos(in.val()));
758 
759  tmp.d0() = - in.d0() * sin( in.val() );
760  tmp.d1() = - in.d1() * sin( in.val() );
761  tmp.d2() = - in.d2() * sin( in.val() );
762  tmp.d3() = - in.d3() * sin( in.val() );
763  tmp.d4() = - in.d4() * sin( in.val() );
764  tmp.d5() = - in.d5() * sin( in.val() );
765  tmp.d6() = - in.d6() * sin( in.val() );
766  tmp.d7() = - in.d7() * sin( in.val() );
767 
768  return tmp;
769 }
770 
771 template <class T> TinyFad<8,T> tan (const TinyFad<8,T>& in)
772 {
773  if ( in.val() == 0) error("TinyFad tan (const TinyFad& in) undiefined in 0.");
774  TinyFad<8,T> tmp(tan(in.val()));
775 
776  T cosinus = cos(in.val());
777  tmp.d0() = in.d0() / cosinus / cosinus;
778  tmp.d1() = in.d1() / cosinus / cosinus;
779  tmp.d2() = in.d2() / cosinus / cosinus;
780  tmp.d3() = in.d3() / cosinus / cosinus;
781  tmp.d4() = in.d4() / cosinus / cosinus;
782  tmp.d5() = in.d5() / cosinus / cosinus;
783  tmp.d6() = in.d6() / cosinus / cosinus;
784  tmp.d7() = in.d7() / cosinus / cosinus;
785 
786  return tmp;
787 }
788 
789 template <class T> TinyFad<8,T> pow (const TinyFad<8,T>& in, double e)
790 {
791  TinyFad<8,T> tmp(pow(in.val(), e));
792 
793  tmp.d0() = e*in.d0()*pow(in.val(), e-1);
794  tmp.d1() = e*in.d1()*pow(in.val(), e-1);
795  tmp.d2() = e*in.d2()*pow(in.val(), e-1);
796  tmp.d3() = e*in.d3()*pow(in.val(), e-1);
797  tmp.d4() = e*in.d4()*pow(in.val(), e-1);
798  tmp.d5() = e*in.d5()*pow(in.val(), e-1);
799  tmp.d6() = e*in.d6()*pow(in.val(), e-1);
800  tmp.d7() = e*in.d7()*pow(in.val(), e-1);
801 
802  return tmp;
803 }
804 
805 template <class T> TinyFad<8,T> pow (const TinyFad<8,T>& un, const TinyFad<8,T>& deux)
806 {
807  if (un.val() == 0) error("TinyFad pow (const TinyFad& un, const TinyFad& deux), un = 0. ");
808  TinyFad<8,T> tmp(pow(un.val(), deux.val()));
809 
810  tmp.d0() = deux.d0() * log(un.val()) * pow(un.val(), deux.val())
811  + deux.val() * un.d0() * pow(un.val(), deux.val()-1);
812  tmp.d1() = deux.d1() * log(un.val()) * pow(un.val(), deux.val())
813  + deux.val() * un.d1() * pow(un.val(), deux.val()-1);
814  tmp.d2() = deux.d2() * log(un.val()) * pow(un.val(), deux.val())
815  + deux.val() * un.d2() * pow(un.val(), deux.val()-1);
816  tmp.d3() = deux.d3() * log(un.val()) * pow(un.val(), deux.val())
817  + deux.val() * un.d3() * pow(un.val(), deux.val()-1);
818  tmp.d4() = deux.d4() * log(un.val()) * pow(un.val(), deux.val())
819  + deux.val() * un.d4() * pow(un.val(), deux.val()-1);
820  tmp.d5() = deux.d5() * log(un.val()) * pow(un.val(), deux.val())
821  + deux.val() * un.d5() * pow(un.val(), deux.val()-1);
822  tmp.d6() = deux.d6() * log(un.val()) * pow(un.val(), deux.val())
823  + deux.val() * un.d6() * pow(un.val(), deux.val()-1);
824  tmp.d7() = deux.d7() * log(un.val()) * pow(un.val(), deux.val())
825  + deux.val() * un.d7() * pow(un.val(), deux.val()-1);
826 
827  return tmp;
828 }
829 
830 template <class T> TinyFad<8,T> pow (const TinyFad<8,T>& in, const int e)
831 {
832  TinyFad<8,T> tmp( pow((double)in.val(), (double)e) );
833 
834  tmp.d0() = e*in.d0()*pow((double)in.val(), (double)e-1);
835  tmp.d1() = e*in.d1()*pow((double)in.val(), (double)e-1);
836  tmp.d2() = e*in.d2()*pow((double)in.val(), (double)e-1);
837  tmp.d3() = e*in.d3()*pow((double)in.val(), (double)e-1);
838  tmp.d4() = e*in.d4()*pow((double)in.val(), (double)e-1);
839  tmp.d5() = e*in.d5()*pow((double)in.val(), (double)e-1);
840  tmp.d6() = e*in.d6()*pow((double)in.val(), (double)e-1);
841  tmp.d7() = e*in.d7()*pow((double)in.val(), (double)e-1);
842 
843  return tmp;
844 }
845 
846 template <class T> TinyFad<8,T> abs (const TinyFad<8,T>& in)
847 {
848  int sign = in.val() > 0? 1:0;
849 
850  if (sign) return in;
851  else return (-in);
852 }
853 
854 template <class T> std::ostream& operator << (std::ostream& os, const TinyFad<8,T>& a)
855 {
856  os.setf(std::ios::fixed,std::ios::scientific);
857  os.width(12);
858  os << a.val() << " [";
859 
860  os.width(12);
861  os << a.d0();
862  os.width(12);
863  os << a.d1();
864  os.width(12);
865  os << a.d2();
866  os.width(12);
867  os << a.d3();
868  os.width(12);
869  os << a.d4();
870  os.width(12);
871  os << a.d5();
872  os.width(12);
873  os << a.d6();
874  os.width(12);
875  os << a.d7();
876 
877  os << "]";
878 
879  return os;
880 }
881 
882 
883 #endif
const T & d0() const
Definition: tinyfadeight.h:114
TinyFad< 8, T > operator+(const TinyFad< 8, T > &in)
Definition: tinyfadeight.h:333
TinyFad< Num, T > & operator-=(const TinyFad< Num, T > &in)
Definition: tinyfad.h:233
TinyFad< 8, typename NumericalTraits< L, R >::promote > operator*(const TinyFad< 8, L > &un, const TinyFad< 8, R > &deux)
Definition: tinyfadeight.h:413
Definition: test.py:1
TinyFad< 8, T > operator--(int)
Definition: tinyfadeight.h:319
TinyFad< 8, T > log(const TinyFad< 8, T > &in)
Definition: tinyfadeight.h:682
TinyFad(const TinyFad< 8, T > &in)
Definition: tinyfadeight.h:96
TinyFad< 8, T > abs(const TinyFad< 8, T > &in)
Definition: tinyfadeight.h:846
TinyFad< 8, T > operator++(int)
Definition: tinyfadeight.h:314
AutoPointerMutexArrayInit tmp
TinyFad< 8, T > cos(const TinyFad< 8, T > &in)
Definition: tinyfadeight.h:755
T val_
Definition: tinyfad.h:47
const T & d7() const
Definition: tinyfadeight.h:135
TinyFad< 8, T > & operator++()
Definition: tinyfadeight.h:324
T & d(int i)
Definition: tinyfadeight.h:164
void error(char *string)
Definition: testShape.cc:7
TinyFad(const T &ind, const int ini)
Definition: tinyfadeight.h:53
const T & d4() const
Definition: tinyfadeight.h:126
const T & d6() const
Definition: tinyfadeight.h:132
const T & dx(int i) const
Definition: tinyfadeight.h:151
TinyFad(const No_Initialization &)
Definition: tinyfadeight.h:85
const T & d5() const
Definition: tinyfadeight.h:129
TinyFad< Num, T > & operator=(const TinyFad< Num, T > &in)
Definition: tinyfad.h:189
TinyFad< 8, typename NumericalTraits< L, R >::promote > operator/(const TinyFad< 8, L > &un, const TinyFad< 8, R > &deux)
Definition: tinyfadeight.h:570
T & dx(int i)
Definition: tinyfadeight.h:138
TinyFad< Num, T > & operator+=(const TinyFad< Num, T > &in)
Definition: tinyfad.h:219
T value_type
Definition: tinyfad.h:53
TinyFad< 8, T > pow(const TinyFad< 8, T > &in, double e)
Definition: tinyfadeight.h:789
TinyFad< 8, T > sqrt(const TinyFad< 8, T > &in)
Definition: tinyfadeight.h:699
TinyFad< Num, T > & operator*=(const TinyFad< Num, T > &in)
Definition: tinyfad.h:247
const T & d(int i) const
Definition: tinyfadeight.h:177
const T & d1() const
Definition: tinyfadeight.h:117
const T & val() const
Definition: tinyfadeight.h:111
TinyFad< 8, T > operator-(const TinyFad< 8, T > &in)
Definition: tinyfadeight.h:338
int N() const
Definition: tinyfadeight.h:109
TinyFad< 8, T > tan(const TinyFad< 8, T > &in)
Definition: tinyfadeight.h:771
const T & d2() const
Definition: tinyfadeight.h:120
TinyFad< Num, T > & operator/=(const TinyFad< Num, T > &in)
Definition: tinyfad.h:261
void diff(const size_t ith, const size_t sz)
Definition: tinyfadeight.h:29
TinyFad< 8, T > & operator--()
Definition: tinyfadeight.h:327
TinyFad(const T &in)
Definition: tinyfadeight.h:86
TinyFad< 8, T > sin(const TinyFad< 8, T > &in)
Definition: tinyfadeight.h:739
const T & val() const
Definition: tinyfad.h:72
TinyFad< 8, T > exp(const TinyFad< 8, T > &in)
Definition: tinyfadeight.h:666
const T & d3() const
Definition: tinyfadeight.h:123