From 8afe90afd640cd9bc9ad7561ec819a0126f8c302 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 28 Apr 2024 14:44:35 -0400 Subject: [PATCH] xo-flatstring: + __int128 printer --- include/xo/flatstring/int128_iostream.hpp | 31 +++++++++++++++++++++++ utest/flatstring.test.cpp | 20 +++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 include/xo/flatstring/int128_iostream.hpp diff --git a/include/xo/flatstring/int128_iostream.hpp b/include/xo/flatstring/int128_iostream.hpp new file mode 100644 index 00000000..cc546a18 --- /dev/null +++ b/include/xo/flatstring/int128_iostream.hpp @@ -0,0 +1,31 @@ +/** @file int128_iostream.hpp + * + * Author: Roland Conybeare + **/ + +#pragma once + +#include "flatstring.hpp" +#include + +namespace std { + /* print a 128-bit integer */ + inline std::ostream & + operator<< (std::ostream & os, __int128 x) { + os << xo::flatstring<48>::from_int(x); + return os; + } +} + +#ifdef NOT_USING +namespace xo { + /* print a 128-bit integer */ + inline std::ostream & + operator<< (std::ostream & os, __int128 x) { + os << xo::flatstring<48>::from_int(x); + return os; + } +} +#endif + +/** end int128_iostream.hpp **/ diff --git a/utest/flatstring.test.cpp b/utest/flatstring.test.cpp index 8a3761a1..69b24c53 100644 --- a/utest/flatstring.test.cpp +++ b/utest/flatstring.test.cpp @@ -1,6 +1,7 @@ /** @file flatstring.utest.cpp **/ #include "xo/flatstring/flatstring.hpp" +#include "xo/flatstring/int128_iostream.hpp" #include "xo/indentlog/scope.hpp" #include "xo/indentlog/print/tag.hpp" #include "xo/indentlog/print/hex.hpp" @@ -419,6 +420,25 @@ namespace xo { } /*TEST_CASE(flatstring)*/ + TEST_CASE("flatstring_int128", "[flatstring]") { + //constexpr bool c_debug_flag = false; + + // can get bits from /dev/random by uncommenting the 2nd line below + //uint64_t seed = xxx; + //rng::Seed seed; + + //auto rng = xo::rng::xoshiro256ss(seed); + + //scope log(XO_DEBUG2(c_debug_flag, "TEST_CASE.flatstring_int128")); + //log && log("(A)", xtag("foo", foo)); + + __int128_t x = 65536UL*65536UL*65536UL*65536UL*65536UL; + + stringstream ss; + ss << x; + } /*TEST_CASE(flatstring_int128)*/ + + } /*namespace ut*/ } /*namespace xo*/