Salome HOME
Boost of expression evaluator DataArrayDouble::applyFunc* + DataArrayDouble::applyFun...
[modules/med.git] / src / INTERP_KERNEL / ExprEval / InterpKernelFunction.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "InterpKernelFunction.hxx"
22 #include "InterpKernelValue.hxx"
23
24 #include <cmath>
25 #include <limits>
26
27 using namespace INTERP_KERNEL;
28
29 const char IdentityFunction::REPR[]="Id";
30
31 const char PositiveFunction::REPR[]="+";
32
33 const char NegateFunction::REPR[]="-";
34
35 const char CosFunction::REPR[]="cos";
36
37 const char SinFunction::REPR[]="sin";
38
39 const char TanFunction::REPR[]="tan";
40
41 const char ACosFunction::REPR[]="acos";
42
43 const char ASinFunction::REPR[]="asin";
44
45 const char ATanFunction::REPR[]="atan";
46
47 const char CoshFunction::REPR[]="cosh";
48
49 const char SinhFunction::REPR[]="sinh";
50
51 const char TanhFunction::REPR[]="tanh";
52
53 const char SqrtFunction::REPR[]="sqrt";
54
55 const char AbsFunction::REPR[]="abs";
56
57 const char PlusFunction::REPR[]="+";
58
59 const char MinusFunction::REPR[]="-";
60
61 const char MultFunction::REPR[]="*";
62
63 const char DivFunction::REPR[]="/";
64
65 const char PowFunction::REPR[]="^";
66
67 const char ExpFunction::REPR[]="exp";
68
69 const char LnFunction::REPR[]="ln";
70
71 const char LogFunction::REPR[]="log";
72
73 const char Log10Function::REPR[]="log10";
74
75 const char MaxFunction::REPR[]="max";
76
77 const char MinFunction::REPR[]="min";
78
79 const char GreaterThanFunction::REPR[]=">";
80
81 const char LowerThanFunction::REPR[]="<";
82
83 const char IfFunction::REPR[]="if";
84
85 Function *FunctionsFactory::buildFuncFromString(const char *type, int nbOfParams)
86 {
87   switch(nbOfParams)
88     {
89     case 1:
90       return buildUnaryFuncFromString(type);
91     case 2:
92       return buildBinaryFuncFromString(type);
93     case 3:
94       return buildTernaryFuncFromString(type);
95     default:
96       throw INTERP_KERNEL::Exception("Invalid number of params detected : limited to 2 !");
97     }
98 }
99
100 Function *FunctionsFactory::buildUnaryFuncFromString(const char *type)
101 {
102   std::string tmp(type);
103   if(tmp.empty())
104     return new IdentityFunction;
105   if(tmp==CosFunction::REPR)
106     return new CosFunction;
107   if(tmp==SinFunction::REPR)
108     return new SinFunction;
109   if(tmp==TanFunction::REPR)
110     return new TanFunction;
111   if(tmp==ACosFunction::REPR)
112     return new ACosFunction;
113   if(tmp==ASinFunction::REPR)
114     return new ASinFunction;
115   if(tmp==ATanFunction::REPR)
116     return new ATanFunction;
117   if(tmp==CoshFunction::REPR)
118     return new CoshFunction;
119   if(tmp==SinhFunction::REPR)
120     return new SinhFunction;
121   if(tmp==TanhFunction::REPR)
122     return new TanhFunction;
123   if(tmp==SqrtFunction::REPR)
124     return new SqrtFunction;
125   if(tmp==AbsFunction::REPR)
126     return new AbsFunction;
127   if(tmp==PositiveFunction::REPR)
128     return new PositiveFunction;
129   if(tmp==NegateFunction::REPR)
130     return new NegateFunction;
131   if(tmp==ExpFunction::REPR)
132     return new ExpFunction;
133   if(tmp==LnFunction::REPR)
134     return new LnFunction;
135   if(tmp==LogFunction::REPR)
136     return new LogFunction;
137   if(tmp==Log10Function::REPR)
138     return new Log10Function;
139   //
140   std::string msg("Invalid unary function detected : \"");
141   msg+=type; msg+="\"";
142   throw INTERP_KERNEL::Exception(msg.c_str());
143 }
144
145 Function *FunctionsFactory::buildBinaryFuncFromString(const char *type)
146 {
147   std::string tmp(type);
148   if(tmp==PositiveFunction::REPR)
149     return new PlusFunction;
150   if(tmp==NegateFunction::REPR)
151     return new MinusFunction;
152   if(tmp==MultFunction::REPR)
153     return new MultFunction;
154   if(tmp==DivFunction::REPR)
155     return new DivFunction;
156   if(tmp==PowFunction::REPR)
157     return new PowFunction;
158   if(tmp==MaxFunction::REPR)
159     return new MaxFunction;
160   if(tmp==MinFunction::REPR)
161     return new MinFunction;
162   if(tmp==GreaterThanFunction::REPR)
163     return new GreaterThanFunction;
164   if(tmp==LowerThanFunction::REPR)
165     return new LowerThanFunction;
166   std::string msg("Invalid binary function detected : \"");
167   msg+=type; msg+="\"";
168   throw INTERP_KERNEL::Exception(msg.c_str());
169 }
170
171 Function *FunctionsFactory::buildTernaryFuncFromString(const char *type)
172 {
173   std::string tmp(type);
174   if(tmp==IfFunction::REPR)
175     return new IfFunction();
176   std::string msg("Invalid ternary function detected : \"");
177   msg+=type; msg+="\"";
178   throw INTERP_KERNEL::Exception(msg.c_str());
179 }
180
181 Function *FunctionsFactory::buildBinaryFuncFromString(char type)
182 {
183   char tmp[2]; tmp[0]=type; tmp[1]='\0';
184   return buildBinaryFuncFromString(tmp);
185 }
186
187 Function::~Function()
188 {
189 }
190
191 IdentityFunction::~IdentityFunction()
192 {
193 }
194
195 void IdentityFunction::operate(std::vector<Value *>& stck) const
196 {
197 }
198
199 void IdentityFunction::operateX86(std::vector<std::string>& asmb) const
200 {
201 }
202
203 void IdentityFunction::operateStackOfDouble(std::vector<double>& stck) const
204 {
205 }
206
207 const char *IdentityFunction::getRepr() const
208 {
209   return REPR;
210 }
211
212 bool IdentityFunction::isACall() const
213 {
214   return false;
215 }
216
217 PositiveFunction::~PositiveFunction()
218 {
219 }
220
221 int UnaryFunction::getNbInputParams() const
222 {
223   return 1;
224 }
225
226 void PositiveFunction::operate(std::vector<Value *>& stck) const
227 {
228 }
229
230 void PositiveFunction::operateX86(std::vector<std::string>& asmb) const
231 {
232 }
233
234 void PositiveFunction::operateStackOfDouble(std::vector<double>& stck) const
235 {
236 }
237
238 const char *PositiveFunction::getRepr() const
239 {
240   return REPR;
241 }
242
243 bool PositiveFunction::isACall() const
244 {
245   return false;
246 }
247
248 NegateFunction::~NegateFunction()
249 {
250 }
251
252 void NegateFunction::operate(std::vector<Value *>& stck) const
253 {
254   Value *val=stck.back();
255   val->negate();
256 }
257
258 void NegateFunction::operateX86(std::vector<std::string>& asmb) const
259 {
260   asmb.push_back("fchs");
261 }
262
263 void NegateFunction::operateStackOfDouble(std::vector<double>& stck) const
264 {
265   double v(stck.back());
266   stck.back()=-v;
267 }
268
269 const char *NegateFunction::getRepr() const
270 {
271   return REPR;
272 }
273
274 bool NegateFunction::isACall() const
275 {
276   return false;
277 }
278
279 CosFunction::~CosFunction()
280 {
281 }
282
283 void CosFunction::operate(std::vector<Value *>& stck) const
284 {
285   Value *val=stck.back();
286   val->cos();
287 }
288
289 void CosFunction::operateX86(std::vector<std::string>& asmb) const
290 {
291   asmb.push_back("fcos");
292 }
293
294 void CosFunction::operateStackOfDouble(std::vector<double>& stck) const
295 {
296   double v(stck.back());
297   stck.back()=cos(v);
298 }
299
300 const char *CosFunction::getRepr() const
301 {
302   return REPR;
303 }
304
305 bool CosFunction::isACall() const
306 {
307   return true;
308 }
309
310 SinFunction::~SinFunction()
311 {
312 }
313
314 void SinFunction::operate(std::vector<Value *>& stck) const
315 {
316   Value *val=stck.back();
317   val->sin();
318 }
319
320 void SinFunction::operateX86(std::vector<std::string>& asmb) const
321 {
322   asmb.push_back("fsin");
323 }
324
325 void SinFunction::operateStackOfDouble(std::vector<double>& stck) const
326 {
327   double v(stck.back());
328   stck.back()=sin(v);
329 }
330
331 const char *SinFunction::getRepr() const
332 {
333   return REPR;
334 }
335
336 bool SinFunction::isACall() const
337 {
338   return true;
339 }
340
341 TanFunction::~TanFunction()
342 {
343 }
344
345 void TanFunction::operate(std::vector<Value *>& stck) const
346 {
347   Value *val=stck.back();
348   val->tan();
349 }
350
351 void TanFunction::operateX86(std::vector<std::string>& asmb) const
352 {
353   throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
354 }
355
356 void TanFunction::operateStackOfDouble(std::vector<double>& stck) const
357 {
358   double v(stck.back());
359   stck.back()=tan(v);
360 }
361
362 const char *TanFunction::getRepr() const
363 {
364   return REPR;
365 }
366
367 bool TanFunction::isACall() const
368 {
369   return true;
370 }
371
372 ACosFunction::~ACosFunction()
373 {
374 }
375
376 void ACosFunction::operate(std::vector<Value *>& stck) const
377 {
378   Value *val=stck.back();
379   val->acos();
380 }
381
382 void ACosFunction::operateX86(std::vector<std::string>& asmb) const
383 {
384   throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
385 }
386
387 void ACosFunction::operateStackOfDouble(std::vector<double>& stck) const
388 {
389   double v(stck.back());
390   stck.back()=acos(v);
391 }
392
393 void ACosFunction::operateStackOfDoubleSafe(std::vector<double>& stck) const
394 {
395   double v(stck.back());
396   if(fabs(v)>1.)
397     throw INTERP_KERNEL::Exception("acos on a value which absolute is > 1 !");
398   stck.back()=acos(v);
399 }
400
401 const char *ACosFunction::getRepr() const
402 {
403   return REPR;
404 }
405
406 bool ACosFunction::isACall() const
407 {
408   return true;
409 }
410
411 ASinFunction::~ASinFunction()
412 {
413 }
414
415 void ASinFunction::operate(std::vector<Value *>& stck) const
416 {
417   Value *val=stck.back();
418   val->asin();
419 }
420
421 void ASinFunction::operateX86(std::vector<std::string>& asmb) const
422 {
423   throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
424 }
425
426 void ASinFunction::operateStackOfDouble(std::vector<double>& stck) const
427 {
428   double v(stck.back());
429   stck.back()=asin(v);
430 }
431
432 void ASinFunction::operateStackOfDoubleSafe(std::vector<double>& stck) const
433 {
434   double v(stck.back());
435   if(fabs(v)>1.)
436     throw INTERP_KERNEL::Exception("asin on a value which absolute is > 1 !");
437   stck.back()=asin(v);
438 }
439
440 const char *ASinFunction::getRepr() const
441 {
442   return REPR;
443 }
444
445 bool ASinFunction::isACall() const
446 {
447   return true;
448 }
449
450 ATanFunction::~ATanFunction()
451 {
452 }
453
454 void ATanFunction::operate(std::vector<Value *>& stck) const
455 {
456   Value *val=stck.back();
457   val->atan();
458 }
459
460 void ATanFunction::operateX86(std::vector<std::string>& asmb) const
461 {
462   throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
463 }
464
465 void ATanFunction::operateStackOfDouble(std::vector<double>& stck) const
466 {
467   double v(stck.back());
468   stck.back()=atan(v);
469 }
470
471 const char *ATanFunction::getRepr() const
472 {
473   return REPR;
474 }
475
476 bool ATanFunction::isACall() const
477 {
478   return true;
479 }
480
481 CoshFunction::~CoshFunction()
482 {
483 }
484
485 void CoshFunction::operate(std::vector<Value *>& stck) const
486 {
487   Value *val=stck.back();
488   val->cosh();
489 }
490
491 void CoshFunction::operateX86(std::vector<std::string>& asmb) const
492 {
493   throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
494 }
495
496 void CoshFunction::operateStackOfDouble(std::vector<double>& stck) const
497 {
498   double v(stck.back());
499   stck.back()=cosh(v);
500 }
501
502 const char *CoshFunction::getRepr() const
503 {
504   return REPR;
505 }
506
507 bool CoshFunction::isACall() const
508 {
509   return true;
510 }
511
512 SinhFunction::~SinhFunction()
513 {
514 }
515
516 void SinhFunction::operate(std::vector<Value *>& stck) const
517 {
518   Value *val=stck.back();
519   val->sinh();
520 }
521
522 void SinhFunction::operateX86(std::vector<std::string>& asmb) const
523 {
524   throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
525 }
526
527 void SinhFunction::operateStackOfDouble(std::vector<double>& stck) const
528 {
529   double v(stck.back());
530   stck.back()=sinh(v);
531 }
532
533 const char *SinhFunction::getRepr() const
534 {
535   return REPR;
536 }
537
538 bool SinhFunction::isACall() const
539 {
540   return true;
541 }
542
543 TanhFunction::~TanhFunction()
544 {
545 }
546
547 void TanhFunction::operate(std::vector<Value *>& stck) const
548 {
549   Value *val=stck.back();
550   val->tanh();
551 }
552
553 void TanhFunction::operateX86(std::vector<std::string>& asmb) const
554 {
555   throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
556 }
557
558 void TanhFunction::operateStackOfDouble(std::vector<double>& stck) const
559 {
560   double v(stck.back());
561   stck.back()=tanh(v);
562 }
563
564 const char *TanhFunction::getRepr() const
565 {
566   return REPR;
567 }
568
569 bool TanhFunction::isACall() const
570 {
571   return true;
572 }
573
574 SqrtFunction::~SqrtFunction()
575 {
576 }
577
578 void SqrtFunction::operate(std::vector<Value *>& stck) const
579 {
580   Value *val=stck.back();
581   val->sqrt();
582 }
583
584 void SqrtFunction::operateX86(std::vector<std::string>& asmb) const
585 {
586   asmb.push_back("fsqrt");
587 }
588
589 void SqrtFunction::operateStackOfDouble(std::vector<double>& stck) const
590 {
591   double v(stck.back());
592   stck.back()=sqrt(v);
593 }
594
595 void SqrtFunction::operateStackOfDoubleSafe(std::vector<double>& stck) const
596 {
597   double v(stck.back());
598   if(v<0.)
599     throw INTERP_KERNEL::Exception("sqrt on a value < 0. !");
600   stck.back()=sqrt(v);
601 }
602
603 const char *SqrtFunction::getRepr() const
604 {
605   return REPR;
606 }
607
608 bool SqrtFunction::isACall() const
609 {
610   return true;
611 }
612
613 AbsFunction::~AbsFunction()
614 {
615 }
616
617 void AbsFunction::operate(std::vector<Value *>& stck) const
618 {
619   Value *val=stck.back();
620   val->abs();
621 }
622
623 void AbsFunction::operateX86(std::vector<std::string>& asmb) const
624 {
625   asmb.push_back("fabs");
626 }
627
628 void AbsFunction::operateStackOfDouble(std::vector<double>& stck) const
629 {
630   double v(stck.back());
631   stck.back()=fabs(v);
632 }
633
634 const char *AbsFunction::getRepr() const
635 {
636   return REPR;
637 }
638
639 bool AbsFunction::isACall() const
640 {
641   return false;
642 }
643
644 void ExpFunction::operate(std::vector<Value *>& stck) const
645 {
646   Value *val=stck.back();
647   val->exp();
648 }
649
650 void ExpFunction::operateX86(std::vector<std::string>& asmb) const
651 {
652   throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
653 }
654
655 void ExpFunction::operateStackOfDouble(std::vector<double>& stck) const
656 {
657   double v(stck.back());
658   stck.back()=std::exp(v);
659 }
660
661 const char *ExpFunction::getRepr() const
662 {
663   return REPR;
664 }
665
666 bool ExpFunction::isACall() const
667 {
668   return true;
669 }
670
671 LnFunction::~LnFunction()
672 {
673 }
674
675 void LnFunction::operate(std::vector<Value *>& stck) const
676 {
677   Value *val=stck.back();
678   val->ln();
679 }
680
681 void LnFunction::operateX86(std::vector<std::string>& asmb) const
682 {
683   throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
684 }
685
686 void LnFunction::operateStackOfDouble(std::vector<double>& stck) const
687 {
688   double v(stck.back());
689   stck.back()=std::log(v);
690 }
691
692 void LnFunction::operateStackOfDoubleSafe(std::vector<double>& stck) const
693 {
694   double v(stck.back());
695   if(v<0.)
696     throw INTERP_KERNEL::Exception("ln on a value < 0. !");
697   stck.back()=std::log(v);
698 }
699
700 const char *LnFunction::getRepr() const
701 {
702   return REPR;
703 }
704
705 bool LnFunction::isACall() const
706 {
707   return true;
708 }
709
710 LogFunction::~LogFunction()
711 {
712 }
713
714 void LogFunction::operate(std::vector<Value *>& stck) const
715 {
716   Value *val=stck.back();
717   val->ln();
718 }
719
720 void LogFunction::operateX86(std::vector<std::string>& asmb) const
721 {
722   throw INTERP_KERNEL::Exception("Assembly for log Not implemented yet !");
723 }
724
725 void LogFunction::operateStackOfDouble(std::vector<double>& stck) const
726 {
727   double v(stck.back());
728   stck.back()=std::log(v);
729 }
730
731 void LogFunction::operateStackOfDoubleSafe(std::vector<double>& stck) const
732 {
733   double v(stck.back());
734   if(v<0.)
735     throw INTERP_KERNEL::Exception("log on a value < 0. !");
736   stck.back()=std::log(v);
737 }
738
739 const char *LogFunction::getRepr() const
740 {
741   return REPR;
742 }
743
744 bool LogFunction::isACall() const
745 {
746   return true;
747 }
748
749 Log10Function::~Log10Function()
750 {
751 }
752
753 void Log10Function::operate(std::vector<Value *>& stck) const
754 {
755   Value *val=stck.back();
756   val->log10();
757 }
758
759 void Log10Function::operateX86(std::vector<std::string>& asmb) const
760 {
761   throw INTERP_KERNEL::Exception("Assembly for log Not implemented yet !");
762 }
763
764 void Log10Function::operateStackOfDouble(std::vector<double>& stck) const
765 {
766   double v(stck.back());
767   stck.back()=std::log10(v);
768 }
769
770 void Log10Function::operateStackOfDoubleSafe(std::vector<double>& stck) const
771 {
772   double v(stck.back());
773   if(v<0.)
774     throw INTERP_KERNEL::Exception("log10 on a value < 0. !");
775   stck.back()=std::log10(v);
776 }
777
778 const char *Log10Function::getRepr() const
779 {
780   return REPR;
781 }
782
783 bool Log10Function::isACall() const
784 {
785   return true;
786 }
787
788 int BinaryFunction::getNbInputParams() const
789 {
790   return 2;
791 }
792
793 PlusFunction::~PlusFunction()
794 {
795 }
796
797 void PlusFunction::operate(std::vector<Value *>& stck) const
798 {
799   Value *val1=stck.back();
800   stck.pop_back();
801   Value *& val2=stck.back();
802   Value *val3;
803   try
804     {
805       val3=val1->plus(val2);
806     }
807   catch(INTERP_KERNEL::Exception& e)
808     {
809       delete val1;
810       throw e;
811     }
812   delete val1;
813   delete val2;
814   val2=val3;
815 }
816
817 void PlusFunction::operateX86(std::vector<std::string>& asmb) const
818 {
819   asmb.push_back("faddp st1");
820 }
821
822 void PlusFunction::operateStackOfDouble(std::vector<double>& stck) const
823 {
824   double a(stck.back());
825   stck.pop_back();
826   stck.back()=a+stck.back();
827 }
828
829 const char *PlusFunction::getRepr() const
830 {
831   return REPR;
832 }
833
834 bool PlusFunction::isACall() const
835 {
836   return false;
837 }
838
839 MinusFunction::~MinusFunction()
840 {
841 }
842
843 void MinusFunction::operate(std::vector<Value *>& stck) const
844 {
845   Value *val1=stck.back();
846   stck.pop_back();
847   Value *& val2=stck.back();
848   Value *val3;
849   try
850     {
851       val3=val1->minus(val2);
852     }
853   catch(INTERP_KERNEL::Exception& e)
854     {
855       delete val1;
856       throw e;
857     }
858   delete val1;
859   delete val2;
860   val2=val3;
861 }
862
863 void MinusFunction::operateX86(std::vector<std::string>& asmb) const
864 {
865   asmb.push_back("fsubp st1");
866 }
867
868 void MinusFunction::operateStackOfDouble(std::vector<double>& stck) const
869 {
870   double a(stck.back());
871   stck.pop_back();
872   stck.back()=a-stck.back();
873 }
874
875 const char *MinusFunction::getRepr() const
876 {
877   return REPR;
878 }
879
880 bool MinusFunction::isACall() const
881 {
882   return false;
883 }
884
885 MultFunction::~MultFunction()
886 {
887 }
888
889 void MultFunction::operate(std::vector<Value *>& stck) const
890 {
891   Value *val1=stck.back();
892   stck.pop_back();
893   Value *& val2=stck.back();
894   Value *val3=val1->mult(val2);
895   delete val1;
896   delete val2;
897   val2=val3;
898 }
899
900 void MultFunction::operateX86(std::vector<std::string>& asmb) const
901 {
902   asmb.push_back("fmulp st1");
903 }
904
905 void MultFunction::operateStackOfDouble(std::vector<double>& stck) const
906 {
907   double a(stck.back());
908   stck.pop_back();
909   stck.back()=a*stck.back();
910 }
911
912 const char *MultFunction::getRepr() const
913 {
914   return REPR;
915 }
916
917 bool MultFunction::isACall() const
918 {
919   return false;
920 }
921
922 DivFunction::~DivFunction()
923 {
924 }
925
926 void DivFunction::operate(std::vector<Value *>& stck) const
927 {
928   Value *val1=stck.back();
929   stck.pop_back();
930   Value *& val2=stck.back();
931   Value *val3;
932   try
933     {
934       val3=val1->div(val2);
935     }
936   catch(INTERP_KERNEL::Exception& e)
937     {
938       delete val1;
939       throw e;
940     }
941   delete val1;
942   delete val2;
943   val2=val3;
944 }
945
946 void DivFunction::operateX86(std::vector<std::string>& asmb) const
947 {
948   asmb.push_back("fdivp st1");
949 }
950
951 void DivFunction::operateStackOfDouble(std::vector<double>& stck) const
952 {
953   double a(stck.back());
954   stck.pop_back();
955   stck.back()=a/stck.back();
956 }
957
958 void DivFunction::operateStackOfDoubleSafe(std::vector<double>& stck) const
959 {
960   double a(stck.back());
961   stck.pop_back();
962   if(stck.back()==0.)
963     throw INTERP_KERNEL::Exception("division by 0. !");
964   stck.back()=a/stck.back();
965 }
966
967 const char *DivFunction::getRepr() const
968 {
969   return REPR;
970 }
971
972 bool DivFunction::isACall() const
973 {
974   return false;
975 }
976
977 PowFunction::~PowFunction()
978 {
979 }
980
981 void PowFunction::operate(std::vector<Value *>& stck) const
982 {
983   Value *val1=stck.back();
984   stck.pop_back();
985   Value *& val2=stck.back();
986   Value *val3;
987   try
988     {
989       val3=val1->pow(val2);
990     }
991   catch(INTERP_KERNEL::Exception& e)
992     {
993       delete val1;
994       throw e;
995     }
996   delete val1;
997   delete val2;
998   val2=val3;
999 }
1000
1001 void PowFunction::operateX86(std::vector<std::string>& asmb) const
1002 {
1003   throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
1004 }
1005
1006 void PowFunction::operateStackOfDouble(std::vector<double>& stck) const
1007 {
1008   double a(stck.back());
1009   stck.pop_back();
1010   stck.back()=std::pow(a,stck.back());
1011 }
1012
1013 void PowFunction::operateStackOfDoubleSafe(std::vector<double>& stck) const
1014 {
1015   double a(stck.back());
1016   stck.pop_back();
1017   double b(stck.back());
1018   if(a<0.)
1019     throw INTERP_KERNEL::Exception("pow with val < 0. !");
1020   stck.back()=std::pow(a,b);
1021 }
1022
1023 const char *PowFunction::getRepr() const
1024 {
1025   return REPR;
1026 }
1027
1028 bool PowFunction::isACall() const
1029 {
1030   return true;
1031 }
1032
1033 ExpFunction::~ExpFunction()
1034 {
1035 }
1036
1037 MaxFunction::~MaxFunction()
1038 {
1039 }
1040
1041 void MaxFunction::operate(std::vector<Value *>& stck) const
1042 {
1043   Value *val1=stck.back();
1044   stck.pop_back();
1045   Value *& val2=stck.back();
1046   Value *val3;
1047   try
1048     {
1049       val3=val1->max(val2);
1050     }
1051   catch(INTERP_KERNEL::Exception& e)
1052     {
1053       delete val1;
1054       throw e;
1055     }
1056   delete val1;
1057   delete val2;
1058   val2=val3;
1059 }
1060
1061 void MaxFunction::operateX86(std::vector<std::string>& asmb) const
1062 {
1063   throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
1064 }
1065
1066 void MaxFunction::operateStackOfDouble(std::vector<double>& stck) const
1067 {
1068   double a(stck.back());
1069   stck.pop_back();
1070   stck.back()=std::max(stck.back(),a);
1071 }
1072
1073 const char *MaxFunction::getRepr() const
1074 {
1075   return REPR;
1076 }
1077
1078 bool MaxFunction::isACall() const
1079 {
1080   return false;
1081 }
1082
1083 MinFunction::~MinFunction()
1084 {
1085 }
1086
1087 void MinFunction::operate(std::vector<Value *>& stck) const
1088 {
1089   Value *val1=stck.back();
1090   stck.pop_back();
1091   Value *& val2=stck.back();
1092   Value *val3;
1093   try
1094     {
1095       val3=val1->min(val2);
1096     }
1097   catch(INTERP_KERNEL::Exception& e)
1098     {
1099       delete val1;
1100       throw e;
1101     }
1102   delete val1;
1103   delete val2;
1104   val2=val3;
1105 }
1106
1107 void MinFunction::operateX86(std::vector<std::string>& asmb) const
1108 {
1109   throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
1110 }
1111
1112 void MinFunction::operateStackOfDouble(std::vector<double>& stck) const
1113 {
1114   double a(stck.back());
1115   stck.pop_back();
1116   stck.back()=std::min(stck.back(),a);
1117 }
1118
1119 const char *MinFunction::getRepr() const
1120 {
1121   return REPR;
1122 }
1123
1124 bool MinFunction::isACall() const
1125 {
1126   return false;
1127 }
1128
1129 GreaterThanFunction::~GreaterThanFunction()
1130 {
1131 }
1132
1133 void GreaterThanFunction::operate(std::vector<Value *>& stck) const
1134 {
1135   Value *val1=stck.back();
1136   stck.pop_back();
1137   Value *& val2=stck.back();
1138   Value *val3;
1139   try
1140     {
1141       val3=val1->greaterThan(val2);
1142     }
1143   catch(INTERP_KERNEL::Exception& e)
1144     {
1145       delete val1;
1146       throw e;
1147     }
1148   delete val1;
1149   delete val2;
1150   val2=val3;
1151 }
1152
1153 void GreaterThanFunction::operateX86(std::vector<std::string>& asmb) const
1154 {
1155   throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
1156 }
1157
1158 void GreaterThanFunction::operateStackOfDouble(std::vector<double>& stck) const
1159 {
1160   double a(stck.back());
1161   stck.pop_back();
1162   double b(stck.back());
1163   stck.back()=a>b?std::numeric_limits<double>::max():-std::numeric_limits<double>::max();
1164 }
1165
1166 const char *GreaterThanFunction::getRepr() const
1167 {
1168   return REPR;
1169 }
1170
1171 bool GreaterThanFunction::isACall() const
1172 {
1173   return false;
1174 }
1175
1176 LowerThanFunction::~LowerThanFunction()
1177 {
1178 }
1179
1180 void LowerThanFunction::operate(std::vector<Value *>& stck) const
1181 {
1182   Value *val1=stck.back();
1183   stck.pop_back();
1184   Value *& val2=stck.back();
1185   Value *val3;
1186   try
1187     {
1188       val3=val1->lowerThan(val2);
1189     }
1190   catch(INTERP_KERNEL::Exception& e)
1191     {
1192       delete val1;
1193       throw e;
1194     }
1195   delete val1;
1196   delete val2;
1197   val2=val3;
1198 }
1199
1200 void LowerThanFunction::operateX86(std::vector<std::string>& asmb) const
1201 {
1202   throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
1203 }
1204
1205 void LowerThanFunction::operateStackOfDouble(std::vector<double>& stck) const
1206 {
1207   double a(stck.back());
1208   stck.pop_back();
1209   double b(stck.back());
1210   stck.back()=a<b?std::numeric_limits<double>::max():-std::numeric_limits<double>::max();
1211 }
1212
1213 const char *LowerThanFunction::getRepr() const
1214 {
1215   return REPR;
1216 }
1217
1218 bool LowerThanFunction::isACall() const
1219 {
1220   return false;
1221 }
1222
1223 int TernaryFunction::getNbInputParams() const
1224 {
1225   return 3;
1226 }
1227
1228 IfFunction::~IfFunction()
1229 {
1230 }
1231
1232 void IfFunction::operate(std::vector<Value *>& stck) const
1233 {
1234   Value *val1=stck.back();
1235   stck.pop_back();
1236   Value *val2=stck.back();
1237   stck.pop_back();
1238   Value *&val3=stck.back();
1239   Value *val4;
1240   try
1241     {
1242       val4=val1->ifFunc(val2,val3);
1243     }
1244   catch(INTERP_KERNEL::Exception& e)
1245     {
1246       delete val1;
1247       delete val2;
1248       throw e;
1249     }
1250   delete val1;
1251   delete val2;
1252   delete val3;
1253   val3=val4;
1254 }
1255
1256 void IfFunction::operateX86(std::vector<std::string>& asmb) const
1257 {
1258   throw INTERP_KERNEL::Exception("Assembly Not implemented yet !");
1259 }
1260
1261 void IfFunction::operateStackOfDouble(std::vector<double>& stck) const
1262 {
1263   double cond(stck.back());
1264   stck.pop_back();
1265   double the(stck.back());
1266   stck.pop_back();
1267   if(cond==std::numeric_limits<double>::max())
1268     stck.back()=the;
1269 }
1270
1271 void IfFunction::operateStackOfDoubleSafe(std::vector<double>& stck) const
1272 {
1273   double cond(stck.back());
1274   stck.pop_back();
1275   double the(stck.back());
1276   stck.pop_back();
1277   if(cond!=std::numeric_limits<double>::max() && cond!=-std::numeric_limits<double>::max())
1278     throw INTERP_KERNEL::Exception("ifFunc : first parameter of ternary func is NOT a consequence of a boolean op !");
1279   if(cond==std::numeric_limits<double>::max())
1280     stck.back()=the;
1281 }
1282
1283 const char *IfFunction::getRepr() const
1284 {
1285   return REPR;
1286 }
1287
1288 bool IfFunction::isACall() const
1289 {
1290   return false;
1291 }
1292