summaryrefslogtreecommitdiff
path: root/absl/numeric/int128.cc
diff options
context:
space:
mode:
authorGravatar Tsige Solomon <tsige@google.com>2023-06-21 08:52:53 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2023-06-21 08:53:52 -0700
commit34eb767645347f100bdd66fc1e35eee96e357961 (patch)
tree5257457b09e5c1533b41e9607fdefd20ef158eae /absl/numeric/int128.cc
parent166d71d18f01aa73fd35aae611692320952a75b5 (diff)
Support for int128 to string type conversion.
PiperOrigin-RevId: 542269673 Change-Id: Ib6f7e9a57f83d73dd6fb9c45fc9f85ff0fdd75fe
Diffstat (limited to 'absl/numeric/int128.cc')
-rw-r--r--absl/numeric/int128.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/absl/numeric/int128.cc b/absl/numeric/int128.cc
index 6ffe43d5..daa32b51 100644
--- a/absl/numeric/int128.cc
+++ b/absl/numeric/int128.cc
@@ -202,6 +202,10 @@ std::string Uint128ToFormattedString(uint128 v, std::ios_base::fmtflags flags) {
} // namespace
+std::string uint128::ToString() const {
+ return Uint128ToFormattedString(*this, std::ios_base::dec);
+}
+
std::ostream& operator<<(std::ostream& os, uint128 v) {
std::ios_base::fmtflags flags = os.flags();
std::string rep = Uint128ToFormattedString(v, flags);
@@ -285,6 +289,14 @@ int128 operator%(int128 lhs, int128 rhs) {
}
#endif // ABSL_HAVE_INTRINSIC_INT128
+std::string int128::ToString() const {
+ std::string rep;
+ if (Int128High64(*this) < 0) rep = "-";
+ rep.append(Uint128ToFormattedString(UnsignedAbsoluteValue(*this),
+ std::ios_base::dec));
+ return rep;
+}
+
std::ostream& operator<<(std::ostream& os, int128 v) {
std::ios_base::fmtflags flags = os.flags();
std::string rep;