Skip to content

Commit

Permalink
fix overflow in test tau_t constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
nkavokine committed Feb 22, 2024
1 parent cd61b92 commit 5b4a7f4
Show file tree
Hide file tree
Showing 10 changed files with 2,600 additions and 1 deletion.
9 changes: 8 additions & 1 deletion c++/triqs_ctseg/tau_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ class tau_t {
/// Not for users. Use the factories
tau_t(uint64_t n_) : n(n_) {}
/// For test only, not for users. Use the factories
tau_t(double x) : tau_t{uint64_t((x / _beta) * double(n_max))} {}
tau_t(double x) : n(0) {
if ((x > _beta || x < 0)) {
throw std::invalid_argument("Time tau must be in the range [0, beta]");
} else if (x == _beta)
n = n_max;
else
n = uint64_t((x / _beta) * double(n_max));
}

/// Comparisons (using integer, so it is safe)
auto operator<=>(tau_t const &tau) const { return n <=> tau.n; }
Expand Down
Loading

0 comments on commit 5b4a7f4

Please sign in to comment.