PageRenderTime 20ms CodeModel.GetById 19ms app.highlight 0ms RepoModel.GetById 0ms app.codeStats 0ms

/jcl/examples/common/expreval/ExprEvalExampleLogic.pas

https://github.com/the-Arioch/jcl
Pascal | 105 lines | 93 code | 10 blank | 2 comment | 0 complexity | fe7747b0693df96fa0f01326a2cc72ec MD5 | raw file
Possible License(s): BSD-3-Clause
  1unit ExprEvalExampleLogic;
  2
  3interface
  4
  5uses
  6  SysUtils, Classes, JclExprEval;
  7
  8procedure Init(Evaluator: TEasyEvaluator; FuncList: TStrings);
  9function ResultAsText(Evaluator: TEvaluator; const Input: string): string;
 10
 11implementation
 12
 13uses
 14  JclMath;
 15
 16procedure Init(Evaluator: TEasyEvaluator; FuncList: TStrings);
 17begin
 18  with Evaluator do
 19  begin
 20    // Constants
 21    AddConst('Pi', Pi);
 22
 23    // Functions
 24    AddFunc('LogBase10', LogBase10);
 25    AddFunc('LogBase2', LogBase2);
 26    AddFunc('LogBaseN', LogBaseN);
 27    AddFunc('ArcCos', ArcCos);
 28    AddFunc('ArcCot', ArcCot);
 29    AddFunc('ArcCsc', ArcCsc);
 30    AddFunc('ArcSec', ArcSec);
 31    AddFunc('ArcSin', ArcSin);
 32    AddFunc('ArcTan', ArcTan);
 33    AddFunc('ArcTan2', ArcTan2);
 34    AddFunc('Cos', Cos);
 35    AddFunc('Cot', Cot);
 36    AddFunc('Coversine', Coversine);
 37    AddFunc('Csc', Csc);
 38    AddFunc('Exsecans', Exsecans);
 39    AddFunc('Haversine', Haversine);
 40    AddFunc('Sec', Sec);
 41    AddFunc('Sin', Sin);
 42    AddFunc('Tan', Tan);
 43    AddFunc('Versine', Versine);
 44    AddFunc('ArcCosH', ArcCosH);
 45    AddFunc('ArcCotH', ArcCotH);
 46    AddFunc('ArcCscH', ArcCscH);
 47    AddFunc('ArcSecH', ArcSecH);
 48    AddFunc('ArcSinH', ArcSinH);
 49    AddFunc('ArcTanH', ArcTanH);
 50    AddFunc('CosH', CosH);
 51    AddFunc('CotH', CotH);
 52    AddFunc('CscH', CscH);
 53    AddFunc('SecH', SecH);
 54    AddFunc('SinH', SinH);
 55    AddFunc('TanH', TanH);
 56  end;
 57  with FuncList do
 58  begin
 59    Add('LogBase10');
 60    Add('LogBase2');
 61    Add('LogBaseN');
 62    Add('ArcCos');
 63    Add('ArcCot');
 64    Add('ArcCsc');
 65    Add('ArcSec');
 66    Add('ArcSin');
 67    Add('ArcTan');
 68    Add('ArcTan2');
 69    Add('Cos');
 70    Add('Cot');
 71    Add('Coversine');
 72    Add('Csc');
 73    Add('Exsecans');
 74    Add('Haversine');
 75    Add('Sec');
 76    Add('Sin');
 77    Add('Tan');
 78    Add('Versine');
 79    Add('ArcCosH');
 80    Add('ArcCotH');
 81    Add('ArcCscH');
 82    Add('ArcSecH');
 83    Add('ArcSinH');
 84    Add('ArcTanH');
 85    Add('CosH');
 86    Add('CotH');
 87    Add('CscH');
 88    Add('SecH');
 89    Add('SinH');
 90    Add('TanH');
 91  end;
 92end;
 93
 94function ResultAsText(Evaluator: TEvaluator; const Input: string): string;
 95begin
 96  try
 97    Result := FloatToStr(Evaluator.Evaluate(Input));
 98  except
 99    on E: Exception do
100      Result := E.Message;
101  end;
102end;
103
104
105end.