Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TComplex.cxx
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: Federico Carminati 22/04/2004
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TComplex //
15 // //
16 //////////////////////////////////////////////////////////////////////////
17 
18 #include "TComplex.h"
19 #include "Riostream.h"
20 
21 #include <sstream>
22 
23 ClassImp(TComplex);
24 
25 ////////////////////////////////////////////////////////////////////////////////
26 /// Standard constructor
27 
28 TComplex::TComplex(Double_t re, Double_t im, Bool_t polar) : fRe(re), fIm(im)
29 {
30  if (polar) {
31  if(re<0) {
32  ::Warning("TComplex::ctor","Modulo of a complex number should be >=0, taking the abs");
33  re=-re;
34  }
35  fRe=re*TMath::Cos(im);
36  fIm=re*TMath::Sin(im);
37  }
38 }
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 
42 std::ostream& operator<<(std::ostream& out, const TComplex& c)
43 {
44  out << "(" << c.fRe << "," << c.fIm << "i)";
45  return out;
46 }
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 
50 std::istream& operator>>(std::istream& in, TComplex& c)
51 {
52  in >> c.fRe >> c.fIm;
53  return in;
54 }
55 
56 namespace cling {
57 std::string printValue(TComplex *c)
58 {
59  std::stringstream s;
60  s << *c;
61  return s.str();
62 }
63 }