QuEST_precision.h
Go to the documentation of this file.
1 // Distributed under MIT licence. See https://github.com/QuEST-Kit/QuEST/blob/master/LICENCE.txt for details
2 
13 # include <math.h>
14 
15 # ifndef QUEST_PRECISION_H
16 # define QUEST_PRECISION_H
17 
18 
19 // set default double precision if not set during compilation
20 # ifndef QuEST_PREC
21 # define QuEST_PREC 2
22 # endif
23 
24 
25 /*
26  * Single precision, which uses 4 bytes per amplitude component
27  */
28 # if QuEST_PREC==1
29  # define qreal float
30  // \cond HIDDEN_SYMBOLS
31  # define MPI_QuEST_REAL MPI_FLOAT
32  # define MPI_MAX_AMPS_IN_MSG (1LL<<29) // must be 2^int
33  # define REAL_STRING_FORMAT "%.8f"
34  # define REAL_QASM_FORMAT "%.8g"
35  # define REAL_EPS 1e-5
36  # define REAL_SPECIFIER "%f"
37  # define absReal(X) fabs(X) // not fabsf(X) - better to return doubles where possible
38  // \endcond
39 /*
40  * Double precision, which uses 8 bytes per amplitude component
41  */
42 # elif QuEST_PREC==2
43  # define qreal double
44  // \cond HIDDEN_SYMBOLS
45  # define MPI_QuEST_REAL MPI_DOUBLE
46  # define MPI_MAX_AMPS_IN_MSG (1LL<<28) // must be 2^int
47  # define REAL_STRING_FORMAT "%.14f"
48  # define REAL_QASM_FORMAT "%.14g"
49  # define REAL_EPS 1e-13
50  # define REAL_SPECIFIER "%lf"
51  # define absReal(X) fabs(X)
52  // \endcond
53 /*
54  * Quad precision, which uses 16 bytes per amplitude component.
55  * This is not compatible with most GPUs.
56  */
57 # elif QuEST_PREC==4
58  # define qreal long double
59  // \cond HIDDEN_SYMBOLS
60  # define MPI_QuEST_REAL MPI_LONG_DOUBLE
61  # define MPI_MAX_AMPS_IN_MSG (1LL<<27) // must be 2^int
62  # define REAL_STRING_FORMAT "%.17Lf"
63  # define REAL_QASM_FORMAT "%.17Lg"
64  # define REAL_EPS 1e-14
65  # define REAL_SPECIFIER "%Lf"
66  # define absReal(X) fabsl(X)
67  // \endcond
68 # endif
69 
70 
71 // the maximum number of qubit registers which can be passed to functions like applyMultiArbitraryPhaseOverrides()
72 # define MAX_NUM_REGS_APPLY_ARBITRARY_PHASE 100
73 
74 
110 # endif // QUEST_PRECISION_H