/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id: RooComplex.h,v 1.13 2007/05/11 09:11:30 verkerke Exp $
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/
#ifndef ROO_COMPLEX
#define ROO_COMPLEX

#if !defined(ROO_MATH) && !defined(ROO_COMPLEX_CXX) && !defined(__CINT__) && !defined(__CLING__) && \
    !defined(R__DICTIONARY_FILENAME)
#warning "RooComplex is deprecated, use std::complex instead!"
#endif

#include <math.h>
#include "Rtypes.h"
#include "Riosfwd.h"
#include <complex>

// This is a bare-bones complex class adapted from the CINT complex.h header,
// and introduced to support the complex error function in RooMath. The main
// changes with respect to the CINT header are to avoid defining global
// functions (at the cost of not supporting implicit casts on the first
// argument) and adding const declarations where appropriate.

class RooComplex {
public:

  inline RooComplex(std::complex<Double_t> c) : _re(c.real()), _im(c.imag()) { }

  inline RooComplex(Double_t a=0, Double_t b=0) : _re(a), _im(b) { warn(); }
  virtual ~RooComplex() { }
  inline RooComplex& operator=(const RooComplex& other) {
    warn();
    if (&other==this) return *this ;
    this->_re= other._re;
    this->_im= other._im;
    return(*this);
  }
  // unary operators
  inline RooComplex operator-() const {
    return RooComplex(-_re,-_im);
  }
  // binary operators
  inline RooComplex operator+(const RooComplex& other) const {
    return RooComplex(this->_re + other._re, this->_im + other._im);
  }
  inline RooComplex operator-(const RooComplex& other) const {
    return RooComplex(this->_re - other._re, this->_im - other._im);
  }
  inline RooComplex operator*(const RooComplex& other) const {
    return RooComplex(this->_re*other._re - this->_im*other._im,
		      this->_re*other._im + this->_im*other._re);
  }
  inline RooComplex operator/(const RooComplex& other) const {
    Double_t x(other.abs2());
    return RooComplex((this->_re*other._re + this->_im*other._im)/x,
		      (this->_im*other._re - this->_re*other._im)/x);
  }
  inline RooComplex operator*(const Double_t& other) const {
    return RooComplex(this->_re*other,this->_im*other);
  }


  inline Bool_t operator==(const RooComplex& other) const {
    return (_re==other._re && _im==other._im) ;
  }

  // unary functions
  inline Double_t re() const {
    return _re;
  }
  inline Double_t im() const {
    return _im;
  }
  inline Double_t abs() const {
    return ::sqrt(_re*_re + _im*_im);
  }
  inline Double_t abs2() const {
    return _re*_re + _im*_im;
  }
  inline RooComplex exp() const {
    Double_t mag(::exp(_re));
    return RooComplex(mag*cos(_im),mag*sin(_im));
  }
  inline RooComplex conj() const {
    return RooComplex(_re,-_im);
  }
  inline RooComplex sqrt() const {
    Double_t arg=atan2(_im,_re)*0.5;
    Double_t mag=::sqrt(::sqrt(_re*_re + _im*_im));
    return RooComplex(mag*cos(arg),mag*sin(arg));
  }
  // ouptput formatting
  void Print() const;
private:
  Double_t _re,_im;

  void warn() const;

  ClassDef(RooComplex,0) // a non-persistent bare-bones complex class
};

// output formatting
std::ostream& operator<<(std::ostream& os, const RooComplex& z);

#endif
 RooComplex.h:1
 RooComplex.h:2
 RooComplex.h:3
 RooComplex.h:4
 RooComplex.h:5
 RooComplex.h:6
 RooComplex.h:7
 RooComplex.h:8
 RooComplex.h:9
 RooComplex.h:10
 RooComplex.h:11
 RooComplex.h:12
 RooComplex.h:13
 RooComplex.h:14
 RooComplex.h:15
 RooComplex.h:16
 RooComplex.h:17
 RooComplex.h:18
 RooComplex.h:19
 RooComplex.h:20
 RooComplex.h:21
 RooComplex.h:22
 RooComplex.h:23
 RooComplex.h:24
 RooComplex.h:25
 RooComplex.h:26
 RooComplex.h:27
 RooComplex.h:28
 RooComplex.h:29
 RooComplex.h:30
 RooComplex.h:31
 RooComplex.h:32
 RooComplex.h:33
 RooComplex.h:34
 RooComplex.h:35
 RooComplex.h:36
 RooComplex.h:37
 RooComplex.h:38
 RooComplex.h:39
 RooComplex.h:40
 RooComplex.h:41
 RooComplex.h:42
 RooComplex.h:43
 RooComplex.h:44
 RooComplex.h:45
 RooComplex.h:46
 RooComplex.h:47
 RooComplex.h:48
 RooComplex.h:49
 RooComplex.h:50
 RooComplex.h:51
 RooComplex.h:52
 RooComplex.h:53
 RooComplex.h:54
 RooComplex.h:55
 RooComplex.h:56
 RooComplex.h:57
 RooComplex.h:58
 RooComplex.h:59
 RooComplex.h:60
 RooComplex.h:61
 RooComplex.h:62
 RooComplex.h:63
 RooComplex.h:64
 RooComplex.h:65
 RooComplex.h:66
 RooComplex.h:67
 RooComplex.h:68
 RooComplex.h:69
 RooComplex.h:70
 RooComplex.h:71
 RooComplex.h:72
 RooComplex.h:73
 RooComplex.h:74
 RooComplex.h:75
 RooComplex.h:76
 RooComplex.h:77
 RooComplex.h:78
 RooComplex.h:79
 RooComplex.h:80
 RooComplex.h:81
 RooComplex.h:82
 RooComplex.h:83
 RooComplex.h:84
 RooComplex.h:85
 RooComplex.h:86
 RooComplex.h:87
 RooComplex.h:88
 RooComplex.h:89
 RooComplex.h:90
 RooComplex.h:91
 RooComplex.h:92
 RooComplex.h:93
 RooComplex.h:94
 RooComplex.h:95
 RooComplex.h:96
 RooComplex.h:97
 RooComplex.h:98
 RooComplex.h:99
 RooComplex.h:100
 RooComplex.h:101
 RooComplex.h:102
 RooComplex.h:103
 RooComplex.h:104
 RooComplex.h:105
 RooComplex.h:106
 RooComplex.h:107
 RooComplex.h:108
 RooComplex.h:109
 RooComplex.h:110
 RooComplex.h:111
 RooComplex.h:112
 RooComplex.h:113
 RooComplex.h:114
 RooComplex.h:115
 RooComplex.h:116