# Algorithms_in_C++: ciphers/uint128_t.hpp File Reference

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 More...

## Functions

std::string | add (const std::string &first, const std::string &second)
| Adding two string. More...
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

  first | First integer string
  second | Second integer string

Returns
  string denoting the addition of both the strings

{
std::string third;
int16_t sum = 0, carry = 0;
for (int32_t i = static_cast<int32_t>(first.size()) - 1,
j = static_cast<int32_t>(second.size()) - 1;
i >= 0 || j >= 0; --i, --j) {
sum = ((i >= 0 ? first[i] - '0' : 0) + (j >= 0 ? second[j] - '0' : 0) +
carry);
carry = sum / 10;
sum %= 10;
third.push_back(sum + '0');
}
if (carry) {
third.push_back('1');
}
std::reverse(third.begin(), third.end());
return third;
}
std::string
std::string::begin
T begin(T... args)
std::string::end
T end(T... args)
machine_learning::sum
T sum(const std::vector< std::valarray< T > > &A)
Definition: vector_ops.hpp:232
std::string::push_back
T push_back(T... args)
std::reverse
T reverse(T... args)
std::string::size
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

{
return uint128_t(p) != q;
}
uint128_t
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

{
return uint128_t(p) % q;
}

## 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

{
return uint128_t(p) & q;
}

## 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

{
return uint128_t(p) && q;
}

## 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

{
return uint128_t(p) * q;
}

## 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

{
return uint128_t(p) + q;
}

## 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

{
return uint128_t(p) - q;
}

## 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

{
return uint128_t(p) / q;
}

## 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

{
return uint128_t(p) < q;
}

## 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

{
return uint128_t(p) <= q;
}

## 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

{
return uint128_t(p) == q;
}

## 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

{
return uint128_t(p) > q;
}

## 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

{
return uint128_t(p) >= q;
}

## 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

{
return uint128_t(p) ^ q;
}

## 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

{
return uint128_t(p) | q;
}

## 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

{
return uint128_t(p) || q;
}