8000 Merge pull request #10416 from charris/fix-sign-compare-dragon4 · numpy/numpy@a6ee59a · GitHub
[go: up one dir, main page]

Skip to content

Commit a6ee59a

Browse files
authored
Merge pull request #10416 from charris/fix-sign-compare-dragon4
MAINT: Fix sign-compare warnings in dragon4.c.
2 parents f96a528 + 21d8207 commit a6ee59a

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

numpy/core/src/multiarray/dragon4.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ FormatPositional(char *buffer, npy_uint32 bufferSize, npy_uint64 mantissa,
15901590
npy_int32 printExponent;
15911591
npy_int32 numDigits, numWholeDigits, has_sign=0;
15921592

1593-
npy_int32 maxPrintLen = bufferSize - 1, pos = 0;
1593+
npy_int32 maxPrintLen = (npy_int32)bufferSize - 1, pos = 0;
15941594

15951595
/* track the # of digits past the decimal point that have been printed */
15961596
npy_int32 numFractionDigits = 0;
@@ -1637,11 +1637,11 @@ FormatPositional(char *buffer, npy_uint32 bufferSize, npy_uint64 mantissa,
16371637
}
16381638
}
16391639
/* insert the decimal point prior to the fraction */
1640-
else if (numDigits > (npy_uint32)numWholeDigits) {
1641-
npy_uint32 maxFractionDigits;
1640+
else if (numDigits > numWholeDigits) {
1641+
npy_int32 maxFractionDigits;
16421642

16431643
numFractionDigits = numDigits - numWholeDigits;
1644-
maxFractionDigits = maxPrintLen - numWholeDigits -1-pos;
1644+
maxFractionDigits = maxPrintLen - numWholeDigits - 1 - pos;
16451645
if (numFractionDigits > maxFractionDigits) {
16461646
numFractionDigits = maxFractionDigits;
16471647
}
@@ -1656,19 +1656,20 @@ FormatPositional(char *buffer, npy_uint32 bufferSize, npy_uint64 mantissa,
16561656
}
16571657
else {
16581658
/* shift out the fraction to make room for the leading zeros */
1659-
npy_uint32 numFractionZeros = 0;
1659+
npy_int32 numFractionZeros = 0;
16601660
if (pos + 2 < maxPrintLen) {
1661-
npy_uint32 maxFractionZeros, digitsStartIdx, maxFractionDigits, i;
1661+
npy_int32 maxFractionZeros, digitsStartIdx, maxFractionDigits, i;
16621662

16631663
maxFractionZeros = maxPrintLen - 2 - pos;
1664-
numFractionZeros = (npy_uint32)-printExponent - 1;
1664+
numFractionZeros = -(printExponent + 1);
16651665
if (numFractionZeros > maxFractionZeros) {
16661666
numFractionZeros = maxFractionZeros;
16671667
}
16681668

16691669
digitsStartIdx = 2 + numFractionZeros;
16701670

1671-
/* shift the significant digits right such that there is room for
1671+
/*
1672+
* shift the significant digits right such that there is room for
16721673
* leading zeros
16731674
*/
16741675
numFractionDigits = numDigits;
@@ -1719,10 +1720,10 @@ FormatPositional(char *buffer, npy_uint32 bufferSize, npy_uint64 mantissa,
17191720
}
17201721
else if (trim_mode == TrimMode_None &&
17211722
digit_mode != DigitMode_Unique &&
1722-
precision > (npy_int32)numFractionDigits && pos < maxPrintLen) {
1723+
precision > numFractionDigits && pos < maxPrintLen) {
17231724
/* add trailing zeros up to precision length */
17241725
/* compute the number of trailing zeros needed */
1725-
npy_uint32 count = precision - numFractionDigits;
1726+
npy_int32 count = precision - numFractionDigits;
17261727
if (pos + count > maxPrintLen) {
17271728
count = maxPrintLen - pos;
17281729
}
@@ -1751,7 +1752,7 @@ FormatPositional(char *buffer, npy_uint32 bufferSize, npy_uint64 mantissa,
17511752

17521753
/* add any whitespace padding to right side */
17531754
if (digits_right >= numFractionDigits) {
1754-
npy_uint32 count = digits_right - numFractionDigits;
1755+
npy_int32 count = digits_right - numFractionDigits;
17551756

17561757
/* in trim_mode DptZeros, if right padding, add a space for the . */
17571758
if (trim_mode == TrimMode_DptZeros && numFractionDigits == 0
@@ -1769,8 +1770,8 @@ FormatPositional(char *buffer, npy_uint32 bufferSize, npy_uint64 mantissa,
17691770
}
17701771
/* add any whitespace padding to left side */
17711772
if (digits_left > numWholeDigits + has_sign) {
1772-
npy_uint32 shift = digits_left - (numWholeDigits + has_sign);
1773-
npy_uint32 count = pos;
1773+
npy_int32 shift = digits_left - (numWholeDigits + has_sign);
1774+
npy_int32 count = pos;
17741775

17751776
if (count + shift > maxPrintLen){
17761777
count = maxPrintLen - shift;
@@ -1781,7 +1782,7 @@ FormatPositional(char *buffer, npy_uint32 bufferSize, npy_uint64 mantissa,
17811782
}
17821783
pos = shift + count;
17831784
for ( ; shift > 0; shift--) {
1784-
buffer[shift-1] = ' ';
1785+
buffer[shift - 1] = ' ';
17851786
}
17861787
}
17871788

@@ -1871,7 +1872,8 @@ FormatScientific (char *buffer, npy_uint32 bufferSize, npy_uint64 mantissa,
18711872
/* insert the decimal point prior to the fractional number */
18721873
numFractionDigits = numDigits-1;
18731874
if (numFractionDigits > 0 && bufferSize > 1) {
1874-
npy_uint32 maxFractionDigits = bufferSize-2;
1875+
npy_int32 maxFractionDigits = (npy_int32)bufferSize - 2;
1876+
18751877
if (numFractionDigits > maxFractionDigits) {
18761878
numFractionDigits = maxFractionDigits;
18771879
}
@@ -1905,9 +1907,10 @@ FormatScientific (char *buffer, npy_uint32 bufferSize, npy_uint64 mantissa,
19051907
if (precision > (npy_int32)numFractionDigits) {
19061908
char *pEnd;
19071909
/* compute the number of trailing zeros needed */
1908-
npy_uint32 numZeros = (precision - numFractionDigits);
1909-
if (numZeros > bufferSize-1) {
1910-
numZeros = bufferSize-1;
1910+
npy_int32 numZeros = (precision - numFractionDigits);
1911+
1912+
if (numZeros > (npy_int32)bufferSize - 1) {
1913+
numZeros = (npy_int32)bufferSize - 1;
19111914
}
19121915

19131916
for (pEnd = pCurOut + numZeros; pCurOut < pEnd; ++pCurOut) {
@@ -1941,7 +1944,7 @@ FormatScientific (char *buffer, npy_uint32 bufferSize, npy_uint64 mantissa,
19411944
/* print the exponent into a local buffer and copy into output buffer */
19421945
if (bufferSize > 1) {
19431946
char exponentBuffer[7];
1944-
npy_uint32 digits[5];
1947+
npy_int32 digits[5];
19451948
npy_int32 i, exp_size, count;
19461949

19471950
if (exp_digits > 5) {
@@ -1978,8 +1981,8 @@ FormatScientific (char *buffer, npy_uint32 bufferSize, npy_uint64 mantissa,
19781981

19791982
/* copy the exponent buffer into the output */
19801983
count = exp_size + 2;
1981-
if (count > bufferSize-1) {
1982-
count = bufferSize-1;
1984+
if (count > (npy_int32)bufferSize - 1) {
1985+
count = (npy_int32)bufferSize - 1;
19831986
}
19841987
memcpy(pCurOut, exponentBuffer, count);
19851988
pCurOut += count;

0 commit comments

Comments
 (0)
0