23#ifndef RestCore_TRestComplex
24#define RestCore_TRestComplex
43 TRestComplex(mpfr::mpreal re, mpfr::mpreal im = 0, Bool_t polar = kFALSE);
46 static void SetPrecision(Int_t precision) {
47 mpfr::mpreal::set_default_prec(mpfr::digits2bits(precision));
50 static int GetPrecision() {
return mpfr::bits2digits(mpfr::mpreal::get_default_prec()); }
57 mpfr::mpreal Re()
const {
return fRe; }
58 mpfr::mpreal Im()
const {
return fIm; }
59 mpfr::mpreal Rho()
const {
return mpfr::sqrt(
fRe *
fRe +
fIm *
fIm); }
60 mpfr::mpreal Rho2()
const {
return fRe *
fRe +
fIm *
fIm; }
61 mpfr::mpreal Theta()
const {
return (
fIm ||
fRe) ? mpfr::atan2(
fIm,
fRe) : 0; }
62 TRestComplex operator()(mpfr::mpreal x, mpfr::mpreal y, Bool_t polar = kFALSE) {
64 fRe = x * mpfr::cos(y);
65 fIm = x * mpfr::sin(y);
112 operator Double_t()
const {
return static_cast<Double_t
>(
fRe); }
113 operator Float_t()
const {
return static_cast<Float_t
>(
fRe); }
114 operator Int_t()
const {
return static_cast<Int_t
>(
fRe); }
118 return TRestComplex(mpfr::sqrt(c.Rho()), 0.5 * c.Theta(), kTRUE);
123 return TRestComplex(0.5 * mpfr::log(c.Rho2()), c.Theta());
136 return Sin(c) * Conjugate(cc) / cc.Rho2();
139 inline int Sign(
const mpfr::mpreal& re,
const mpfr::mpreal& im) {
155 return -0.5 * I() * Log((1. + I() * c) / (1. - I() * c));
166 return SinH(c) * Conjugate(cc) / cc.Rho2();
181 static mpfr::mpreal Abs(
const TRestComplex& c) {
return c.Rho(); }
184 mpfr::mpreal lrho = mpfr::log(x.Rho());
185 mpfr::mpreal theta = x.Theta();
186 return TRestComplex(mpfr::exp(lrho * y.Re() - theta * y.Im()), lrho * y.Im() + theta * y.Re(), kTRUE);
189 return TRestComplex(mpfr::pow(x.Rho(), y), x.Theta() * y, kTRUE);
192 mpfr::mpreal lrho = mpfr::log(mpfr::abs(x));
193 mpfr::mpreal theta = (x > 0) ? 0 : mpfr::const_pi();
194 return TRestComplex(mpfr::exp(lrho * y.Re() - theta * y.Im()), lrho * y.Im() + theta * y.Re(), kTRUE);
197 return TRestComplex(mpfr::pow(x.Rho(), y), x.Theta() * y, kTRUE);
200 static Int_t IsNaN(
const TRestComplex& c) {
return mpfr::isnan(c.Re()) || mpfr::isnan(c.Im()); }
203 return a.Rho() <= b.Rho() ? a : b;
206 return a.Rho() >= b.Rho() ? a : b;
211 return Max(lb, Min(c, ub));
215 friend std::ostream& operator<<(std::ostream& out,
const TRestComplex& c);
216 friend std::istream& operator>>(std::istream& in,
TRestComplex& c);
A generic class to handle complex numbers with real precision.
static TRestComplex ASinH(const TRestComplex &c)
int Sign(const mpfr::mpreal &re, const mpfr::mpreal &im)
mpfr::mpreal fIm
The imaginary part of the complex number using MPFR precision.
static TRestComplex ASin(const TRestComplex &c)
static TRestComplex ACos(const TRestComplex &c)
static TRestComplex ACosH(const TRestComplex &c)
mpfr::mpreal fRe
The real part of the complex number using MPFR precision.