Skip to content

Commit 5b4a7f4

Browse files
committed
fix overflow in test tau_t constructor
1 parent cd61b92 commit 5b4a7f4

File tree

10 files changed

+2600
-1
lines changed

10 files changed

+2600
-1
lines changed

c++/triqs_ctseg/tau_t.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ class tau_t {
3939
/// Not for users. Use the factories
4040
tau_t(uint64_t n_) : n(n_) {}
4141
/// For test only, not for users. Use the factories
42-
tau_t(double x) : tau_t{uint64_t((x / _beta) * double(n_max))} {}
42+
tau_t(double x) : n(0) {
43+
if ((x > _beta || x < 0)) {
44+
throw std::invalid_argument("Time tau must be in the range [0, beta]");
45+
} else if (x == _beta)
46+
n = n_max;
47+
else
48+
n = uint64_t((x / _beta) * double(n_max));
49+
}
4350

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

0 commit comments

Comments
 (0)