22#define NONAMELESSUNION
23#define NONAMELESSSTRUCT
38#define CY_MULTIPLIER 10000
39#define CY_MULTIPLIER_F 10000.0
40#define CY_HALF (CY_MULTIPLIER/2)
41#define CY_HALF_F (CY_MULTIPLIER_F/2.0)
70 FIXME(
"VT_ type %d unhandled, please report!\n",
vt);
77#define VARIANT_DutchRound(typ, value, res) do { \
78 double whole = value < 0 ? ceil(value) : floor(value); \
79 double fract = value - whole; \
80 if (fract > 0.5) res = (typ)whole + (typ)1; \
81 else if (fract == 0.5) { typ is_odd = (typ)whole & 1; res = whole + is_odd; } \
82 else if (fract >= 0.0) res = (typ)whole; \
83 else if (fract == -0.5) { typ is_odd = (typ)whole & 1; res = whole - is_odd; } \
84 else if (fract > -0.5) res = (typ)whole; \
85 else res = (typ)whole - (typ)1; \
118 static DISPPARAMS emptyParams = {
NULL,
NULL, 0, 0 };
146#define RETTYP static inline HRESULT
150#define SIMPLE(dest, src, func) RETTYP _##func(src in, dest* out) { \
151 *out = in; return S_OK; }
154#define NEGTST(dest, src, func) RETTYP _##func(src in, dest* out) { \
155 if (in < 0) return DISP_E_OVERFLOW; *out = in; return S_OK; }
158#define POSTST(dest, src, func, tst) RETTYP _##func(src in, dest* out) { \
159 if (in > (dest)tst) return DISP_E_OVERFLOW; *out = in; return S_OK; }
162#define BOTHTST(dest, src, func, lo, hi) RETTYP _##func(src in, dest* out) { \
163 if (in < (dest)lo || in > hi) return DISP_E_OVERFLOW; *out = in; return S_OK; }
284 return _VarI1FromUI1(bIn, pcOut);
303 return _VarI1FromI2(sIn, pcOut);
322 return _VarI1FromI4(iIn, pcOut);
363 if (dblIn < I1_MIN - 0.5 || dblIn >=
I1_MAX + 0.5)
407 return _VarI1FromI4(
i, pcOut);
467 return _VarI1FromBool(boolIn, pcOut);
486 return _VarI1FromUI2(usIn, pcOut);
506 return _VarI1FromUI4(ulIn, pcOut);
531 hRet = _VarI1FromI8(i64, pcOut);
551 return _VarI1FromI8(llIn, pcOut);
570 return _VarI1FromUI8(ullIn, pcOut);
592 return _VarUI1FromI2(sIn, pbOut);
611 return _VarUI1FromI4(iIn, pbOut);
653 if (dblIn < -0.5 || dblIn >=
UI1_MAX + 0.5)
681 return _VarUI1FromUI4(
i, pbOut);
760 return _VarUI1FromBool(boolIn, pbOut);
779 return _VarUI1FromI1(cIn, pbOut);
798 return _VarUI1FromUI2(usIn, pbOut);
817 return _VarUI1FromUI4(ulIn, pbOut);
842 hRet = _VarUI1FromI8(i64, pbOut);
862 return _VarUI1FromI8(llIn, pbOut);
881 return _VarUI1FromUI8(ullIn, pbOut);
902 return _VarI2FromUI1(bIn, psOut);
920 return _VarI2FromI4(iIn, psOut);
959 if (dblIn < I2_MIN - 0.5 || dblIn >=
I2_MAX + 0.5)
983 return _VarI2FromI4(
i, psOut);
1061 return _VarI2FromBool(boolIn, psOut);
1078 return _VarI2FromI1(cIn, psOut);
1096 return _VarI2FromUI2(usIn, psOut);
1114 return _VarI2FromUI4(ulIn, psOut);
1139 hRet = _VarI2FromI8(i64, psOut);
1158 return _VarI2FromI8(llIn, psOut);
1176 return _VarI2FromUI8(ullIn, psOut);
1196 return _VarUI2FromUI1(bIn, pusOut);
1214 return _VarUI2FromI2(sIn, pusOut);
1232 return _VarUI2FromI4(iIn, pusOut);
1271 if (dblIn < -0.5 || dblIn >=
UI2_MAX + 0.5)
1316 return _VarUI2FromUI4(
i, pusOut);
1375 return _VarUI2FromBool(boolIn, pusOut);
1393 return _VarUI2FromI1(cIn, pusOut);
1411 return _VarUI2FromUI4(ulIn, pusOut);
1436 hRet = _VarUI2FromI8(i64, pusOut);
1455 return _VarUI2FromI8(llIn, pusOut);
1473 return _VarUI2FromUI8(ullIn, pusOut);
1493 return _VarI4FromUI1(bIn, piOut);
1512 return _VarI4FromI2(sIn, piOut);
1551 if (dblIn < I4_MIN - 0.5 || dblIn >=
I4_MAX + 0.5)
1651 return _VarI4FromBool(boolIn, piOut);
1668 return _VarI4FromI1(cIn, piOut);
1685 return _VarI4FromUI2(usIn, piOut);
1703 return _VarI4FromUI4(ulIn, piOut);
1728 hRet = _VarI4FromI8(i64, piOut);
1747 return _VarI4FromI8(llIn, piOut);
1765 return _VarI4FromUI8(ullIn, piOut);
1785 return _VarUI4FromUI1(bIn, pulOut);
1803 return _VarUI4FromI2(sIn, pulOut);
1821 return _VarUI4FromI4(iIn, pulOut);
1860 if (dblIn < -0.5 || dblIn >=
UI4_MAX + 0.5)
1960 return _VarUI4FromBool(boolIn, pulOut);
1978 return _VarUI4FromI1(cIn, pulOut);
1995 return _VarUI4FromUI2(usIn, pulOut);
2020 hRet = _VarUI4FromI8(i64, pulOut);
2039 return _VarUI4FromI8(llIn, pulOut);
2057 return _VarUI4FromUI8(ullIn, pulOut);
2077 return _VarI8FromUI1(bIn, pi64Out);
2095 return _VarI8FromI2(sIn, pi64Out);
2150 if ( dblIn < -4611686018427387904.0 || dblIn >= 4611686018427387904.0)
2284 return _VarI8FromI1(cIn, pi64Out);
2301 return _VarI8FromUI2(usIn, pi64Out);
2318 return _VarI8FromUI4(ulIn, pi64Out);
2340 if (
DEC_SIGN(pdecIn) & ~DECIMAL_NEG)
2380 return _VarI8FromUI8(ullIn, pi64Out);
2401 return _VarUI8FromI8(llIn, pui64Out);
2418 return _VarUI8FromUI1(bIn, pui64Out);
2435 return _VarUI8FromI2(sIn, pui64Out);
2475 if (dblIn < -0.5 || dblIn > 1.844674407370955e19)
2613 return _VarUI8FromI1(cIn, pui64Out);
2630 return _VarUI8FromUI2(usIn, pui64Out);
2647 return _VarUI8FromUI4(ulIn, pui64Out);
2675 if (
DEC_SIGN(pdecIn) & ~DECIMAL_NEG)
2683 WARN(
"Sign would be ignored under Win32!\n");
2720 return _VarR4FromUI1(bIn, pFltOut);
2737 return _VarR4FromI2(sIn, pFltOut);
2754 return _VarR4FromI4(lIn, pFltOut);
2772 double d = dblIn < 0.0 ? -dblIn : dblIn;
2890 return _VarR4FromI1(cIn, pFltOut);
2910 return _VarR4FromUI2(usIn, pFltOut);
2930 return _VarR4FromUI4(ulIn, pFltOut);
2964 highPart *= 4294967296.0F;
2965 highPart *= 4294967296.0F;
2988 return _VarR4FromI8(llIn, pFltOut);
3005 return _VarR4FromUI8(ullIn, pFltOut);
3023 if (fltLeft < dblRight)
3025 else if (fltLeft > dblRight)
3047 return _VarR8FromUI1(bIn, pDblOut);
3064 return _VarR8FromI2(sIn, pDblOut);
3081 return _VarR8FromI4(lIn, pDblOut);
3098 return _VarR8FromR4(fltIn, pDblOut);
3132 return _VarR8FromDate(dateIn, pDblOut);
3211 return _VarR8FromI1(cIn, pDblOut);
3231 return _VarR8FromUI2(usIn, pDblOut);
3251 return _VarR8FromUI4(ulIn, pDblOut);
3270 double divisor = 1.0, highPart;
3284 highPart *= 4294967296.0F;
3285 highPart *= 4294967296.0F;
3308 return _VarR8FromI8(llIn, pDblOut);
3325 return _VarR8FromUI8(ullIn, pDblOut);
3343 *pDblOut =
pow(dblLeft, dblPow);
3370 double scale, whole, fract;
3378 whole = dblIn < 0 ?
ceil(dblIn) :
floor(dblIn);
3379 fract = dblIn - whole;
3382 dblIn = whole + 1.0;
3383 else if (fract == 0.5)
3384 dblIn = whole +
fmod(whole, 2.0);
3385 else if (fract >= 0.0)
3387 else if (fract == -0.5)
3388 dblIn = whole -
fmod(whole, 2.0);
3389 else if (fract > -0.5)
3392 dblIn = whole - 1.0;
3394 *pDblOut = dblIn /
scale;
3505#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3509 static const unsigned short r8_fpcontrol = 0x137f;
3511 unsigned short old_fpcontrol, result_fpstatus;
3514 __asm__ __volatile__(
"fnclex" );
3515 __asm__ __volatile__(
"fstcw %0" :
"=m" (old_fpcontrol) : );
3516 __asm__ __volatile__(
"fldcw %0" : :
"m" (r8_fpcontrol) );
3518 __asm__ __volatile__(
"fldl %0" : :
"m" (dblIn) );
3519 __asm__ __volatile__(
"fmull %0" : :
"m" (r8_multiplier) );
3520 __asm__ __volatile__(
"fistpll %0" : :
"m" (*pCyOut) );
3522 __asm__ __volatile__(
"fstsw %0" :
"=m" (result_fpstatus) : );
3523 __asm__ __volatile__(
"fnclex" );
3524 __asm__ __volatile__(
"fldcw %0" : :
"m" (old_fpcontrol) );
3526 if (result_fpstatus & 0x9)
3530 if (dblIn < -922337203685477.5807 || dblIn >= 922337203685477.5807)
3878 if (cyIn.s.
Hi == (
int)0x80000000 && !cyIn.s.
Lo)
3953 if (cyIn.s.
Hi == (
int)0x80000000 && !cyIn.s.
Lo)
4024 else if (
result.int64 > 0)
4244 if (cyIn.s.
Hi & 0x80000000)
4403 if (pLi->
u.HighPart & 0x80000000)
4448 if (
DEC_SIGN(*ppDecLeft) & ~DECIMAL_NEG ||
DEC_SIGN(*ppDecRight) & ~DECIMAL_NEG)
4458 if (scaleAmount > 0)
4460 decTemp = *(*ppDecRight);
4461 *ppDecRight = &pDecOut[0];
4465 decTemp = *(*ppDecLeft);
4466 *ppDecLeft = &pDecOut[0];
4473 decTemp = pDecOut[0];
4479 DEC_SCALE(&pDecOut[0]) += (scaleAmount > 0) ? scaleAmount : (-scaleAmount);
4484 pDecOut[0] = decTemp;
4485 if (scaleAmount > 0)
4489 *ppDecLeft = &pDecOut[1];
4493 DEC_SCALE(&pDecOut[0]) += (-scaleAmount) -
i;
4495 *ppDecRight = &pDecOut[1];
4510 remainder = (digit > 0xFFFFFFFF) ? 1 : 0;
4511 di.
bitsnum[
i] = digit & 0xFFFFFFFF;
4525 *pulHigh = ul64.
u.HighPart;
4526 return ul64.
u.LowPart;
4536 if (ulLeft < ulRight)
4547 ul64.
u.HighPart = -ul64.
u.HighPart ;
4549 *pulHigh = ul64.
u.HighPart;
4550 return ul64.
u.LowPart;
4559 *pulHigh = ul64.
u.HighPart;
4560 return ul64.
u.LowPart;
4607 goto VarDecAdd_AsPositive;
4617VarDecAdd_AsNegative:
4624VarDecAdd_AsInvertedNegative:
4638 goto VarDecAdd_AsInvertedNegative;
4640 goto VarDecAdd_AsNegative;
4645VarDecAdd_AsPositive:
4708 for (
i =
n - 1;
i >= 0 && !
p[
i];
i--);
4709 for (;
i >= 0;
i--) {
4722 for (;
n > 0;
n--)
if (*
p++ != 0)
return FALSE;
4735 signed int mulstart;
4738 result->sign = (
a->sign ^
b->sign) ? 1 : 0;
4743 result->scale =
a->scale +
b->scale;
4744 memset(running, 0,
sizeof(running));
4747 for (mulstart =
ARRAY_SIZE(
a->bitsnum) - 1; mulstart >= 0 && !
a->bitsnum[mulstart]; mulstart--);
4757 for (iA = 0; iA <= mulstart; iA++) {
4761 for (iOverflowMul = 0, iB = 0; iB <
ARRAY_SIZE(
b->bitsnum); iB++) {
4765 iRV =
VARIANT_Mul(
b->bitsnum[iB],
a->bitsnum[iA], &iOverflowMul);
4781 while (
result->scale > 0) {
4782 memcpy(quotient, running,
sizeof(quotient));
4785 memcpy(running, quotient,
sizeof(quotient));
4806 remainder = (digit > 0xFFFFFFFF) ? 1 : 0;
4807 running[
i] = digit & 0xFFFFFFFF;
4838 else overflow =
TRUE;
4846 }
else overflow =
TRUE;
4850 memcpy(quotient,
a->bitsnum,
sizeof(
a->bitsnum));
4872 if (i <= a->
scale) {
4873 unsigned int numzeroes =
a->scale + 1 -
i;
4874 if (
i + 1 + numzeroes >=
n) {
4879 while (numzeroes > 0) {
4880 s[--numzeroes] =
'0';
4887 unsigned int periodpos =
i -
a->scale;
4891 memmove(
s + periodpos + 1,
s + periodpos, (
i + 1 - periodpos) *
sizeof(
WCHAR));
4892 s[periodpos] =
'.';
i++;
4895 while (
s[
i - 1] ==
'0')
s[--
i] =
'\0';
4896 if (
s[
i - 1] ==
'.')
s[--
i] =
'\0';
4935 unsigned char carry = 0;
4941 for (
i = 0;
i < np;
i++) {
4945 v[
i] =
sum & 0xffffffff;
4948 for (;
i < nv && carry;
i++) {
4951 v[
i] =
sum & 0xffffffff;
4976 DWORD * negdivisor = tempsub +
n;
4979 for (
i = 0;
i <
n;
i++) negdivisor[
i] = (
i < dn) ?
~divisor[
i] : 0xFFFFFFFF;
4987 for (
i <<= 5;
i < (
n << 5);
i++) {
4995 if ((tempsub[
n - 1] & 0x80000000) == 0) {
5008 for (iOverflowMul = 0,
i = 0;
i <
n;
i++)
5010 return (
unsigned char)iOverflowMul;
5019 DWORD *
a,
int * ascale,
unsigned int an,
5020 DWORD *
b,
int * bscale,
unsigned int bn)
5033 unsigned int tn = an + 1;
5036 if (bn + 1 > tn) tn = bn + 1;
5037 if (*ascale != *bscale) {
5040 DWORD * digitchosen;
5041 unsigned int nchosen;
5045 if (*ascale < *bscale) {
5046 targetscale = *ascale;
5047 scalechosen = bscale;
5051 targetscale = *bscale;
5052 scalechosen = ascale;
5060 while (*scalechosen > targetscale) {
5069 if (*ascale != *bscale) {
5070 DWORD * digitchosen;
5071 unsigned int nchosen;
5076 if (*ascale > *bscale) {
5077 targetscale = *ascale;
5078 scalechosen = bscale;
5082 targetscale = *bscale;
5083 scalechosen = ascale;
5093 while (*scalechosen < targetscale &&
t[nchosen] == 0) {
5095 if (
t[nchosen] == 0) {
5103 if (*ascale != *bscale) {
5106 DWORD * digitchosen;
5107 unsigned int nchosen;
5111 if (*ascale < *bscale) {
5112 targetscale = *ascale;
5113 scalechosen = bscale;
5117 targetscale = *bscale;
5118 scalechosen = ascale;
5126 while (*scalechosen > targetscale) {
5143 while (!underflow) {
5183 int quotientscale, remainderscale, tempquotientscale;
5184 DWORD remainderplusquotient[8];
5187 quotientscale = remainderscale = (
int)dividend->
scale - (
int)
divisor->scale;
5188 tempquotientscale = quotientscale;
5207 memset(remainderplusquotient, 0,
sizeof(remainderplusquotient));
5213 if (round_remainder) {
5214 if(remainderplusquotient[4] >= 5){