aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/int128/int128.cpp
diff options
context:
space:
mode:
authorVlad Yaroslavlev <vladon@vladon.com>2022-02-10 16:46:23 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:23 +0300
commit706b83ed7de5a473436620367af31fc0ceecde07 (patch)
tree103305d30dec77e8f6367753367f59b3cd68f9f1 /library/cpp/int128/int128.cpp
parent918e8a1574070d0ec733f0b76cfad8f8892ad2e5 (diff)
downloadydb-706b83ed7de5a473436620367af31fc0ceecde07.tar.gz
Restoring authorship annotation for Vlad Yaroslavlev <vladon@vladon.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/int128/int128.cpp')
-rw-r--r--library/cpp/int128/int128.cpp104
1 files changed, 52 insertions, 52 deletions
diff --git a/library/cpp/int128/int128.cpp b/library/cpp/int128/int128.cpp
index a28a389fe8..dedcd28f91 100644
--- a/library/cpp/int128/int128.cpp
+++ b/library/cpp/int128/int128.cpp
@@ -1,55 +1,55 @@
-#include "int128.h"
-
-#include <tuple>
-
-IOutputStream& operator<<(IOutputStream& out, const ui128& other) {
- // see http://stackoverflow.com/questions/4361441/c-print-a-biginteger-in-base-10
- // and http://stackoverflow.com/questions/8023414/how-to-convert-a-128-bit-integer-to-a-decimal-ascii-string-in-c
- int d[39] = {0};
- int i;
- int j;
- for (i = 63; i > -1; i--) {
- if ((other.High_ >> i) & 1)
- ++d[0];
- for (j = 0; j < 39; j++)
- d[j] *= 2;
- for (j = 0; j < 38; j++) {
- d[j + 1] += d[j] / 10;
- d[j] %= 10;
- }
- }
- for (i = 63; i > -1; i--) {
- if ((other.Low_ >> i) & 1)
- ++d[0];
- if (i > 0)
- for (j = 0; j < 39; j++)
- d[j] *= 2;
- for (j = 0; j < 38; j++) {
- d[j + 1] += d[j] / 10;
- d[j] %= 10;
- }
- }
- for (i = 38; i > 0; i--)
- if (d[i] > 0)
- break;
- for (; i > -1; i--)
- out << static_cast<char>('0' + d[i]);
-
- return out;
-}
-
-void TSerializer<ui128>::Save(IOutputStream* out, const ui128& Number) {
- ::Save(out, GetHigh(Number));
- ::Save(out, GetLow(Number));
-}
-
-void TSerializer<ui128>::Load(IInputStream* in, ui128& Number) {
- ui64 High;
- ui64 Low;
- ::Load(in, High);
- ::Load(in, Low);
- Number = ui128(High, Low);
-}
+#include "int128.h"
+
+#include <tuple>
+
+IOutputStream& operator<<(IOutputStream& out, const ui128& other) {
+ // see http://stackoverflow.com/questions/4361441/c-print-a-biginteger-in-base-10
+ // and http://stackoverflow.com/questions/8023414/how-to-convert-a-128-bit-integer-to-a-decimal-ascii-string-in-c
+ int d[39] = {0};
+ int i;
+ int j;
+ for (i = 63; i > -1; i--) {
+ if ((other.High_ >> i) & 1)
+ ++d[0];
+ for (j = 0; j < 39; j++)
+ d[j] *= 2;
+ for (j = 0; j < 38; j++) {
+ d[j + 1] += d[j] / 10;
+ d[j] %= 10;
+ }
+ }
+ for (i = 63; i > -1; i--) {
+ if ((other.Low_ >> i) & 1)
+ ++d[0];
+ if (i > 0)
+ for (j = 0; j < 39; j++)
+ d[j] *= 2;
+ for (j = 0; j < 38; j++) {
+ d[j + 1] += d[j] / 10;
+ d[j] %= 10;
+ }
+ }
+ for (i = 38; i > 0; i--)
+ if (d[i] > 0)
+ break;
+ for (; i > -1; i--)
+ out << static_cast<char>('0' + d[i]);
+
+ return out;
+}
+
+void TSerializer<ui128>::Save(IOutputStream* out, const ui128& Number) {
+ ::Save(out, GetHigh(Number));
+ ::Save(out, GetLow(Number));
+}
+
+void TSerializer<ui128>::Load(IInputStream* in, ui128& Number) {
+ ui64 High;
+ ui64 Low;
+ ::Load(in, High);
+ ::Load(in, Low);
+ Number = ui128(High, Low);
+}
IOutputStream& operator<<(IOutputStream& out, const i128& other)
{