C++QEDCore  v2 Milestone 10
a framework for simulating open quantum dynamics – core
MathExtensions.h
Go to the documentation of this file.
1 // Copyright András Vukics 2006–2014. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.txt)
2 // -*- C++ -*-
7 #ifndef CPPQEDCORE_UTILS_MATHEXTENSIONS_H_INCLUDED
8 #define CPPQEDCORE_UTILS_MATHEXTENSIONS_H_INCLUDED
9 
10 #include "MathExtensionsFwd.h"
11 
12 #include "ComplexExtensions.h"
13 #include "Exception.h"
14 
15 
17 namespace mathutils {
18 
19 struct FactOverflow : public cpputils::Exception {};
20 
21 extern const double PI ;
22 extern const double SQRTPI;
23 extern const double EULER ;
24 
25 int sign(double);
26 int fcmp(double, double, double);
27 
28 template<class T> const T sqr(T x) {return x*x;}
29 
30 double sqr(double x);
31 
32 double sqrAbs(const dcomp&);
33 
34 double fact (unsigned ) throw(FactOverflow);
35 double choose(unsigned, unsigned);
36 
37 template<typename T>
38 bool parity(T n) { return n & 1;}
39 // even --- false, odd --- true;
40 
41 
42 inline int round(double r) {
43  return (r>0) ? floor(r+0.5) : ceil(r-0.5);
44 }
45 
46 template<typename T>
47 char minusOneToThePowerOf(T n) {return parity(n) ? -1 : 1;}
48 
49 
51 
58 dcomp coherentElement(unsigned long n, const dcomp& alpha);
59 
60 } // mathutils
61 
62 #endif // CPPQEDCORE_UTILS_MATHEXTENSIONS_H_INCLUDED
The class that is (meant to be, at least) the base of all exceptions in the framework.
Definition: Exception.h:18
dcomp coherentElement(unsigned long n, const dcomp &alpha)
Calculates relying on the Stirling formula if is too large for explicit calculation of factorial...
Additional helpers for dcomp.
Comprises wrapper functions for mathematical functions taken from libraries (Boost.Math, GSL), and several other mathematical functions.
std::complex< double > dcomp
Double-precision complex number.
Defines tentative base classes for the exception classes of the framework.