Quantum++  v1.1
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 - 2019 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 {
36 inline namespace literals {
42 inline constexpr cplx operator"" _i(unsigned long long int x) noexcept {
43  return {0., static_cast<double>(x)};
44 }
45 } /* inline namespace literals */
46 
52 inline constexpr cplx operator"" _i(long double x) noexcept {
53  return {0., static_cast<double>(x)};
54 }
55 
60 constexpr double chop = 1e-10;
61 
68 constexpr double eps = 1e-12;
69 
75 constexpr idx maxn = 64; // maximum number of qubits/qudits a state may have
76 
80 constexpr double pi = 3.141592653589793238462643383279502884;
84 constexpr double ee = 2.718281828459045235360287471352662497;
85 
89 constexpr double infty = std::numeric_limits<double>::max();
90 
97 inline cplx omega(idx D) {
98  if (D == 0)
99  throw exception::OutOfRange("qpp::omega()");
100  return exp(2.0 * pi * 1_i / static_cast<double>(D));
101 }
102 
103 } /* namespace qpp */
104 
105 #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:60
constexpr idx maxn
Maximum number of allowed qubits/qudits (subsystems)
Definition: constants.h:75
cplx omega(idx D)
D-th root of unity.
Definition: constants.h:97
constexpr double eps
Used to decide whether a number or expression in double precision is zero or not. ...
Definition: constants.h:68
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:89
constexpr double pi
Definition: constants.h:80
Parameter out of range exception.
Definition: exception.h:515
std::size_t idx
Non-negative integer index.
Definition: types.h:39
constexpr double ee
Base of natural logarithm, .
Definition: constants.h:84