TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
uint128_t.hpp File Reference
#include <algorithm>
#include <cstdint>
#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::reverse and other operations
 

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

Definition in file uint128_t.hpp.

Macro Definition Documentation

◆ CIPHERS_UINT128_T_HPP_

#define CIPHERS_UINT128_T_HPP_

for std::reverse and other operations

for std::cout overload for std::string for std::pair library

Definition at line 21 of file uint128_t.hpp.

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

Definition at line 38 of file uint128_t.hpp.

38 {
39 std::string third;
40 int16_t sum = 0, carry = 0;
41 for (int32_t i = static_cast<int32_t>(first.size()) - 1,
42 j = static_cast<int32_t>(second.size()) - 1;
43 i >= 0 || j >= 0; --i, --j) {
44 sum = ((i >= 0 ? first[i] - '0' : 0) + (j >= 0 ? second[j] - '0' : 0) +
45 carry);
46 carry = sum / 10;
47 sum %= 10;
48 third.push_back(sum + '0');
49 }
50 if (carry) {
51 third.push_back('1');
52 }
53 std::reverse(third.begin(), third.end());
54 return third;
55}
T sum(const std::vector< std::valarray< T > > &A)

◆ 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

Definition at line 1079 of file uint128_t.hpp.

1079 {
1080 return uint128_t(p) != q;
1081}
class for 128-bit unsigned integer
Definition uint128_t.hpp:60

◆ 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

Definition at line 1034 of file uint128_t.hpp.

1034 {
1035 return uint128_t(p) % q;
1036}

◆ 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

Definition at line 1041 of file uint128_t.hpp.

1041 {
1042 return uint128_t(p) & q;
1043}

◆ 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

Definition at line 1060 of file uint128_t.hpp.

1060 {
1061 return uint128_t(p) && q;
1062}

◆ 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

Definition at line 1022 of file uint128_t.hpp.

1022 {
1023 return uint128_t(p) * q;
1024}

◆ 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

Definition at line 1010 of file uint128_t.hpp.

1010 {
1011 return uint128_t(p) + q;
1012}

◆ 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

Definition at line 1016 of file uint128_t.hpp.

1016 {
1017 return uint128_t(p) - q;
1018}

◆ 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

Definition at line 1028 of file uint128_t.hpp.

1028 {
1029 return uint128_t(p) / q;
1030}

◆ 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

Definition at line 1085 of file uint128_t.hpp.

1085 {
1086 return uint128_t(p) < q;
1087}

◆ 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

Definition at line 1091 of file uint128_t.hpp.

1091 {
1092 return uint128_t(p) <= q;
1093}

◆ 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

Definition at line 1073 of file uint128_t.hpp.

1073 {
1074 return uint128_t(p) == q;
1075}

◆ 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

Definition at line 1097 of file uint128_t.hpp.

1097 {
1098 return uint128_t(p) > q;
1099}

◆ 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

Definition at line 1103 of file uint128_t.hpp.

1103 {
1104 return uint128_t(p) >= q;
1105}

◆ 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

Definition at line 1053 of file uint128_t.hpp.

1053 {
1054 return uint128_t(p) ^ q;
1055}

◆ 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

Definition at line 1047 of file uint128_t.hpp.

1047 {
1048 return uint128_t(p) | q;
1049}

◆ 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

Definition at line 1066 of file uint128_t.hpp.

1066 {
1067 return uint128_t(p) || q;
1068}