CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
testUnits.cc
Go to the documentation of this file.
1// -*- C++ -*-
2// $Id: testUnits.cc,v 1.4 2011/07/20 23:00:04 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 small program for testing the Units module
8//
9
10#include <assert.h>
11#include "CLHEP/Units/defs.h"
12#include "CLHEP/Units/PhysicalConstants.h"
13#include <iostream>
14#include <iomanip>
15#include <sstream>
16#include <cmath>
17
18#if (defined __STRICT_ANSI__) || (defined _WIN32)
19#ifndef M_PI
20#define M_PI 3.14159265358979323846
21#endif // M_PI
22#endif // __STRICT_ANSI__
23
24int main() {
25
26 int nbad=0;
27
28 // Check that local m does not interfere with global m
29
30 double m=0;
31 for (int i=0; i<7; i++, m++) { assert(m == double(i)); }
32 assert(m != CLHEP::meter);
33
34 //std::cout << "Speed of light is " << std::setw(10) << std::setprecision(8)
35 // << CLHEP::c_light << std::endl;
36 //output: Speed of light is 299.79246
37
38 std::ostringstream os1, os2, os3, os4;
39 os1 << std::setprecision(8) << CLHEP::c_light;
40 os2 << "299.79246";
41 if( os1.str() != os2.str() ) {
42 std::cout << "compare --" << os1.str() << "-- to --" << os2.str() << "--" << std::endl;
43 nbad++;
44 }
45 os3 << std::setprecision(16) << CLHEP::pi ;
46 os4 << "3.141592653589793";
47 if( os3.str() != os4.str() ) {
48 nbad++;
49 std::cout << "compare --" << os3.str() << "--" << std::endl;
50 std::cout << " to --" << os4.str() << "--" << std::endl;
51 std::cout << "M_PI --" << std::setprecision(16) << M_PI << "--" << std::endl;
52 }
53
54 return nbad;
55
56}
int main()
Definition: testUnits.cc:24