14#include <fmt/ostream.h>
16namespace triqs_ctseg {
32 inline static double _beta;
39 static constexpr uint64_t
n_max = std::numeric_limits<uint64_t>::max();
51 if ((x > _beta || x < 0)) {
52 throw std::invalid_argument(
"Time tau must be in the range [0, beta]");
53 }
else if (x == _beta)
56 n = uint64_t((x / _beta) *
double(
n_max));
60 auto operator<=>(tau_t
const &tau)
const {
return n <=> tau.n; }
61 bool operator==(
tau_t const &tau)
const {
return n == tau.n; }
64 explicit operator double()
const {
return _beta * (double(n) / double(
n_max)); }
70 static tau_t
zero() {
return {uint64_t{0}}; }
73 static tau_t
epsilon() {
return {uint64_t{1}}; }
78 return {rng(tau2.n - n1) + n1};
82 static tau_t
random(
auto &rng, tau_t
const &tau) {
return {rng(tau.n - 1) + 1}; }
86 friend tau_t operator+(
tau_t const &a,
tau_t const &b) {
return {a.n + b.n}; }
88 friend tau_t operator-(tau_t
const &a, tau_t
const &b) {
return {a.n - b.n}; }
90 friend tau_t operator-(tau_t
const &a) {
return {
tau_t::n_max - a.n}; }
95 friend std::ostream &
operator<<(std::ostream &out, tau_t
const &p) {
96 return out << double(p) <<
" [tau_t : n = " << p.n <<
"]";
103 inline double operator*(tau_t
const &a, tau_t
const &b) {
return double(a) * double(b); }
104 inline double operator/(
tau_t const &a,
tau_t const &b) {
return double(a) / double(b); }
106 inline double operator+(
tau_t const &x,
double y) {
return double(x) + y; }
107 inline double operator+(
double y,
tau_t const &x) {
return y + double(x); }
109 inline double operator-(
tau_t const &x,
double y) {
return double(x) - y; }
110 inline double operator-(
double y,
tau_t const &x) {
return y - double(x); }
112 inline double operator*(
tau_t const &x,
double y) {
return double(x) * y; }
113 inline double operator*(
double y,
tau_t const &x) {
return y * double(x); }
115 inline double operator/(
tau_t const &x,
double y) {
return double(x) / y; }
116 inline double operator/(
double y,
tau_t const &x) {
return y / double(x); }
120template <>
struct fmt::formatter<triqs_ctseg::tau_t> : ostream_formatter {};
friend std::ostream & operator<<(std::ostream &out, tau_t const &p)
Stream insertion.
static constexpr uint64_t n_max
Maximum value that can be stored inside a uint64_t.
static void set_beta(double beta)
Set the temperature.
tau_t(uint64_t n_)
Not for users. Use the factories.
tau_t(double x)
For test only, not for users. Use the factories.
static tau_t epsilon()
Get epsilon, defined as $\epsilon = \beta /N_max$.
static tau_t beta()
tau_t at tau = beta
static tau_t random(auto &rng, tau_t const &tau)
Get a random point in $]0, tau[$.
auto operator<=>(tau_t const &tau) const
Comparisons (using integer, so it is safe).
static tau_t zero()
$\tau = 0$