Skip to content

Commit 88e8fa6

Browse files
committed
[MSVCRT] Import msvcrt from wine-10.0
1 parent 0fca13d commit 88e8fa6

50 files changed

Lines changed: 48882 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dll/win32/msvcrt/bnum.h

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Copyright 2020 Piotr Caban for CodeWeavers
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17+
*/
18+
19+
#ifndef __WINE_BNUM_H
20+
#define __WINE_BNUM_H
21+
22+
#define EXP_BITS 11
23+
#define MANT_BITS 53
24+
25+
static const int p10s[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
26+
27+
#define LIMB_DIGITS 9 /* each DWORD stores up to 9 digits */
28+
#define LIMB_MAX 1000000000 /* 10^9 */
29+
30+
#define BNUM_PREC64 128 /* data size needed to store 64-bit double */
31+
#define BNUM_PREC80 2048 /* data size needed to store 80-bit double */
32+
33+
/* bnum represents real number with fixed decimal point */
34+
struct bnum {
35+
int b; /* least significant digit position */
36+
int e; /* most significant digit position + 1 */
37+
int size; /* data buffer size in DWORDS (power of 2) */
38+
DWORD data[1]; /* circular buffer, base 10 number */
39+
};
40+
41+
static inline int bnum_idx(struct bnum *b, int idx)
42+
{
43+
return idx & (b->size - 1);
44+
}
45+
46+
/* Returns TRUE if new most significant limb was added */
47+
static inline BOOL bnum_lshift(struct bnum *b, int shift)
48+
{
49+
DWORD rest = 0;
50+
ULONGLONG tmp;
51+
int i;
52+
53+
/* The limbs number can change by up to 1 so shift <= 29 */
54+
assert(shift <= 29);
55+
56+
for(i=b->b; i<b->e; i++) {
57+
tmp = ((ULONGLONG)b->data[bnum_idx(b, i)] << shift) + rest;
58+
rest = tmp / LIMB_MAX;
59+
b->data[bnum_idx(b, i)] = tmp % LIMB_MAX;
60+
61+
if(i == b->b && !b->data[bnum_idx(b, i)])
62+
b->b++;
63+
}
64+
65+
if(rest) {
66+
b->data[bnum_idx(b, b->e)] = rest;
67+
b->e++;
68+
69+
if(bnum_idx(b, b->b) == bnum_idx(b, b->e)) {
70+
if(b->data[bnum_idx(b, b->b)]) b->data[bnum_idx(b, b->b+1)] |= 1;
71+
b->b++;
72+
}
73+
return TRUE;
74+
}
75+
return FALSE;
76+
}
77+
78+
/* Returns TRUE if most significant limb was removed */
79+
static inline BOOL bnum_rshift(struct bnum *b, int shift)
80+
{
81+
DWORD tmp, rest = 0;
82+
BOOL ret = FALSE;
83+
int i;
84+
85+
/* Compute LIMB_MAX << shift without accuracy loss */
86+
assert(shift <= 9);
87+
88+
for(i=b->e-1; i>=b->b; i--) {
89+
tmp = b->data[bnum_idx(b, i)] & ((1<<shift)-1);
90+
b->data[bnum_idx(b, i)] = (b->data[bnum_idx(b, i)] >> shift) + rest;
91+
rest = (LIMB_MAX >> shift) * tmp;
92+
if(i==b->e-1 && !b->data[bnum_idx(b, i)]) {
93+
b->e--;
94+
ret = TRUE;
95+
}
96+
}
97+
98+
if(rest) {
99+
if(bnum_idx(b, b->b-1) == bnum_idx(b, b->e)) {
100+
if(rest) b->data[bnum_idx(b, b->b)] |= 1;
101+
} else {
102+
b->b--;
103+
b->data[bnum_idx(b, b->b)] = rest;
104+
}
105+
}
106+
return ret;
107+
}
108+
109+
static inline void bnum_mult(struct bnum *b, int mult)
110+
{
111+
DWORD rest = 0;
112+
ULONGLONG tmp;
113+
int i;
114+
115+
assert(mult <= LIMB_MAX);
116+
117+
for(i=b->b; i<b->e; i++) {
118+
tmp = ((ULONGLONG)b->data[bnum_idx(b, i)] * mult) + rest;
119+
rest = tmp / LIMB_MAX;
120+
b->data[bnum_idx(b, i)] = tmp % LIMB_MAX;
121+
122+
if(i == b->b && !b->data[bnum_idx(b, i)])
123+
b->b++;
124+
}
125+
126+
if(rest) {
127+
b->data[bnum_idx(b, b->e)] = rest;
128+
b->e++;
129+
130+
if(bnum_idx(b, b->b) == bnum_idx(b, b->e)) {
131+
if(b->data[bnum_idx(b, b->b)]) b->data[bnum_idx(b, b->b+1)] |= 1;
132+
b->b++;
133+
}
134+
}
135+
}
136+
137+
#endif /* __WINE_BNUM_H */

0 commit comments

Comments
 (0)