sparrow
2.4.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Toggle main menu visibility
Loading...
Searching...
No Matches
int128_t.hpp
Go to the documentation of this file.
1
2
// SPARROW: THIS HAS BEEN COPY-PASTED FROM https://github.com/kimwalisch/primesum/blob/master/include/int128_t.hpp
3
// PLEASE UPDATE THIS COMMENT IF YOU REPLACE THIS
4
// SEE README.md for rational
6
// Modification from the original:
7
// * disabled io operators
18
19
#ifndef INT128_T_HPP
20
#define INT128_T_HPP
21
22
#include <sstream>
23
#include <stdint.h>
24
#include <limits>
25
#include <type_traits>
26
33
#if !defined(INT128_MAX) && \
34
defined(__SIZEOF_INT128__)
35
36
#include <ostream>
37
#include <string>
38
39
namespace
primesum
{
40
41
using
int128_t
= __int128_t;
42
using
uint128_t = __uint128_t;
43
44
}
// namespace
45
46
#endif
47
48
inline
std::ostream&
operator<<
(std::ostream& stream, primesum::uint128_t n)
49
{
50
std::string str;
51
52
while
(n > 0)
53
{
54
str +=
'0'
+ char(n % 10);
55
n /= 10;
56
}
57
if
(str.empty())
58
{
59
str =
"0"
;
60
}
61
62
stream << std::string(str.rbegin(), str.rend());
63
return
stream;
64
}
65
66
inline
std::ostream&
operator<<
(std::ostream& stream, primesum::int128_t n)
67
{
68
if
(n < 0)
69
{
70
stream <<
"-"
;
71
n = -n;
72
}
73
stream << (primesum::uint128_t) n;
74
return
stream;
75
}
76
77
namespace
primesum
{
78
79
inline
std::string
to_string
(
const
uint128_t& n)
80
{
81
std::ostringstream oss;
82
oss << n;
83
return
oss.str();
84
}
85
86
inline
std::string
to_string
(
const
int128_t& n)
87
{
88
std::ostringstream oss;
89
oss << n;
90
return
oss.str();
91
}
92
97
namespace
prt
{
98
99
template
<
typename
T>
100
struct
numeric_limits
101
{
102
static
constexpr
T
max
()
103
{
104
return
std::numeric_limits<T>::max();
105
}
106
};
107
108
template
<>
109
struct
numeric_limits
<int128_t>
110
{
111
static
constexpr
int128_t
min
() {
return
((int128_t) 1) << 127; }
112
static
constexpr
int128_t
max
() {
return
~min
(); }
113
};
114
115
template
<>
116
struct
numeric_limits
<uint128_t>
117
{
118
static
constexpr
uint128_t
min
() {
return
0; }
119
static
constexpr
uint128_t
max
() {
return
~min
(); }
120
};
121
122
template
<
typename
T>
123
struct
is_integral
124
{
125
enum
126
{
127
value
= std::is_integral<T>::value ||
128
std::is_same<T, int128_t>::value ||
129
std::is_same<T, uint128_t>::value
130
};
131
};
132
133
template
<
typename
T>
134
struct
is_signed
135
{
136
enum
137
{
138
value
= std::is_signed<T>::value ||
139
std::is_same<T, int128_t>::value
140
};
141
};
142
143
template
<
typename
T>
144
struct
is_unsigned
145
{
146
enum
147
{
148
value
= std::is_unsigned<T>::value ||
149
std::is_same<T, uint128_t>::value
150
};
151
};
152
153
}
// namespace prt
154
}
// namespace primesum
155
156
#endif
operator<<
std::ostream & operator<<(std::ostream &stream, primesum::uint128_t n)
The __int128_t type (GCC/Clang) is not well supported by the C++ standard library (in 2016) so we hav...
Definition
int128_t.hpp:48
primesum::prt
Portable namespace, includes functions which (unlike the versions form the C++ standard library) work...
Definition
int128_t.hpp:97
primesum
Definition
int128_t.hpp:77
primesum::to_string
std::string to_string(const uint128_t &n)
Definition
int128_t.hpp:79
sparrow::int128_t
primesum::int128_t int128_t
Definition
large_int.hpp:84
primesum::prt::is_integral
Definition
int128_t.hpp:124
primesum::prt::is_integral::value
@ value
Definition
int128_t.hpp:127
primesum::prt::is_signed
Definition
int128_t.hpp:135
primesum::prt::is_signed::value
@ value
Definition
int128_t.hpp:138
primesum::prt::is_unsigned
Definition
int128_t.hpp:145
primesum::prt::is_unsigned::value
@ value
Definition
int128_t.hpp:148
primesum::prt::numeric_limits< int128_t >::max
static constexpr int128_t max()
Definition
int128_t.hpp:112
primesum::prt::numeric_limits< int128_t >::min
static constexpr int128_t min()
Definition
int128_t.hpp:111
primesum::prt::numeric_limits< uint128_t >::max
static constexpr uint128_t max()
Definition
int128_t.hpp:119
primesum::prt::numeric_limits< uint128_t >::min
static constexpr uint128_t min()
Definition
int128_t.hpp:118
primesum::prt::numeric_limits
Definition
int128_t.hpp:101
primesum::prt::numeric_limits::max
static constexpr T max()
Definition
int128_t.hpp:102
sparrow
details
3rdparty
large_integers
int128_t.hpp
Generated by
1.17.0