CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
testEvaluator.cc
Go to the documentation of this file.
1// -*- C++ -*-
2// $Id: testEvaluator.cc,v 1.1 2003/07/16 21:47:28 garren Exp $
3// ---------------------------------------------------------------------------
4//
5// This file is a part of the CLHEP - a Class Library for High Energy Physics.
6//
7// This is a test for the Evaluator class.
8// It can be also used as a scientific caculator.
9//
10
11#include "CLHEP/Evaluator/Evaluator.h"
12#include <iostream>
13#include <string.h>
14#include <assert.h>
15
16int main() {
17 char exp[240];
19
20 eval.setVariable(" dummy ", 0.); // these three lines have been
21 assert( eval.findVariable(" dummy ") ); // included just for test
22 eval.clear(); // ===========================
23
24 eval.setStdMath(); // set standard constants and functions
25 eval.setSystemOfUnits(); // set SI units
26 std::cout.precision(15);
27 for(;;) {
28 std::cout << "CALC> ";
29
30 // In principle, next two lines could be replaced with just
31 // std::cin.getline(exp, 240); but that does not work on DEC
32 // because of bug in the cxx V6.1-027 compiler.
33 std::cin.get(exp, 240);
34 std::cin.ignore();
35 if ( !std::cin || strcmp(exp,"exit") == 0 || strcmp(exp,"quit") == 0) {
36 std::cout << std::endl;
37 break; // exit
38 }
39 double value = eval.evaluate(exp);
40 switch(eval.status()) {
42 std::cout << value << std::endl;
43 break;
45 continue;
46 default:
47 std::cout << "------";
48 for (int i=0; i<eval.error_position(); i++) std::cout << "-";
49 std::cout << "^" << std::endl;
50 eval.print_error();
51 }
52 std::cout << std::endl;
53 }
54 return 0;
55}
double eval(std::string expr, int &numbad, std::ofstream &os)
Definition: testBug66214.cc:11
int main()