BYTE rgb[1024];
/* Use VarParseNumFromStr/VarNumFromParseNum as MSDN indicates */
- np.cDig = sizeof(rgb) / sizeof(BYTE);
+ np.cDig = ARRAY_SIZE(rgb);
np.dwInFlags = NUMPRS_STD;
hRet = VarParseNumFromStr(pStrIn, lcid, ulFlags, &np, rgb);
* Success: S_OK.
* Failure: DISP_E_OVERFLOW, if the value will not fit in the destination
*/
-HRESULT WINAPI VarCyAdd(const CY cyLeft, const CY cyRight, CY* pCyOut)
+HRESULT WINAPI VarCyAdd(CY cyLeft, CY cyRight, CY* pCyOut)
{
double l,r;
_VarR8FromCy(cyLeft, &l);
* Success: S_OK.
* Failure: DISP_E_OVERFLOW, if the value will not fit in the destination
*/
-HRESULT WINAPI VarCyMul(const CY cyLeft, CY cyRight, CY* pCyOut)
+HRESULT WINAPI VarCyMul(CY cyLeft, CY cyRight, CY* pCyOut)
{
double l,r;
_VarR8FromCy(cyLeft, &l);
* Success: S_OK.
* Failure: DISP_E_OVERFLOW, if the value will not fit in the destination
*/
-HRESULT WINAPI VarCyMulI4(const CY cyLeft, LONG lRight, CY* pCyOut)
+HRESULT WINAPI VarCyMulI4(CY cyLeft, LONG lRight, CY* pCyOut)
{
double d;
* Success: S_OK.
* Failure: DISP_E_OVERFLOW, if the value will not fit in the destination
*/
-HRESULT WINAPI VarCySub(const CY cyLeft, const CY cyRight, CY* pCyOut)
+HRESULT WINAPI VarCySub(CY cyLeft, CY cyRight, CY* pCyOut)
{
double l,r;
_VarR8FromCy(cyLeft, &l);
* Success: S_OK. pCyOut contains the absolute value.
* Failure: DISP_E_OVERFLOW, if the value will not fit in the destination
*/
-HRESULT WINAPI VarCyAbs(const CY cyIn, CY* pCyOut)
+HRESULT WINAPI VarCyAbs(CY cyIn, CY* pCyOut)
{
if (cyIn.s.Hi == (int)0x80000000 && !cyIn.s.Lo)
return DISP_E_OVERFLOW;
* - The difference between this function and VarCyInt() is that VarCyInt() rounds
* negative numbers away from 0, while this function rounds them towards zero.
*/
-HRESULT WINAPI VarCyFix(const CY cyIn, CY* pCyOut)
+HRESULT WINAPI VarCyFix(CY cyIn, CY* pCyOut)
{
pCyOut->int64 = cyIn.int64 / CY_MULTIPLIER;
pCyOut->int64 *= CY_MULTIPLIER;
* - The difference between this function and VarCyFix() is that VarCyFix() rounds
* negative numbers towards 0, while this function rounds them away from zero.
*/
-HRESULT WINAPI VarCyInt(const CY cyIn, CY* pCyOut)
+HRESULT WINAPI VarCyInt(CY cyIn, CY* pCyOut)
{
pCyOut->int64 = cyIn.int64 / CY_MULTIPLIER;
pCyOut->int64 *= CY_MULTIPLIER;
* Success: S_OK.
* Failure: DISP_E_OVERFLOW, if the value will not fit in the destination
*/
-HRESULT WINAPI VarCyNeg(const CY cyIn, CY* pCyOut)
+HRESULT WINAPI VarCyNeg(CY cyIn, CY* pCyOut)
{
if (cyIn.s.Hi == (int)0x80000000 && !cyIn.s.Lo)
return DISP_E_OVERFLOW;
* Success: S_OK.
* Failure: E_INVALIDARG, if cDecimals is less than 0.
*/
-HRESULT WINAPI VarCyRound(const CY cyIn, int cDecimals, CY* pCyOut)
+HRESULT WINAPI VarCyRound(CY cyIn, int cDecimals, CY* pCyOut)
{
if (cDecimals < 0)
return E_INVALIDARG;
* compare is less, equal or greater than source respectively.
* Failure: DISP_E_OVERFLOW, if overflow occurs during the comparison
*/
-HRESULT WINAPI VarCyCmp(const CY cyLeft, const CY cyRight)
+HRESULT WINAPI VarCyCmp(CY cyLeft, CY cyRight)
{
HRESULT hRet;
CY result;
* less than, equal to or greater than cyLeft respectively.
* Failure: DISP_E_OVERFLOW, if overflow occurs during the comparison
*/
-HRESULT WINAPI VarCyCmpR8(const CY cyLeft, double dblRight)
+HRESULT WINAPI VarCyCmpR8(CY cyLeft, double dblRight)
{
HRESULT hRet;
CY cyRight;
* Success: S_OK.
* Failure: DISP_E_OVERFLOW, if the value will not fit in the destination
*/
-HRESULT WINAPI VarCyMulI8(const CY cyLeft, LONG64 llRight, CY* pCyOut)
+HRESULT WINAPI VarCyMulI8(CY cyLeft, LONG64 llRight, CY* pCyOut)
{
double d;
di.scale -= i;
remainder = 0;
- while (i-- > 0 && !VARIANT_int_iszero(di.bitsnum, sizeof(di.bitsnum)/sizeof(DWORD)))
+ while (i-- > 0 && !VARIANT_int_iszero(di.bitsnum, ARRAY_SIZE(di.bitsnum)))
{
- remainder = VARIANT_int_divbychar(di.bitsnum, sizeof(di.bitsnum)/sizeof(DWORD), 10);
+ remainder = VARIANT_int_divbychar(di.bitsnum, ARRAY_SIZE(di.bitsnum), 10);
if (remainder > 0) WARN("losing significant digits (remainder %u)...\n", remainder);
}
/* round up the result - native oleaut32 does this */
if (remainder >= 5) {
- for (remainder = 1, i = 0; i < sizeof(di.bitsnum)/sizeof(DWORD) && remainder; i++) {
+ for (remainder = 1, i = 0; i < ARRAY_SIZE(di.bitsnum) && remainder; i++) {
ULONGLONG digit = di.bitsnum[i] + 1;
remainder = (digit > 0xFFFFFFFF) ? 1 : 0;
di.bitsnum[i] = digit & 0xFFFFFFFF;
memset(running, 0, sizeof(running));
/* count number of leading zero-bytes in operand A */
- for (mulstart = sizeof(a->bitsnum)/sizeof(DWORD) - 1; mulstart >= 0 && !a->bitsnum[mulstart]; mulstart--);
+ for (mulstart = ARRAY_SIZE(a->bitsnum) - 1; mulstart >= 0 && !a->bitsnum[mulstart]; mulstart--);
if (mulstart < 0) {
/* result is 0, because operand A is 0 */
result->scale = 0;
ULONG iOverflowMul;
int iB;
- for (iOverflowMul = 0, iB = 0; iB < sizeof(b->bitsnum)/sizeof(DWORD); iB++) {
+ for (iOverflowMul = 0, iB = 0; iB < ARRAY_SIZE(b->bitsnum); iB++) {
ULONG iRV;
int iR;
This operation *will* lose significant digits of the result because
all the factors of 10 were consumed by the previous operation.
*/
- while (result->scale > 0 && !VARIANT_int_iszero(
- running + sizeof(result->bitsnum) / sizeof(DWORD),
- (sizeof(running) - sizeof(result->bitsnum)) / sizeof(DWORD))) {
-
- remainder = VARIANT_int_divbychar(running, sizeof(running) / sizeof(DWORD), 10);
+ while (result->scale > 0 && !VARIANT_int_iszero(running + ARRAY_SIZE(result->bitsnum),
+ ARRAY_SIZE(running) - ARRAY_SIZE(result->bitsnum))) {
+
+ remainder = VARIANT_int_divbychar(running, ARRAY_SIZE(running), 10);
if (remainder > 0) WARN("losing significant digits (remainder %u)...\n", remainder);
result->scale--;
}
/* round up the result - native oleaut32 does this */
if (remainder >= 5) {
unsigned int i;
- for (remainder = 1, i = 0; i < sizeof(running)/sizeof(DWORD) && remainder; i++) {
+ for (remainder = 1, i = 0; i < ARRAY_SIZE(running) && remainder; i++) {
ULONGLONG digit = running[i] + 1;
remainder = (digit > 0xFFFFFFFF) ? 1 : 0;
running[i] = digit & 0xFFFFFFFF;
/* Signal overflow if scale == 0 and 256-bit result still overflows,
and copy result bits into result structure
*/
- r_overflow = !VARIANT_int_iszero(
- running + sizeof(result->bitsnum)/sizeof(DWORD),
- (sizeof(running) - sizeof(result->bitsnum))/sizeof(DWORD));
+ r_overflow = !VARIANT_int_iszero(running + ARRAY_SIZE(result->bitsnum),
+ ARRAY_SIZE(running) - ARRAY_SIZE(result->bitsnum));
memcpy(result->bitsnum, running, sizeof(result->bitsnum));
}
return r_overflow;
unsigned int i;
/* place negative sign */
- if (!VARIANT_int_iszero(a->bitsnum, sizeof(a->bitsnum) / sizeof(DWORD)) && a->sign) {
+ if (!VARIANT_int_iszero(a->bitsnum, ARRAY_SIZE(a->bitsnum)) && a->sign) {
if (n > 0) {
*s++ = '-';
n--;
i = 0;
memcpy(quotient, a->bitsnum, sizeof(a->bitsnum));
- while (!overflow && !VARIANT_int_iszero(quotient, sizeof(quotient) / sizeof(DWORD))) {
- remainder = VARIANT_int_divbychar(quotient, sizeof(quotient) / sizeof(DWORD), 10);
+ while (!overflow && !VARIANT_int_iszero(quotient, ARRAY_SIZE(quotient))) {
+ remainder = VARIANT_int_divbychar(quotient, ARRAY_SIZE(quotient), 10);
if (i + 2 > n) {
overflow = TRUE;
} else {
}
}
- if (!overflow && !VARIANT_int_iszero(a->bitsnum, sizeof(a->bitsnum) / sizeof(DWORD))) {
+ if (!overflow && !VARIANT_int_iszero(a->bitsnum, ARRAY_SIZE(a->bitsnum))) {
/* reverse order of digits */
WCHAR * x = s; WCHAR * y = s + i - 1;
{
HRESULT r_overflow = S_OK;
- if (VARIANT_int_iszero(divisor->bitsnum, sizeof(divisor->bitsnum)/sizeof(DWORD))) {
+ if (VARIANT_int_iszero(divisor->bitsnum, ARRAY_SIZE(divisor->bitsnum))) {
/* division by 0 */
r_overflow = DISP_E_DIVBYZERO;
- } else if (VARIANT_int_iszero(dividend->bitsnum, sizeof(dividend->bitsnum)/sizeof(DWORD))) {
+ } else if (VARIANT_int_iszero(dividend->bitsnum, ARRAY_SIZE(dividend->bitsnum))) {
VARIANT_DI_clear(quotient);
} else {
int quotientscale, remainderscale, tempquotientscale;
memset(remainderplusquotient, 0, sizeof(remainderplusquotient));
memcpy(remainderplusquotient, dividend->bitsnum, sizeof(dividend->bitsnum));
do {
- VARIANT_int_div(
- remainderplusquotient, 4,
- divisor->bitsnum, sizeof(divisor->bitsnum)/sizeof(DWORD));
- underflow = VARIANT_int_addlossy(
- quotient->bitsnum, "ientscale, sizeof(quotient->bitsnum) / sizeof(DWORD),
- remainderplusquotient, &tempquotientscale, 4);
+ VARIANT_int_div(remainderplusquotient, 4, divisor->bitsnum, ARRAY_SIZE(divisor->bitsnum));
+ underflow = VARIANT_int_addlossy( quotient->bitsnum, "ientscale,
+ ARRAY_SIZE(quotient->bitsnum), remainderplusquotient, &tempquotientscale, 4);
if (round_remainder) {
if(remainderplusquotient[4] >= 5){
unsigned int i;
unsigned char remainder = 1;
- for (i = 0; i < sizeof(quotient->bitsnum) / sizeof(DWORD) && remainder; i++) {
+ for (i = 0; i < ARRAY_SIZE(quotient->bitsnum) && remainder; i++) {
ULONGLONG digit = quotient->bitsnum[i] + 1;
remainder = (digit > 0xFFFFFFFF) ? 1 : 0;
quotient->bitsnum[i] = digit & 0xFFFFFFFF;
while (r_overflow == S_OK && quotientscale < 0) {
memset(remainderplusquotient, 0, sizeof(remainderplusquotient));
memcpy(remainderplusquotient, quotient->bitsnum, sizeof(quotient->bitsnum));
- VARIANT_int_mulbychar(remainderplusquotient, sizeof(remainderplusquotient)/sizeof(DWORD), 10);
- if (VARIANT_int_iszero(remainderplusquotient + sizeof(quotient->bitsnum)/sizeof(DWORD),
- (sizeof(remainderplusquotient) - sizeof(quotient->bitsnum))/sizeof(DWORD))) {
+ VARIANT_int_mulbychar(remainderplusquotient, ARRAY_SIZE(remainderplusquotient), 10);
+ if (VARIANT_int_iszero(remainderplusquotient + ARRAY_SIZE(quotient->bitsnum),
+ ARRAY_SIZE(remainderplusquotient) - ARRAY_SIZE(quotient->bitsnum))) {
quotientscale++;
memcpy(quotient->bitsnum, remainderplusquotient, sizeof(quotient->bitsnum));
} else r_overflow = DISP_E_OVERFLOW;
WARN("result scale is %u, scaling (with loss of significant digits)...\n",
di_result.scale);
while (di_result.scale > DEC_MAX_SCALE &&
- !VARIANT_int_iszero(di_result.bitsnum, sizeof(di_result.bitsnum) / sizeof(DWORD)))
+ !VARIANT_int_iszero(di_result.bitsnum, ARRAY_SIZE(di_result.bitsnum)))
{
- remainder = VARIANT_int_divbychar(di_result.bitsnum, sizeof(di_result.bitsnum) / sizeof(DWORD), 10);
+ remainder = VARIANT_int_divbychar(di_result.bitsnum, ARRAY_SIZE(di_result.bitsnum), 10);
di_result.scale--;
}
if (di_result.scale > DEC_MAX_SCALE)
else if (remainder >= 5) /* round up result - native oleaut32 does this */
{
unsigned int i;
- for (remainder = 1, i = 0; i < sizeof(di_result.bitsnum) / sizeof(DWORD) && remainder; i++) {
+ for (remainder = 1, i = 0; i < ARRAY_SIZE(di_result.bitsnum) && remainder; i++) {
ULONGLONG digit = di_result.bitsnum[i] + 1;
remainder = (digit > 0xFFFFFFFF) ? 1 : 0;
di_result.bitsnum[i] = digit & 0xFFFFFFFF;
WARN("result scale is %u, scaling (with loss of significant digits)...\n",
di_result.scale);
while (di_result.scale > DEC_MAX_SCALE &&
- !VARIANT_int_iszero(di_result.bitsnum, sizeof(di_result.bitsnum)/sizeof(DWORD)))
+ !VARIANT_int_iszero(di_result.bitsnum, ARRAY_SIZE(di_result.bitsnum)))
{
- VARIANT_int_divbychar(di_result.bitsnum, sizeof(di_result.bitsnum)/sizeof(DWORD), 10);
+ VARIANT_int_divbychar(di_result.bitsnum, ARRAY_SIZE(di_result.bitsnum), 10);
di_result.scale--;
}
if (di_result.scale > DEC_MAX_SCALE)
{
/* Format the number for the locale */
szConverted[0] = '\0';
- GetNumberFormatW(lcid,
- dwFlags & LOCALE_NOUSEROVERRIDE,
- szOut, NULL, szConverted, sizeof(szConverted)/sizeof(WCHAR));
+ GetNumberFormatW(lcid, dwFlags & LOCALE_NOUSEROVERRIDE,
+ szOut, NULL, szConverted, ARRAY_SIZE(szConverted));
szOut = szConverted;
}
return SysAllocStringByteLen((LPCSTR)szOut, strlenW(szOut) * sizeof(WCHAR));
/* Create a (possibly localised) BSTR from a UI8 and sign */
static HRESULT VARIANT_BstrFromUInt(ULONG64 ulVal, LCID lcid, DWORD dwFlags, BSTR *pbstrOut)
{
- WCHAR szBuff[64], *szOut = szBuff + sizeof(szBuff)/sizeof(WCHAR) - 1;
+ WCHAR szBuff[64], *szOut = szBuff + ARRAY_SIZE(szBuff) - 1;
if (!pbstrOut)
return E_INVALIDARG;
if (lIn < 0)
{
- ul64 = (ULONG)-lIn;
+ ul64 = -(LONG64)lIn;
dwFlags |= VAR_NEGATIVE;
}
return VARIANT_BstrFromUInt(ul64, lcid, dwFlags, pbstrOut);
appropriate NUMBERFMTW structure to do the job via GetNumberFormatW().
*/
GetLocaleInfoW(lcid, LOCALE_SDECIMAL | (dwFlags & LOCALE_NOUSEROVERRIDE),
- lpDecimalSep, sizeof(lpDecimalSep) / sizeof(WCHAR));
+ lpDecimalSep, ARRAY_SIZE(lpDecimalSep));
if (lpDecimalSep[0] == '.' && lpDecimalSep[1] == '\0')
{
/* locale is compatible with English - return original string */
if (p) minFormat.NumDigits = strlenW(p + 1);
numbuff[0] = '\0';
- if (!GetNumberFormatW(lcid, 0, buff, &minFormat, numbuff, sizeof(numbuff) / sizeof(WCHAR)))
+ if (!GetNumberFormatW(lcid, 0, buff, &minFormat, numbuff, ARRAY_SIZE(numbuff)))
{
WARN("GetNumberFormatW() failed, returning raw number string instead\n");
bstrOut = SysAllocString(buff);
*/
if (buff[0] == '-')
{
- const WCHAR szAccept[] = {'0', '.', '\0'};
+ static const WCHAR szAccept[] = {'0', '.', '\0'};
if (strlenW(buff + 1) == strspnW(buff + 1, szAccept))
{ buff[0] = '0'; buff[1] = '\0'; }
}
/* Format the number for the locale */
numbuff[0] = '\0';
GetNumberFormatW(lcid, dwFlags & LOCALE_NOUSEROVERRIDE,
- buff, NULL, numbuff, sizeof(numbuff) / sizeof(WCHAR));
+ buff, NULL, numbuff, ARRAY_SIZE(numbuff));
TRACE("created NLS string %s\n", debugstr_w(numbuff));
*pbstrOut = SysAllocString(numbuff);
}
VARIANT_int_add(decVal.bitsnum, 3, &one, 1);
}
decVal.bitsnum[2] = 0;
- VARIANT_DI_tostringW(&decVal, buff, sizeof(buff)/sizeof(buff[0]));
+ VARIANT_DI_tostringW(&decVal, buff, ARRAY_SIZE(buff));
if (dwFlags & LOCALE_USE_NLS)
{
/* Format the currency for the locale */
cybuff[0] = '\0';
GetCurrencyFormatW(lcid, dwFlags & LOCALE_NOUSEROVERRIDE,
- buff, NULL, cybuff, sizeof(cybuff) / sizeof(WCHAR));
+ buff, NULL, cybuff, ARRAY_SIZE(cybuff));
*pbstrOut = SysAllocString(cybuff);
}
else
if (dwFlags & VAR_TIMEVALUEONLY)
date[0] = '\0';
else
- if (!GetLocaleInfoW(lcid, LOCALE_SSHORTDATE, fmt_buff, sizeof(fmt_buff)/sizeof(WCHAR)) ||
- !get_date_format(lcid, dwFlags, &st, fmt_buff, date, sizeof(date)/sizeof(WCHAR)))
+ if (!GetLocaleInfoW(lcid, LOCALE_SSHORTDATE, fmt_buff, ARRAY_SIZE(fmt_buff)) ||
+ !get_date_format(lcid, dwFlags, &st, fmt_buff, date, ARRAY_SIZE(date)))
return E_INVALIDARG;
if (!(dwFlags & VAR_DATEVALUEONLY))
time = date + strlenW(date);
if (time != date)
*time++ = ' ';
- if (!GetTimeFormatW(lcid, dwFormatFlags, &st, NULL, time,
- sizeof(date)/sizeof(WCHAR)-(time-date)))
+ if (!GetTimeFormatW(lcid, dwFormatFlags, &st, NULL, time, ARRAY_SIZE(date)-(time-date)))
return E_INVALIDARG;
}
/* Format the number for the locale */
numbuff[0] = '\0';
GetNumberFormatW(lcid, dwFlags & LOCALE_NOUSEROVERRIDE,
- buff, NULL, numbuff, sizeof(numbuff) / sizeof(WCHAR));
+ buff, NULL, numbuff, ARRAY_SIZE(numbuff));
TRACE("created NLS string %s\n", debugstr_w(numbuff));
*pbstrOut = SysAllocString(numbuff);
}
1,2,3,4,5,6,7,8,9,10,11,12,13
};
unsigned int i;
- BSTR tokens[sizeof(ParseDateTokens)/sizeof(ParseDateTokens[0])];
+ BSTR tokens[ARRAY_SIZE(ParseDateTokens)];
DATEPARSE dp;
DWORD dwDateSeps = 0, iDate = 0;
HRESULT hRet = S_OK;
TRACE("iDate is %d\n", iDate);
/* Get the month/day/am/pm tokens for this locale */
- for (i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++)
+ for (i = 0; i < ARRAY_SIZE(tokens); i++)
{
WCHAR buff[128];
LCTYPE lctype = ParseDateTokens[i] | (dwFlags & LOCALE_NOUSEROVERRIDE);
* GetAltMonthNames(). We should really cache these strings too.
*/
buff[0] = '\0';
- GetLocaleInfoW(lcid, lctype, buff, sizeof(buff)/sizeof(WCHAR));
+ GetLocaleInfoW(lcid, lctype, buff, ARRAY_SIZE(buff));
tokens[i] = SysAllocString(buff);
TRACE("token %d is %s\n", i, debugstr_w(tokens[i]));
}
{
BOOL bFound = FALSE;
- for (i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++)
+ for (i = 0; i < ARRAY_SIZE(tokens); i++)
{
DWORD dwLen = strlenW(tokens[i]);
if (dwLen && !strncmpiW(strIn, tokens[i], dwLen))
}
}
- for (i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++)
+ for (i = 0; i < ARRAY_SIZE(tokens); i++)
SysFreeString(tokens[i]);
return hRet;
}