HILA
Loading...
Searching...
No Matches
real_var_ops.h
1#ifndef REAL_VAR_OPS_H_
2#define REAL_VAR_OPS_H_
3
4#include "plumbing/defs.h"
5#include "plumbing/random.h"
6
7
8//////////////////////////////////////////////////////////////////////////
9
10// define abs() -function for floating point
11template <typename T, std::enable_if_t<std::is_floating_point<T>::value, int> = 0>
12inline T abs(T val) {
13 return std::abs(val);
14}
15
16// also def min and max, for all arith types
17template <typename T, std::enable_if_t<std::is_arithmetic<T>::value, int> = 0>
18inline T min(T val1, T val2) {
19 return std::min(val1, val2);
20}
21
22// also def min and max
23template <typename T, std::enable_if_t<std::is_arithmetic<T>::value, int> = 0>
24inline T max(T val1, T val2) {
25 return std::max(val1, val2);
26}
27
28// define real(), imag(), conj() -functions for basic arithmetic types
29template <typename T, std::enable_if_t<hila::is_arithmetic<T>::value, int> = 0>
30inline T real(T val) {
31 return val;
32}
33
34template <typename T, std::enable_if_t<hila::is_arithmetic<T>::value, int> = 0>
35inline T imag(T val) {
36 return (T)0;
37}
38
39template <typename T, std::enable_if_t<hila::is_arithmetic<T>::value, int> = 0>
40inline T conj(T val) {
41 return val;
42}
43
44template <typename T, std::enable_if_t<hila::is_arithmetic<T>::value, int> = 0>
45inline T dagger(T val) {
46 return val;
47}
48
49// define squarenorm and norm
50template <typename T, std::enable_if_t<hila::is_arithmetic<T>::value, int> = 0>
51inline T squarenorm(T val) {
52 return val * val;
53}
54
55// for integral types, sqrt -> double, so auto here makes sens
56template <typename T, std::enable_if_t<hila::is_arithmetic<T>::value, int> = 0>
57inline auto norm(T val) {
58 return sqrt(val * val);
59}
60
61namespace hila {
62
63
64/// convert to string: separator does nothing, but for compatibility w. other to_strings
65
66template <typename T, std::enable_if_t<hila::is_arithmetic<T>::value, int> = 0>
67std::string to_string(const T v, int prec = 8, char separator = ' ') {
68 std::stringstream ss;
69 ss.precision(prec);
70 ss << v;
71 return ss.str();
72}
73
74template <typename T, std::enable_if_t<hila::is_arithmetic<T>::value, int> = 0>
75std::string prettyprint(const T v, int prec = 8) {
76 return to_string(v, prec);
77}
78
79
80} // namespace hila
81
82#endif
Array< n, m, T > conj(const Array< n, m, T > &arg)
Return conjugate Array.
Definition array.h:674
Array< n, m, hila::arithmetic_type< T > > imag(const Array< n, m, T > &arg)
Return imaginary part of Array.
Definition array.h:702
hila::arithmetic_type< T > squarenorm(const Array< n, m, T > &rhs)
Return square norm of Array.
Definition array.h:1018
Array< n, m, T > sqrt(Array< n, m, T > a)
Square root.
Definition array.h:1039
Array< n, m, hila::arithmetic_type< T > > real(const Array< n, m, T > &arg)
Return real part of Array.
Definition array.h:688
Complex< T > dagger(const Complex< T > &val)
Return dagger of Complex number.
Definition cmplx.h:1223
T abs(const Complex< T > &a)
Return absolute value of Complex number.
Definition cmplx.h:1187
This file defines all includes for HILA.
Implement hila::swap for gauge fields.
Definition array.h:981
std::string to_string(const Array< n, m, T > &A, int prec=8, char separator=' ')
Converts Array object to string.
Definition array.h:995