Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
uint128_t.hpp File Reference
#include <algorithm>
#include <ostream>
#include <string>
#include <utility>
Include dependency graph for uint128_t.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  std::is_integral< uint128_t >
 
struct  std::is_arithmetic< uint128_t >
 
struct  std::is_unsigned< uint128_t >
 
class  uint128_t
 class for 128-bit unsigned integer More...
 

Macros

#define CIPHERS_UINT128_T_HPP_
 for std::pair library
 

Functions

std::string add (const std::string &first, const std::string &second)
 Adding two string.
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint128_t operator+ (const T &p, const uint128_t &q)
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint128_t operator- (const T p, const uint128_t &q)
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint128_t operator* (const T p, const uint128_t &q)
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint128_t operator/ (const T p, const uint128_t &q)
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint128_t operator% (const T p, const uint128_t &q)
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint128_t operator& (const T &p, const uint128_t &q)
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint128_t operator| (const T p, const uint128_t &q)
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint128_t operator^ (const T p, const uint128_t &q)
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator&& (const T p, const uint128_t &q)
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator|| (const T p, const uint128_t &q)
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator== (const T p, const uint128_t &q)
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator!= (const T p, const uint128_t &q)
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator< (const T p, const uint128_t &q)
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator<= (const T p, const uint128_t &q)
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator> (const T p, const uint128_t &q)
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator>= (const T p, const uint128_t &q)
 

Detailed Description

Implementation of 128-bit unsigned integers.

Note
The implementation can be flagged as not completed. This header is used with enough operations as a part of bigger integer types 256-bit integer.
Author
Ashish Daulatabad

Macro Definition Documentation

◆ CIPHERS_UINT128_T_HPP_

#define CIPHERS_UINT128_T_HPP_

for std::pair library

for std::reverse and other operations for std::cout overload for std::string

Function Documentation

◆ add()

std::string add ( const std::string & first,
const std::string & second )

Adding two string.

Adds two long integer, only used for printing numbers

Parameters
firstFirst integer string
secondSecond integer string
Returns
string denoting the addition of both the strings
37 {
38 std::string third;
39 int16_t sum = 0, carry = 0;
40 for (int32_t i = static_cast<int32_t>(first.size()) - 1,
41 j = static_cast<int32_t>(second.size()) - 1;
42 i >= 0 || j >= 0; --i, --j) {
43 sum = ((i >= 0 ? first[i] - '0' : 0) + (j >= 0 ? second[j] - '0' : 0) +
44 carry);
45 carry = sum / 10;
46 sum %= 10;
47 third.push_back(sum + '0');
48 }
49 if (carry) {
50 third.push_back('1');
51 }
52 std::reverse(third.begin(), third.end());
53 return third;
54}
T begin(T... args)
T end(T... args)
T sum(const std::vector< std::valarray< T > > &A)
Definition vector_ops.hpp:232
T push_back(T... args)
T reverse(T... args)
T size(T... args)
Here is the call graph for this function:

◆ operator!=()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator!= ( const T p,
const uint128_t & q )
inline
1078 {
1079 return uint128_t(p) != q;
1080}
class for 128-bit unsigned integer
Definition uint128_t.hpp:59

◆ operator%()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint128_t operator% ( const T p,
const uint128_t & q )
inline
1033 {
1034 return uint128_t(p) % q;
1035}

◆ operator&()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint128_t operator& ( const T & p,
const uint128_t & q )
inline
1040 {
1041 return uint128_t(p) & q;
1042}

◆ operator&&()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator&& ( const T p,
const uint128_t & q )
inline
1059 {
1060 return uint128_t(p) && q;
1061}

◆ operator*()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint128_t operator* ( const T p,
const uint128_t & q )
inline
1021 {
1022 return uint128_t(p) * q;
1023}

◆ operator+()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint128_t operator+ ( const T & p,
const uint128_t & q )
inline
1009 {
1010 return uint128_t(p) + q;
1011}

◆ operator-()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint128_t operator- ( const T p,
const uint128_t & q )
inline
1015 {
1016 return uint128_t(p) - q;
1017}

◆ operator/()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint128_t operator/ ( const T p,
const uint128_t & q )
inline
1027 {
1028 return uint128_t(p) / q;
1029}

◆ operator<()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator< ( const T p,
const uint128_t & q )
inline
1084 {
1085 return uint128_t(p) < q;
1086}

◆ operator<=()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator<= ( const T p,
const uint128_t & q )
inline
1090 {
1091 return uint128_t(p) <= q;
1092}

◆ operator==()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator== ( const T p,
const uint128_t & q )
inline
1072 {
1073 return uint128_t(p) == q;
1074}

◆ operator>()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator> ( const T p,
const uint128_t & q )
inline
1096 {
1097 return uint128_t(p) > q;
1098}

◆ operator>=()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator>= ( const T p,
const uint128_t & q )
inline
1102 {
1103 return uint128_t(p) >= q;
1104}

◆ operator^()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint128_t operator^ ( const T p,
const uint128_t & q )
inline
1052 {
1053 return uint128_t(p) ^ q;
1054}

◆ operator|()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint128_t operator| ( const T p,
const uint128_t & q )
inline
1046 {
1047 return uint128_t(p) | q;
1048}

◆ operator||()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator|| ( const T p,
const uint128_t & q )
inline
1065 {
1066 return uint128_t(p) || q;
1067}