Debian Codegraph @

packages/sacado/Fad/TinyFad/Specializations/tinyfadnine.h

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