CLHEP VERSION Reference Documentation
CLHEP Home Page
CLHEP Documentation
CLHEP Bug Reports
Evaluator
test
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
16
int
main
() {
17
char
exp[240];
18
HepTool::Evaluator
eval
;
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()) {
41
case
HepTool::Evaluator::OK
:
42
std::cout << value << std::endl;
43
break
;
44
case
HepTool::Evaluator::WARNING_BLANK_STRING
:
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
}
Evaluator.h
HepTool::Evaluator
Definition
Evaluator/Evaluator.h:26
HepTool::Evaluator::setVariable
void setVariable(const char *name, double value)
Definition
Evaluator.cc:688
HepTool::Evaluator::WARNING_BLANK_STRING
@ WARNING_BLANK_STRING
Definition
CLHEP/Evaluator/Evaluator.h:43
HepTool::Evaluator::OK
@ OK
Definition
CLHEP/Evaluator/Evaluator.h:40
eval
double eval(std::string expr, int &numbad, std::ofstream &os)
Definition
testBug66214.cc:11
main
int main()
Definition
testEvaluator.cc:16
Generated by
1.12.0