Quantum++  v1.0-rc4
A modern C++11 quantum computing library
constants.h
Go to the documentation of this file.
1 /*
2  * This file is part of Quantum++.
3  *
4  * MIT License
5  *
6  * Copyright (c) 2013 - 2018 Vlad Gheorghiu (vgheorgh@gmail.com)
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26 
32 #ifndef CONSTANTS_H_
33 #define CONSTANTS_H_
34 
35 namespace qpp {
41 inline constexpr cplx operator"" _i(unsigned long long int x) noexcept {
42  return {0., static_cast<double>(x)};
43 }
44 
50 inline constexpr cplx operator"" _i(long double x) noexcept {
51  return {0., static_cast<double>(x)};
52 }
53 
58 constexpr double chop = 1e-10;
59 
66 constexpr double eps = 1e-12;
67 
73 constexpr idx maxn = 64; // maximum number of qubits/qudits a state may have
74 
78 constexpr double pi = 3.141592653589793238462643383279502884;
82 constexpr double ee = 2.718281828459045235360287471352662497;
83 
87 constexpr double infty = std::numeric_limits<double>::max();
88 
95 inline cplx omega(idx D) {
96  if (D == 0)
97  throw exception::OutOfRange("qpp::omega()");
98  return exp(2.0 * pi * 1_i / static_cast<double>(D));
99 }
100 
101 } /* namespace qpp */
102 
103 #endif /* CONSTANTS_H_ */
constexpr double chop
Used in qpp::disp() for setting to zero numbers that have their absolute value smaller than qpp::chop...
Definition: constants.h:58
constexpr idx maxn
Maximum number of allowed qubits/qudits (subsystems)
Definition: constants.h:73
cplx omega(idx D)
D-th root of unity.
Definition: constants.h:95
constexpr double eps
Used to decide whether a number or expression in double precision is zero or not. ...
Definition: constants.h:66
Quantum++ main namespace.
Definition: codes.h:35
std::complex< double > cplx
Complex number in double precision.
Definition: types.h:49
constexpr double infty
Used to denote infinity in double precision.
Definition: constants.h:87
constexpr double pi
Definition: constants.h:78
Parameter out of range exception.
Definition: exception.h:513
std::size_t idx
Non-negative integer index.
Definition: types.h:39
constexpr double ee
Base of natural logarithm, .
Definition: constants.h:82