Go to the documentation of this file.
69 #include "absl/base/casts.h"
70 #include "absl/base/macros.h"
71 #include "absl/numeric/int128.h"
72 #include "absl/strings/string_view.h"
73 #include "absl/strings/strip.h"
74 #include "absl/time/time.h"
90 return d != std::numeric_limits<double>::infinity() &&
91 d != -std::numeric_limits<double>::infinity();
101 template <
typename Double>
103 return d < 0 ? std::ceil(d - 0.5) : std::floor(d + 0.5);
151 rep_hi =
static_cast<int64_t>(hi);
159 const uint64_t kMaxRepHi64 = 0x77359400UL;
160 if (h64 >= kMaxRepHi64) {
161 if (is_neg && h64 == kMaxRepHi64 && l64 == 0) {
192 return absl::bit_cast<uint64_t>(
v);
203 double c = a_hi + b_hi;
204 if (c >=
static_cast<double>(
kint64max)) {
208 if (c <=
static_cast<double>(
kint64min)) {
218 template <
typename Ignored>
235 template <
template <
typename>
class Operation>
239 const uint128 q = Operation<uint128>()(
a,
b);
246 template <
template <
typename>
class Operation>
248 Operation<double>
op;
253 double hi_frac = std::modf(hi_doub, &hi_int);
260 double lo_frac = std::modf(lo_doub, &lo_int);
318 }
else if (den_hi > 0 && den_lo == 0) {
326 *q = num_hi / den_hi;
333 int64_t quotient = num_hi / den_hi;
334 int64_t rem_sec = num_hi % den_hi;
352 namespace time_internal {
367 const bool quotient_neg = num_neg != den_neg;
390 const uint128 remainder128 =
a - quotient128 *
b;
393 if (!quotient_neg || quotient128 == 0) {
437 if (rhs.
rep_hi_ < 0 ? rep_hi_ < orig_rep_hi : rep_hi_ > orig_rep_hi) {
449 const bool is_neg = (
r < 0) != (
rep_hi_ < 0);
452 return *
this = ScaleFixed<SafeMultiply>(*
this,
r);
457 const bool is_neg = (std::signbit(
r) != 0) != (
rep_hi_ < 0);
460 return *
this = ScaleDouble<std::multiplies>(*
this,
r);
465 const bool is_neg = (
r < 0) != (
rep_hi_ < 0);
468 return *
this = ScaleFixed<std::divides>(*
this,
r);
473 const bool is_neg = (std::signbit(
r) != 0) != (
rep_hi_ < 0);
476 return *
this = ScaleDouble<std::divides>(*
this,
r);
488 ? std::numeric_limits<double>::infinity()
489 : -std::numeric_limits<double>::infinity();
507 return d - (d % unit);
525 if (
static_cast<uint64_t>(ts.tv_nsec) < 1000 * 1000 * 1000) {
584 return hi / (60 * 60);
621 if (ts.tv_sec == rep_hi) {
628 ts.tv_nsec = 1000 * 1000 * 1000 - 1;
642 ts.tv_nsec += 1000 - 1;
643 if (ts.tv_nsec >= 1000 * 1000 * 1000) {
645 ts.tv_nsec -= 1000 * 1000 * 1000;
649 if (tv.
tv_sec != ts.tv_sec) {
659 tv.
tv_usec =
static_cast<int>(ts.tv_nsec / 1000);
664 return time_internal::ToChronoDuration<std::chrono::nanoseconds>(d);
667 return time_internal::ToChronoDuration<std::chrono::microseconds>(d);
670 return time_internal::ToChronoDuration<std::chrono::milliseconds>(d);
673 return time_internal::ToChronoDuration<std::chrono::seconds>(d);
676 return time_internal::ToChronoDuration<std::chrono::minutes>(d);
679 return time_internal::ToChronoDuration<std::chrono::hours>(d);
694 *--ep =
'0' + (
v % 10);
696 while (--
width >= 0) *--ep =
'0';
727 char buf[
sizeof(
"2562047788015216")];
728 char*
const ep =
buf +
sizeof(
buf);
729 char* bp = Format64(ep, 0, n);
730 if (*bp !=
'0' || bp + 1 != ep) {
731 out->append(bp, ep - bp);
732 out->append(unit.abbr.data(), unit.abbr.size());
738 void AppendNumberUnit(
std::string*
out,
double n, DisplayUnit unit) {
739 constexpr
int kBufferSize = std::numeric_limits<double>::digits10;
742 char* ep =
buf +
sizeof(
buf);
744 int64_t frac_part =
Round(std::modf(n, &d) * unit.pow10);
746 if (int_part != 0 || frac_part != 0) {
747 char* bp = Format64(ep, 0, int_part);
748 out->append(bp, ep - bp);
749 if (frac_part != 0) {
751 bp = Format64(ep, prec, frac_part);
752 while (ep[-1] ==
'0') --ep;
753 out->append(bp, ep - bp);
755 out->append(unit.abbr.data(), unit.abbr.size());
771 if (d == kMinDuration) {
774 s =
"-2562047788015215h30m8s";
798 if (
s.empty() ||
s ==
"-") {
809 bool ConsumeDurationNumber(
const char** dpp,
const char* ep,
int64_t* int_part,
814 const char*
start = *dpp;
815 for (; *dpp != ep; *dpp += 1) {
816 const int d = **dpp -
'0';
817 if (d < 0 || 10 <= d)
break;
819 if (*int_part >
kint64max / 10)
return false;
821 if (*int_part >
kint64max - d)
return false;
824 const bool int_part_empty = (*dpp ==
start);
825 if (*dpp == ep || **dpp !=
'.')
return !int_part_empty;
827 for (*dpp += 1; *dpp != ep; *dpp += 1) {
828 const int d = **dpp -
'0';
829 if (d < 0 || 10 <= d)
break;
836 return !int_part_empty || *frac_scale != 1;
843 bool ConsumeDurationUnit(
const char**
start,
const char*
end,
Duration* unit) {
851 if (*(*
start + 1) ==
's') {
858 if (*(*
start + 1) ==
's') {
865 if (*(*
start + 1) ==
's') {
909 if (dur_sv.
empty())
return false;
917 if (dur_sv ==
"inf") {
931 if (!ConsumeDurationNumber(&
start,
end, &int_part, &frac_part,
933 !ConsumeDurationUnit(&
start,
end, &unit)) {
936 if (int_part != 0) dur += sign * int_part * unit;
937 if (frac_part != 0) dur += sign * frac_part * unit / frac_scale;
constexpr int64_t kTicksPerNanosecond
std::chrono::microseconds ToChronoMicroseconds(Duration d)
std::chrono::duration< std::int_fast64_t > seconds
uint128 MakeU128Ticks(Duration d)
ABSL_NAMESPACE_BEGIN bool ParseFlag(absl::string_view input, T *dst, std::string *error)
ABSL_NAMESPACE_BEGIN const ABSL_DLL uint128 kuint128max
static const int kBufferSize
std::chrono::milliseconds ToChronoMilliseconds(Duration d)
constexpr Duration ZeroDuration()
constexpr Duration MakeDuration(int64_t hi, uint32_t lo)
constexpr int64_t kTicksPerSecond
constexpr Duration Nanoseconds(T n)
int64_t ToInt64Minutes(Duration d)
int64_t DecodeTwosComp(uint64_t v)
std::string UnparseFlag(const T &v)
int64_t ToInt64Microseconds(Duration d)
Duration & operator%=(Duration rhs)
#define ABSL_NAMESPACE_END
std::chrono::hours ToChronoHours(Duration d)
double ToDoubleHours(Duration d)
bool AbslParseFlag(absl::string_view text, absl::LogSeverity *dst, std::string *err)
int64_t ToInt64Milliseconds(Duration d)
Duration Floor(const Duration d, const Duration unit)
constexpr bool IsInfiniteDuration(Duration d)
constexpr Duration Milliseconds(T n)
constexpr uint64_t Uint128High64(uint128 v)
uint128 MakeU128(int64_t a)
#define ABSL_NAMESPACE_BEGIN
constexpr Duration Microseconds(T n)
void NormalizeTicks(int64_t *sec, int64_t *ticks)
constexpr uint64_t Uint128Low64(uint128 v)
std::chrono::minutes ToChronoMinutes(Duration d)
constexpr int64_t kint64max
constexpr size_type size() const noexcept
Duration & operator/=(int64_t r)
double ToDoubleMilliseconds(Duration d)
timeval ToTimeval(Duration d)
unsigned __int64 uint64_t
Duration ScaleFixed(Duration d, int64_t r)
Duration & operator*=(int64_t r)
bool IDivFastPath(const Duration num, const Duration den, int64_t *q, Duration *rem)
double ToDoubleSeconds(Duration d)
std::string AbslUnparseFlag(absl::LogSeverity v)
double FDivDuration(Duration num, Duration den)
bool ParseDuration(absl::string_view dur_sv, Duration *d)
Duration ScaleDouble(Duration d, double r)
std::string FormatDuration(Duration d)
std::chrono::seconds ToChronoSeconds(Duration d)
constexpr Duration Seconds(T n)
timespec ToTimespec(Duration d)
constexpr Duration Hours(T n)
int64_t IDivDuration(bool satq, const Duration num, const Duration den, Duration *rem)
uint64_t EncodeTwosComp(int64_t v)
int64_t ToInt64Hours(Duration d)
FloatingPoint< double > Double
int64_t IDivDuration(Duration num, Duration den, Duration *rem)
Duration DurationFromTimeval(timeval tv)
double ToDoubleMicroseconds(Duration d)
Duration & operator-=(Duration d)
constexpr Duration Minutes(T n)
Duration Ceil(const Duration d, const Duration unit)
Duration AbsDuration(Duration d)
uint128 operator()(uint128 a, uint128 b) const
constexpr int64_t GetRepHi(Duration d)
std::chrono::nanoseconds ToChronoNanoseconds(Duration d)
constexpr bool empty() const noexcept
constexpr uint32_t GetRepLo(Duration d)
double ToDoubleNanoseconds(Duration d)
Duration Trunc(Duration d, Duration unit)
bool IsValidDivisor(double d)
Duration & operator+=(Duration d)
constexpr Duration InfiniteDuration()
bool SafeAddRepHi(double a_hi, double b_hi, Duration *d)
#define ABSL_FALLTHROUGH_INTENDED
constexpr const_pointer data() const noexcept
Duration DurationFromTimespec(timespec ts)
constexpr int64_t kint64min
static unsigned long ticks
Duration MakeDurationFromU128(uint128 u128, bool is_neg)
int64_t ToInt64Nanoseconds(Duration d)
double ToDoubleMinutes(Duration d)
ABSL_NAMESPACE_BEGIN bool ConsumePrefix(absl::string_view *str, absl::string_view expected)
int64_t ToInt64Seconds(Duration d)
grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:17