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 absReal(X) fabs(X) // not fabsf(X) - better to return doubles where possible
37  // \endcond
38 /*
39  * Double precision, which uses 8 bytes per amplitude component
40  */
41 # elif QuEST_PREC==2
42  # define qreal double
43  // \cond HIDDEN_SYMBOLS
44  # define MPI_QuEST_REAL MPI_DOUBLE
45  # define MPI_MAX_AMPS_IN_MSG (1LL<<28) // must be 2^int
46  # define REAL_STRING_FORMAT "%.14f"
47  # define REAL_QASM_FORMAT "%.14g"
48  # define REAL_EPS 1e-13
49  # define absReal(X) fabs(X)
50  // \endcond
51 /*
52  * Quad precision, which uses 16 bytes per amplitude component.
53  * This is not compatible with most GPUs.
54  */
55 # elif QuEST_PREC==4
56  # define qreal long double
57  // \cond HIDDEN_SYMBOLS
58  # define MPI_QuEST_REAL MPI_LONG_DOUBLE
59  # define MPI_MAX_AMPS_IN_MSG (1LL<<27) // must be 2^int
60  # define REAL_STRING_FORMAT "%.17Lf"
61  # define REAL_QASM_FORMAT "%.17Lg"
62  # define REAL_EPS 1e-14
63  # define absReal(X) fabsl(X)
64  // \endcond
65 # endif
66 
67 
92 # endif // QUEST_PRECISION_H