CLHEP/test/testEvaluator.cc
// -*- C++ -*-
// $Id: testEvaluator.cc,v 1.4 2001/06/15 08:37:04 evc Exp $
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is a test for the Evaluator class.
// It can be also used as a scientific caculator.
//
#include "CLHEP/Evaluator/Evaluator.h"
#include "CLHEP/config/iostream.h"
#include <string.h>
#include <assert.h>
int main() {
char exp[240];
HepTool::Evaluator eval;
eval.setVariable(" dummy ", 0.); // these three lines have been
assert( eval.findVariable(" dummy ") ); // included just for test
eval.clear(); // ===========================
eval.setStdMath(); // set standard constants and functions
eval.setSystemOfUnits(); // set SI units
HepStd::cout.precision(15);
for(;;) {
HepStd::cout << "CALC> ";
// In principle, next two lines could be replaced with just
// HepStd::cin.getline(exp, 240); but that does not work on DEC
// because of bug in the cxx V6.1-027 compiler.
HepStd::cin.get(exp, 240);
HepStd::cin.ignore();
if ( !HepStd::cin || strcmp(exp,"exit") == 0 || strcmp(exp,"quit") == 0) {
HepStd::cout << HepStd::endl;
break; // exit
}
double value = eval.evaluate(exp);
switch(eval.status()) {
case HepTool::Evaluator::OK:
HepStd::cout << value << HepStd::endl;
break;
case HepTool::Evaluator::WARNING_BLANK_STRING:
continue;
default:
HepStd::cout << "------";
for (int i=0; i<eval.error_position(); i++) HepStd::cout << "-";
HepStd::cout << "^" << HepStd::endl;
eval.print_error();
}
HepStd::cout << HepStd::endl;
}
return 0;
}
Generated by GNU enscript 1.6.1.