• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #4548

22 Jul 2025 02:37AM UTC coverage: 54.273% (-3.0%) from 57.287%
#4548

push

travis-ci

GitHub
Merge pull request #32061 from taosdata/new_testcases

132738 of 315239 branches covered (42.11%)

Branch coverage included in aggregate %.

201371 of 300373 relevant lines covered (67.04%)

3475977.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

43.3
/source/libs/decimal/src/detail/wideInteger.cpp
1
#include "wideInteger.h"
2
#include "intx/int128.hpp"
3
#include "intx/intx.hpp"
4

5

6
const UInt128  uInt128Zero = {0, 0};
7
const uint64_t k1e18 = 1000000000000000000LL;
8
const UInt128  uInt128_1e18 = {k1e18, 0};
9
const UInt128 uInt128One = {1, 0};
10
const UInt128 uInt128Two = {2, 0};
11

12
void makeUInt128(uint128* pUint128, uint64_t high, uint64_t low) {
28,345,870✔
13
  intx::uint128* pIntxUint = (intx::uint128*)pUint128;
28,345,870✔
14
  pIntxUint->hi = high;
28,345,870✔
15
  pIntxUint->lo = low;
28,345,870✔
16
}
28,345,870✔
17

18
uint64_t uInt128Hi(const UInt128* pInt) {
15,240,404✔
19
  intx::uint128 *pIntUint = (intx::uint128*)pInt;
15,240,404✔
20
  return pIntUint->hi;
15,240,404✔
21
}
22

23
uint64_t uInt128Lo(const UInt128* pInt) {
15,768,675✔
24
  intx::uint128 *pIntUint = (intx::uint128*)pInt;
15,768,675✔
25
  return pIntUint->lo;
15,768,675✔
26
}
27

28
void uInt128Add(UInt128* pLeft, const UInt128* pRight) {
×
29
  intx::uint128 *pX = (intx::uint128*)pLeft;
×
30
  const intx::uint128 *pY = (const intx::uint128*)pRight;
×
31
  *pX += *pY;
×
32
}
×
33
void uInt128Subtract(UInt128* pLeft, const UInt128* pRight) {
×
34
  intx::uint128 *pX = (intx::uint128*)pLeft;
×
35
  const intx::uint128 *pY = (const intx::uint128*)pRight;
×
36
  *pX -= *pY;
×
37
}
×
38
void uInt128Multiply(UInt128* pLeft, const UInt128* pRight) {
14,265,940✔
39
  intx::uint128 *pX = (intx::uint128*)pLeft;
14,265,940✔
40
  const intx::uint128 *pY = (const intx::uint128*)pRight;
14,265,940✔
41
  *pX *= *pY;
14,265,940✔
42
  /* __uint128_t *px = (__uint128_t*)pLeft;
43
  const __uint128_t *py = (__uint128_t*)pRight;
44
  *px = *px * *py; */
45
}
15,772,539✔
46
void uInt128Divide(UInt128* pLeft, const UInt128* pRight) {
119,450✔
47
  intx::uint128 *pX = (intx::uint128*)pLeft;
119,450✔
48
  const intx::uint128 *pY = (const intx::uint128*)pRight;
119,450✔
49
  *pX /= *pY;
119,450✔
50
  /* __uint128_t *px = (__uint128_t*)pLeft;
51
  const __uint128_t *py = (__uint128_t*)pRight;
52
  *px = *px / *py; */
53
}
119,450✔
54
void uInt128Mod(UInt128* pLeft, const UInt128* pRight) {
119,450✔
55
  intx::uint128 *pX = (intx::uint128*)pLeft;
119,450✔
56
  const intx::uint128 *pY = (const intx::uint128*)pRight;
119,450✔
57
  *pX %= *pY;
119,450✔
58
  /* __uint128_t *px = (__uint128_t*)pLeft;
59
  const __uint128_t *py = (__uint128_t*)pRight;
60
  *px = *px % *py; */
61
}
119,450✔
62
bool uInt128Lt(const UInt128* pLeft, const UInt128* pRight) {
67✔
63
  const intx::uint128 *pX = (const intx::uint128*)pLeft;
67✔
64
  const intx::uint128 *pY = (const intx::uint128*)pRight;
67✔
65
  return *pX < *pY;
67✔
66
}
67
bool uInt128Gt(const UInt128* pLeft, const UInt128* pRight) {
×
68
  const intx::uint128 *pX = (const intx::uint128*)pLeft;
×
69
  const intx::uint128 *pY = (const intx::uint128*)pRight;
×
70
  return *pX > *pY;
×
71
}
72
bool uInt128Eq(const UInt128* pLeft, const UInt128* pRight) {
179,487✔
73
  const intx::uint128 *pX = (const intx::uint128*)pLeft;
179,487✔
74
  const intx::uint128 *pY = (const intx::uint128*)pRight;
179,487✔
75
  return *pX == *pY;
179,487✔
76
}
77

78
Int128 makeInt128(int64_t high, uint64_t low) {
×
79
  Int128 int128 = {low, high};
×
80
  return int128;
×
81
}
82
int64_t int128Hi(const Int128* pUint128) {
×
83
  return pUint128->high;
×
84
}
85
uint64_t int128Lo(const Int128* pUint128) {
×
86
  return pUint128->low;
×
87
}
88
Int128 int128Abs(const Int128* pInt128) {
×
89
  if (int128Lt(pInt128, &int128Zero)) {
×
90
    return int128Negate(pInt128);
×
91
  }
92
  return *pInt128;
×
93
}
94
Int128 int128Negate(const Int128* pInt128) {
×
95
  uint64_t low = ~pInt128->low + 1;
×
96
  int64_t  high = ~pInt128->high;
×
97
  if (low == 0) high += 1;
×
98
  return makeInt128(high, low);
×
99
}
100
Int128 int128Add(const Int128* pLeft, const Int128* pRight) {
×
101
  intx::uint128 result = *(intx::uint128*)pLeft + *(intx::uint128*)pRight;
×
102
  return *(Int128*)&result;
×
103
}
104
Int128 int128Subtract(const Int128* pLeft, const Int128* pRight) {
×
105
  intx::uint128 result = *(intx::uint128*)pLeft - *(intx::uint128*)pRight;
×
106
  return *(Int128*)&result;
×
107
}
108
Int128 int128Multiply(const Int128* pLeft, const Int128* pRight) {
×
109
  intx::uint128 result = *(intx::uint128*)pLeft * *(intx::uint128*)pRight;
×
110
  return *(Int128*)&result;
×
111
}
112
Int128 int128Divide(const Int128* pLeft, const Int128* pRight) {
×
113
  intx::uint128 result = *(intx::uint128*)pLeft / *(intx::uint128*)pRight;
×
114
  return *(Int128*)&result;
×
115
}
116
Int128 int128Mod(const Int128* pLeft, const Int128* pRight) {
×
117
  intx::uint128 result = *(intx::uint128*)pLeft % *(intx::uint128*)pRight;
×
118
  return *(Int128*)&result;
×
119
}
120
bool int128Lt(const Int128* pLeft, const Int128* pRight) {
83✔
121
  return pLeft->high < pRight->high || (pLeft->high == pRight->high && pLeft->low < pRight->low);
83!
122
}
123
bool int128Gt(const Int128* pLeft, const Int128* pRight) {
×
124
  return int128Lt(pRight, pLeft);
×
125
}
126
bool int128Eq(const Int128* pLeft, const Int128* pRight) {
82✔
127
  return pLeft->high == pRight->high && pLeft->low == pRight->low;
82!
128
}
129
Int128 int128RightShift(const Int128* pLeft, int32_t shift) {
×
130
  intx::uint128 result = *(intx::uint128*)pLeft >> shift;
×
131
  return *(Int128*)&result;
×
132
}
133

134
const Int128 int128Zero = {0, 0};
135
const Int128 int128One = {1, 0};
136

137
UInt256 makeUint256(UInt128 high, UInt128 low) {
×
138
  UInt256 uint256 = {high, low};
×
139
  return uint256;
×
140
}
141
uint128 uInt256Hi(const UInt256* pUint256) {
×
142
  return pUint256->high;
×
143
}
144
uint128 uInt256Lo(const UInt256* pUint256) {
×
145
  return pUint256->low;
×
146
}
147
UInt256 uInt256Add(const UInt256* pLeft, const UInt256* pRight) {
×
148
  intx::uint256 result = *(intx::uint256*)pLeft + *(intx::uint256*)pRight;
×
149
  return *(UInt256*)&result;
×
150
}
151
UInt256 uInt256Subtract(const UInt256* pLeft, const UInt256* pRight) {
×
152
  intx::uint256 result = *(intx::uint256*)pLeft - *(intx::uint256*)pRight;
×
153
  return *(UInt256*)&result;
×
154
}
155
UInt256 uInt256Multiply(const UInt256* pLeft, const UInt256* pRight) {
×
156
  intx::uint256 result = *(intx::uint256*)pLeft * *(intx::uint256*)pRight;
×
157
  return *(UInt256*)&result;
×
158
}
159
UInt256 uInt256Divide(const UInt256* pLeft, const UInt256* pRight) {
×
160
  intx::uint256 result = *(intx::uint256*)pLeft / *(intx::uint256*)pRight;
×
161
  return *(UInt256*)&result;
×
162
}
163
UInt256 uInt256Mod(const UInt256* pLeft, const UInt256* pRight) {
×
164
  intx::uint256 result = *(intx::uint256*)pLeft % *(intx::uint256*)pRight;
×
165
  return *(UInt256*)&result;
×
166
}
167
bool uInt256Lt(const UInt256* pLeft, const UInt256* pRight) {
×
168
  return *(intx::uint256*)pLeft < *(intx::uint256*)pRight;
×
169
}
170
bool uInt256Gt(const UInt256* pLeft, const UInt256* pRight) {
×
171
  return *(intx::uint256*)pLeft > *(intx::uint256*)pRight;
×
172
}
173
bool uInt256Eq(const UInt256* pLeft, const UInt256* pRight) {
×
174
  return *(intx::uint256*)pLeft == *(intx::uint256*)pRight;
×
175
}
176
UInt256 uInt256RightShift(const UInt256* pLeft, int32_t shift) {
×
177
  intx::uint256 result = *(intx::uint256*)pLeft >> shift;
×
178
  return *(UInt256*)&result;
×
179
}
180

181
Int256 makeInt256(Int128 high, UInt128 low) {
36✔
182
  Int256 int256 = {low, high};
36✔
183
  return int256;
36✔
184
}
185
Int128 int256Hi(const Int256* pUint256) {
166✔
186
  return pUint256->high;
166✔
187
}
188
UInt128 int256Lo(const Int256* pUint256) {
175✔
189
  return pUint256->low;
175✔
190
}
191
Int256 int256Abs(const Int256* pInt256) {
19✔
192
  if (int256Lt(pInt256, &int256Zero)) {
19!
193
    return int256Negate(pInt256);
×
194
  }
195
  return *pInt256;
19✔
196
}
197

198
Int256 int256Negate(const Int256* pInt256) {
×
199
  return int256Subtract(&int256Zero, pInt256);
×
200
}
201
Int256 int256Add(const Int256* pLeft, const Int256* pRight) {
1✔
202
  intx::uint256 result = *(intx::uint256*)pLeft + *(intx::uint256*)pRight;
1✔
203
  return *(Int256*)&result;
1✔
204
}
205
Int256 int256Subtract(const Int256* pLeft, const Int256* pRight) {
×
206
  intx::uint256 result = *(intx::uint256*)pLeft - *(intx::uint256*)pRight;
×
207
  return *(Int256*)&result;
×
208
}
209
Int256 int256Multiply(const Int256* pLeft, const Int256* pRight) {
14✔
210
  intx::uint256 result = *(intx::uint256*)pLeft * *(intx::uint256*)pRight;
14✔
211
  return *(Int256*)&result;
14✔
212
}
213
Int256 int256Divide(const Int256* pLeft, const Int256* pRight) {
8✔
214
  Int256 l = *pLeft, r = *pRight;
8✔
215
  bool   leftNegative = int256Lt(pLeft, &int256Zero), rightNegative = int256Lt(pRight, &int256Zero);
8!
216
  if (leftNegative) {
8!
217
    l = int256Abs(pLeft);
×
218
  }
219
  if (rightNegative) {
8!
220
    r = int256Abs(pRight);
×
221
  }
222
  intx::uint256 result = *(intx::uint256*)&l / *(intx::uint256*)&r;
8✔
223
  Int256 res =  *(Int256*)&result;
8✔
224
  if (leftNegative != rightNegative)
8!
225
    res = int256Negate(&res);
×
226
  return res;
16✔
227
}
228

229
Int256 int256Mod(const Int256* pLeft, const Int256* pRight) {
9✔
230
  Int256 left = *pLeft, right = *pRight;
9✔
231
  bool leftNegative = int256Lt(pLeft, &int256Zero);
9!
232
  if (leftNegative) {
9!
233
    left = int256Abs(&left);
×
234
  }
235
  bool rightNegate = int256Lt(pRight, &int256Zero);
9!
236
  if (rightNegate) right = int256Abs(pRight);
9!
237
  intx::uint256 result = *(intx::uint256*)&left % *(intx::uint256*)&right;
9✔
238
  Int256 res =  *(Int256*)&result;
9✔
239
  if (leftNegative) res = int256Negate(&res);
9!
240
  return res;
18✔
241
}
242
bool int256Lt(const Int256* pLeft, const Int256* pRight) {
83✔
243
  Int128  hiLeft = int256Hi(pLeft), hiRight = int256Hi(pRight);
83!
244
  UInt128 lowLeft = int256Lo(pLeft), lowRight = int256Lo(pRight);
83!
245
  return int128Lt(&hiLeft, &hiRight) || (int128Eq(&hiLeft, &hiRight) && uInt128Lt(&lowLeft, &lowRight));
83!
246
}
247
bool int256Gt(const Int256* pLeft, const Int256* pRight) {
19✔
248
  return int256Lt(pRight, pLeft);
19✔
249
}
250
bool int256Eq(const Int256* pLeft, const Int256* pRight) {
×
251
  Int128  hiLeft = int256Hi(pLeft), hiRight = int256Hi(pRight);
×
252
  UInt128 lowLeft = int256Lo(pLeft), lowRight = int256Lo(pRight);
×
253
  return int128Eq(&hiLeft, &hiRight) && uInt128Eq(&lowLeft, &lowRight);
×
254
}
255
Int256 int256RightShift(const Int256* pLeft, int32_t shift) {
15✔
256
  intx::uint256 result = *(intx::uint256*)pLeft >> shift;
15✔
257
  return *(Int256*)&result;
15✔
258
}
259

260
const Int256 int256One = {uInt128One, int128Zero};
261
const Int256 int256Zero = {uInt128Zero, int128Zero};
262
const Int256 int256Two = {uInt128Two, int128Zero};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc