-
Notifications
You must be signed in to change notification settings - Fork 1
/
uint128.h
127 lines (106 loc) · 3.49 KB
/
uint128.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//////////////////////////////////////////////////////////////////////////
//
// UINT128 : A 128 bit integer type class
// Based on the code of 'Evan Teran'
// as published on "http://codef00.com/code/uint128.h"
// but enhanced for operators and functions
//
// NOTE: This permutation of the code is **NOT** dependent on BOOST
//
#pragma once
#include <intsafe.h>
#include <sqltypes.h>
using std::string;
// Handy definitions
#ifndef int64
using int64 = __int64;
#endif
#ifndef uint64
using uint64 = unsigned __int64;
#endif
//////////////////////////////////////////////////////////////////////////
class uint128
{
public:
// XTOR's
uint128();
uint128(TCHAR p_value);
#ifndef UNICODE
uint128(_TUCHAR p_value);
#endif
uint128(short p_value);
uint128(unsigned short p_value);
uint128(int p_value);
uint128(unsigned int p_value);
uint128(float p_value);
uint128(double p_value);
uint128(const uint128& p_value);
uint128(LPCTSTR p_string);
uint128(uint64 p_low,uint64 p_high = 0);
uint128(const SQL_NUMERIC_STRUCT* p_numeric);
// OPERATORS
// Unary operators
uint128 operator-() const;
uint128 operator~() const;
bool operator!() const;
uint128& operator++();
uint128& operator--();
// Arithmetic operators
uint128 operator+(const uint128& p_other);
uint128 operator-(const uint128& p_other);
uint128 operator*(const uint128& p_other);
uint128 operator/(const uint128& p_other);
uint128 operator%(const uint128& p_other);
// Assignment operators
uint128& operator =(const uint128& p_other);
uint128& operator+=(const uint128& p_other);
uint128& operator-=(const uint128& p_other);
uint128& operator*=(const uint128& p_other);
uint128& operator/=(const uint128& p_other);
uint128& operator%=(const uint128& p_other);
// Bitwise operators
uint128& operator|=(const uint128& p_other);
uint128& operator&=(const uint128& p_other);
uint128& operator^=(const uint128& p_other);
uint128 operator&(const uint128& p_rhs);
uint128 operator|(const uint128& p_rhs);
uint128 operator^(const uint128& p_rhs);
// Shift operators
uint128& operator<<=(const uint128& p_rhs);
uint128& operator>>=(const uint128& p_rhs);
uint128 operator<< (const uint128& p_rhs);
uint128 operator>> (const uint128& p_rhs);
uint128 operator<< (const int p_rhs);
uint128 operator>> (const int p_rhs);
// Comparison operators
bool operator==(const uint128& p_other) const;
bool operator!=(const uint128& p_other) const;
bool operator <(const uint128& p_other) const;
bool operator >(const uint128& p_other) const;
bool operator>=(const uint128& p_other) const;
bool operator<=(const uint128& p_other) const;
// Needed for internal multiplication/division
bool operator!=(const int p_other) const;
// FUNCTIONS
bool IsNull() const; // Is 0.0 ?
void Zero(); // Make it 0.0 !
// GETTERS
short AsShort() const;
int AsInteger() const;
uint64 AsUInt64() const;
CString AsString(unsigned int p_radix = 10) const;
void AsNumeric(SQL_NUMERIC_STRUCT* p_numeric) const;
uint64 GetHighPart() const;
uint64 GetLowPart() const;
#ifdef _DEBUG
void PrintDebug();
#endif
private:
void SetString (LPCTSTR p_string);
void SetNumeric(const SQL_NUMERIC_STRUCT* p_numeric);
// DATA: Our 128 bits integer
uint64 hi; // High 64 bits of 128 in total
uint64 lo; // Low 64 bits of 128 in total
};
// For std junkies
typedef uint128 uint128_t;