From c192c49b65fb6e6f4f94c85816cd4e9fbc0ddb8f Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 10 Aug 2020 10:12:07 -0600 Subject: [PATCH] Temporal: add std::numeric_limits<> for timecnt_t and comment on these in general --- libs/temporal/temporal/timeline.h | 39 ++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/libs/temporal/temporal/timeline.h b/libs/temporal/temporal/timeline.h index 53da108cb0..cc8ceaaa82 100644 --- a/libs/temporal/temporal/timeline.h +++ b/libs/temporal/temporal/timeline.h @@ -386,15 +386,35 @@ class LIBTEMPORAL_API timecnt_t { */ namespace std { - template<> - struct numeric_limits { - static Temporal::timepos_t min() { - return Temporal::timepos_t (0); - } - static Temporal::timepos_t max() { - return Temporal::timepos_t (4611686018427387904); /* pow (2,62) */ - } - }; + +/* The utility of these two specializations of std::numeric_limits<> is not + * clear, since both timepos_t and timecnt_t have a time domain, and comparing + * across time domains, while possible, is expensive. + * + * To avoid hidden costs, it seems easier to use timepos_t::max and + * timecnt_t::max although these have a similar fundamental problem. + */ + +template<> +struct numeric_limits { + static Temporal::timepos_t min() { + return Temporal::timepos_t (0); + } + static Temporal::timepos_t max() { + return Temporal::timepos_t (4611686018427387904); /* pow (2,62) */ + } +}; + +template<> +struct numeric_limits { + static Temporal::timecnt_t min() { + return Temporal::timecnt_t (Temporal::superclock_t (0), Temporal::timepos_t (Temporal::superclock_t (0))); + } + static Temporal::timecnt_t max() { + return Temporal::timecnt_t (Temporal::superclock_t (4611686018427387904), Temporal::timepos_t (Temporal::superclock_t (0))); /* pow (2,62) */ + } +}; + } @@ -438,3 +458,4 @@ inline static bool operator>= (Temporal::Beats const & b, Temporal::timecnt_t co #undef TEMPORAL_DOMAIN_WARNING #endif /* __libtemporal_timeline_h__ */ +