QuEST_precision.h
1// Distributed under MIT licence. See https://github.com/QuEST-Kit/QuEST/blob/master/LICENCE.txt for details
2
13# ifndef QUEST_PRECISION_H
14# define QUEST_PRECISION_H
15
16# include <math.h>
17
18
19// define CUDA complex types as void if not using cuQuantum.
20// note we used cuComplex.h for complex numbers, in lieu of
21// Thrust's complex<qreal>, so that the QuEST.h header can
22// always be compiled with C99, rather than C++14.
23# ifdef USE_CUQUANTUM
24 # include <cuComplex.h>
25# else
26 # define cuFloatComplex void
27 # define cuDoubleComplex void
28# endif
29
30
31// set default double precision if not set during compilation
32# ifndef QuEST_PREC
33 # define QuEST_PREC 2
34# endif
35
36
37/*
38 * Single precision, which uses 4 bytes per amplitude component
39 */
40# if QuEST_PREC==1
41 # define qreal float
42 // \cond HIDDEN_SYMBOLS
43 # define cuAmp cuFloatComplex
44 # define MPI_QuEST_REAL MPI_FLOAT
45 # define MPI_MAX_AMPS_IN_MSG (1LL<<29) // must be 2^int
46 # define REAL_STRING_FORMAT "%.8f"
47 # define REAL_QASM_FORMAT "%.8g"
48 # define REAL_EPS 1e-5
49 # define REAL_SPECIFIER "%f"
50 # define absReal(X) fabs(X) // not fabsf(X) - better to return doubles where possible
51 // \endcond
52/*
53 * Double precision, which uses 8 bytes per amplitude component
54 */
55# elif QuEST_PREC==2
56 # define qreal double
57 // \cond HIDDEN_SYMBOLS
58 # define cuAmp cuDoubleComplex
59 # define MPI_QuEST_REAL MPI_DOUBLE
60 # define MPI_MAX_AMPS_IN_MSG (1LL<<28) // must be 2^int
61 # define REAL_STRING_FORMAT "%.14f"
62 # define REAL_QASM_FORMAT "%.14g"
63 # define REAL_EPS 1e-13
64 # define REAL_SPECIFIER "%lf"
65 # define absReal(X) fabs(X)
66 // \endcond
67/*
68 * Quad precision, which uses 16 bytes per amplitude component.
69 * This is not compatible with most GPUs.
70 */
71# elif QuEST_PREC==4
72 # define qreal long double
73 // \cond HIDDEN_SYMBOLS
74 # define cuAmp void // invalid
75 # define MPI_QuEST_REAL MPI_LONG_DOUBLE
76 # define MPI_MAX_AMPS_IN_MSG (1LL<<27) // must be 2^int
77 # define REAL_STRING_FORMAT "%.17Lf"
78 # define REAL_QASM_FORMAT "%.17Lg"
79 # define REAL_EPS 1e-14
80 # define REAL_SPECIFIER "%Lf"
81 # define absReal(X) fabsl(X)
82 # define sin(x) sinl(x)
83 # define cos(x) cosl(x)
84 # define tan(x) tanl(x)
85 # define exp(x) expl(x)
86 # define fabs(x) fabsl(x)
87 # define pow(x,y) powl(x,y)
88 # define sqrt(x) sqrtl(x)
89 # define asin(x) asinl(x)
90 # define acos(x) acosl(x)
91 # define atan(x) atanl(x)
92 # define atan2(x,y) atan2l(x,y)
93 # define ceil(x) ceill(x)
94 # define floor(x) floorl(x)
95 // \endcond
96# endif
97
98
99// the maximum number of qubit registers which can be passed to functions like applyMultiArbitraryPhaseOverrides()
100# define MAX_NUM_REGS_APPLY_ARBITRARY_PHASE 100
101
102
138# endif // QUEST_PRECISION_H