Algorithms_in_C++  1.0.0
Set of algorithms implemented in C++.
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
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: