Merge initializers and assignments (#1088)
This commit is contained in:
@@ -303,17 +303,13 @@ PRAT numtorat(_In_ PNUMBER pin, uint32_t radix)
|
||||
PNUMBER nRadixxtonum(_In_ PNUMBER a, uint32_t radix, int32_t precision)
|
||||
|
||||
{
|
||||
uint32_t bitmask;
|
||||
uint32_t cdigits;
|
||||
MANTTYPE* ptr;
|
||||
|
||||
PNUMBER sum = i32tonum(0, radix);
|
||||
PNUMBER powofnRadix = i32tonum(BASEX, radix);
|
||||
|
||||
// A large penalty is paid for conversion of digits no one will see anyway.
|
||||
// limit the digits to the minimum of the existing precision or the
|
||||
// requested precision.
|
||||
cdigits = precision + 1;
|
||||
uint32_t cdigits = precision + 1;
|
||||
if (cdigits > (uint32_t)a->cdigit)
|
||||
{
|
||||
cdigits = (uint32_t)a->cdigit;
|
||||
@@ -323,10 +319,10 @@ PNUMBER nRadixxtonum(_In_ PNUMBER a, uint32_t radix, int32_t precision)
|
||||
numpowi32(&powofnRadix, a->exp + (a->cdigit - cdigits), radix, precision);
|
||||
|
||||
// Loop over all the relative digits from MSD to LSD
|
||||
for (ptr = &(a->mant[a->cdigit - 1]); cdigits > 0; ptr--, cdigits--)
|
||||
for (MANTTYPE* ptr = &(a->mant[a->cdigit - 1]); cdigits > 0; ptr--, cdigits--)
|
||||
{
|
||||
// Loop over all the bits from MSB to LSB
|
||||
for (bitmask = BASEX / 2; bitmask > 0; bitmask /= 2)
|
||||
for (uint32_t bitmask = BASEX / 2; bitmask > 0; bitmask /= 2)
|
||||
{
|
||||
addnum(&sum, sum, radix);
|
||||
if (*ptr & bitmask)
|
||||
@@ -368,9 +364,7 @@ PNUMBER numtonRadixx(_In_ PNUMBER a, uint32_t radix)
|
||||
ptrdigit += a->cdigit - 1;
|
||||
|
||||
PNUMBER thisdigit = nullptr; // thisdigit holds the current digit of a
|
||||
// being summed into result.
|
||||
int32_t idigit; // idigit is the iterate of digits in a.
|
||||
for (idigit = 0; idigit < a->cdigit; idigit++)
|
||||
for (int32_t idigit = 0; idigit < a->cdigit; idigit++)
|
||||
{
|
||||
mulnumx(&pnumret, num_radix);
|
||||
// WARNING:
|
||||
@@ -628,11 +622,10 @@ PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precis
|
||||
MANTTYPE* pmant = pnumret->mant + numberString.length() - 1;
|
||||
|
||||
uint8_t state = START; // state is the state of the input state machine.
|
||||
wchar_t curChar;
|
||||
for (const auto& c : numberString)
|
||||
{
|
||||
// If the character is the decimal separator, use L'.' for the purposes of the state machine.
|
||||
curChar = (c == g_decimalSeparator ? L'.' : c);
|
||||
wchar_t curChar = (c == g_decimalSeparator ? L'.' : c);
|
||||
|
||||
// Switch states based on the character we encountered
|
||||
switch (curChar)
|
||||
@@ -1032,13 +1025,10 @@ int32_t numtoi32(_In_ PNUMBER pnum, uint32_t radix)
|
||||
|
||||
bool stripzeroesnum(_Inout_ PNUMBER pnum, int32_t starting)
|
||||
{
|
||||
MANTTYPE* pmant;
|
||||
int32_t cdigits;
|
||||
bool fstrip = false;
|
||||
|
||||
// point pmant to the LeastCalculatedDigit
|
||||
pmant = pnum->mant;
|
||||
cdigits = pnum->cdigit;
|
||||
MANTTYPE* pmant = pnum->mant;
|
||||
int32_t cdigits = pnum->cdigit;
|
||||
// point pmant to the LSD
|
||||
if (cdigits > starting)
|
||||
{
|
||||
|
@@ -63,7 +63,6 @@ void exprat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
|
||||
{
|
||||
PRAT pwr = nullptr;
|
||||
PRAT pint = nullptr;
|
||||
int32_t intpwr;
|
||||
|
||||
if (rat_gt(*px, rat_max_exp, precision) || rat_lt(*px, rat_min_exp, precision))
|
||||
{
|
||||
@@ -76,7 +75,7 @@ void exprat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
|
||||
|
||||
intrat(&pint, radix, precision);
|
||||
|
||||
intpwr = rattoi32(pint, radix, precision);
|
||||
const int32_t intpwr = rattoi32(pint, radix, precision);
|
||||
ratpowi32(&pwr, intpwr, precision);
|
||||
|
||||
subrat(px, pint, precision);
|
||||
@@ -153,7 +152,6 @@ void _lograt(PRAT* px, int32_t precision)
|
||||
void lograt(_Inout_ PRAT* px, int32_t precision)
|
||||
|
||||
{
|
||||
bool fneglog;
|
||||
PRAT pwr = nullptr; // pwr is the large scaling factor.
|
||||
PRAT offset = nullptr; // offset is the incremental scaling factor.
|
||||
|
||||
@@ -164,12 +162,10 @@ void lograt(_Inout_ PRAT* px, int32_t precision)
|
||||
}
|
||||
|
||||
// Get number > 1, for scaling
|
||||
fneglog = rat_lt(*px, rat_one, precision);
|
||||
bool fneglog = rat_lt(*px, rat_one, precision);
|
||||
if (fneglog)
|
||||
{
|
||||
// WARNING: This is equivalent to doing *px = 1 / *px
|
||||
PNUMBER pnumtemp = nullptr;
|
||||
pnumtemp = (*px)->pp;
|
||||
PNUMBER pnumtemp = (*px)->pp;
|
||||
(*px)->pp = (*px)->pq;
|
||||
(*px)->pq = pnumtemp;
|
||||
}
|
||||
@@ -178,10 +174,7 @@ void lograt(_Inout_ PRAT* px, int32_t precision)
|
||||
// log(x*2^(BASEXPWR*k)) = BASEXPWR*k*log(2)+log(x)
|
||||
if (LOGRAT2(*px) > 1)
|
||||
{
|
||||
// Take advantage of px's base BASEX to scale quickly down to
|
||||
// a reasonable range.
|
||||
int32_t intpwr;
|
||||
intpwr = LOGRAT2(*px) - 1;
|
||||
const int32_t intpwr = LOGRAT2(*px) - 1;
|
||||
(*px)->pq->exp += intpwr;
|
||||
pwr = i32torat(intpwr * BASEXPWR);
|
||||
mulrat(&pwr, ln_two, precision);
|
||||
@@ -448,10 +441,9 @@ void powratcomp(_Inout_ PRAT* px, _In_ PRAT y, uint32_t radix, int32_t precision
|
||||
{
|
||||
// If power is an integer let ratpowi32 deal with it.
|
||||
PRAT iy = nullptr;
|
||||
int32_t inty;
|
||||
DUPRAT(iy, y);
|
||||
subrat(&iy, podd, precision);
|
||||
inty = rattoi32(iy, radix, precision);
|
||||
int32_t inty = rattoi32(iy, radix, precision);
|
||||
|
||||
PRAT plnx = nullptr;
|
||||
DUPRAT(plnx, *px);
|
||||
|
@@ -67,13 +67,9 @@ void _gamma(PRAT* pn, uint32_t radix, int32_t precision)
|
||||
PRAT sum = nullptr;
|
||||
PRAT err = nullptr;
|
||||
PRAT mpy = nullptr;
|
||||
PRAT ratprec = nullptr;
|
||||
PRAT ratRadix = nullptr;
|
||||
int32_t oldprec;
|
||||
|
||||
// Set up constants and initial conditions
|
||||
oldprec = precision;
|
||||
ratprec = i32torat(oldprec);
|
||||
PRAT ratprec = i32torat(precision);
|
||||
|
||||
// Find the best 'A' for convergence to the required precision.
|
||||
a = i32torat(radix);
|
||||
@@ -102,7 +98,7 @@ void _gamma(PRAT* pn, uint32_t radix, int32_t precision)
|
||||
exprat(&tmp, radix, precision);
|
||||
mulrat(&term, tmp, precision);
|
||||
lograt(&term, precision);
|
||||
ratRadix = i32torat(radix);
|
||||
const auto ratRadix = i32torat(radix);
|
||||
DUPRAT(tmp, ratRadix);
|
||||
lograt(&tmp, precision);
|
||||
subrat(&term, tmp, precision);
|
||||
@@ -173,7 +169,6 @@ void _gamma(PRAT* pn, uint32_t radix, int32_t precision)
|
||||
mulrat(&sum, mpy, precision);
|
||||
|
||||
// And cleanup
|
||||
precision = oldprec;
|
||||
destroyrat(ratprec);
|
||||
destroyrat(err);
|
||||
destroyrat(term);
|
||||
|
@@ -21,7 +21,6 @@ void lshrat(_Inout_ PRAT* pa, _In_ PRAT b, uint32_t radix, int32_t precision)
|
||||
|
||||
{
|
||||
PRAT pwr = nullptr;
|
||||
int32_t intb;
|
||||
|
||||
intrat(pa, radix, precision);
|
||||
if (!zernum((*pa)->pp))
|
||||
@@ -32,7 +31,7 @@ void lshrat(_Inout_ PRAT* pa, _In_ PRAT b, uint32_t radix, int32_t precision)
|
||||
// Don't attempt lsh of anything big
|
||||
throw(CALC_E_DOMAIN);
|
||||
}
|
||||
intb = rattoi32(b, radix, precision);
|
||||
const int32_t intb = rattoi32(b, radix, precision);
|
||||
DUPRAT(pwr, rat_two);
|
||||
ratpowi32(&pwr, intb, precision);
|
||||
mulrat(pa, pwr, precision);
|
||||
@@ -44,7 +43,6 @@ void rshrat(_Inout_ PRAT* pa, _In_ PRAT b, uint32_t radix, int32_t precision)
|
||||
|
||||
{
|
||||
PRAT pwr = nullptr;
|
||||
int32_t intb;
|
||||
|
||||
intrat(pa, radix, precision);
|
||||
if (!zernum((*pa)->pp))
|
||||
@@ -55,7 +53,7 @@ void rshrat(_Inout_ PRAT* pa, _In_ PRAT b, uint32_t radix, int32_t precision)
|
||||
// Don't attempt rsh of anything big and negative.
|
||||
throw(CALC_E_DOMAIN);
|
||||
}
|
||||
intb = rattoi32(b, radix, precision);
|
||||
const int32_t intb = rattoi32(b, radix, precision);
|
||||
DUPRAT(pwr, rat_two);
|
||||
ratpowi32(&pwr, intb, precision);
|
||||
divrat(pa, pwr, precision);
|
||||
|
@@ -67,8 +67,7 @@ void _addnum(PNUMBER* pa, PNUMBER b, uint32_t radix)
|
||||
MANTTYPE* pcha; // pcha is a pointer to the mantissa of a.
|
||||
MANTTYPE* pchb; // pchb is a pointer to the mantissa of b.
|
||||
MANTTYPE* pchc; // pchc is a pointer to the mantissa of c.
|
||||
int32_t cdigits; // cdigits is the max count of the digits results
|
||||
// used as a counter.
|
||||
int32_t cdigits; // cdigits is the max count of the digits results used as a counter.
|
||||
int32_t mexp; // mexp is the exponent of the result.
|
||||
MANTTYPE da; // da is a single 'digit' after possible padding.
|
||||
MANTTYPE db; // db is a single 'digit' after possible padding.
|
||||
@@ -558,48 +557,34 @@ bool equnum(_In_ PNUMBER a, _In_ PNUMBER b)
|
||||
bool lessnum(_In_ PNUMBER a, _In_ PNUMBER b)
|
||||
|
||||
{
|
||||
int32_t diff;
|
||||
MANTTYPE* pa;
|
||||
MANTTYPE* pb;
|
||||
int32_t cdigits;
|
||||
int32_t ccdigits;
|
||||
MANTTYPE da;
|
||||
MANTTYPE db;
|
||||
|
||||
diff = (a->cdigit + a->exp) - (b->cdigit + b->exp);
|
||||
int32_t diff = (a->cdigit + a->exp) - (b->cdigit + b->exp);
|
||||
if (diff < 0)
|
||||
{
|
||||
// The exponent of a is less than b
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (diff > 0)
|
||||
{
|
||||
if (diff > 0)
|
||||
return false;
|
||||
}
|
||||
MANTTYPE* pa = a->mant;
|
||||
MANTTYPE* pb = b->mant;
|
||||
pa += a->cdigit - 1;
|
||||
pb += b->cdigit - 1;
|
||||
int32_t cdigits = max(a->cdigit, b->cdigit);
|
||||
int32_t ccdigits = cdigits;
|
||||
for (; cdigits > 0; cdigits--)
|
||||
{
|
||||
MANTTYPE da = ((cdigits > (ccdigits - a->cdigit)) ? *pa-- : 0);
|
||||
MANTTYPE db = ((cdigits > (ccdigits - b->cdigit)) ? *pb-- : 0);
|
||||
diff = da - db;
|
||||
if (diff)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
pa = a->mant;
|
||||
pb = b->mant;
|
||||
pa += a->cdigit - 1;
|
||||
pb += b->cdigit - 1;
|
||||
cdigits = max(a->cdigit, b->cdigit);
|
||||
ccdigits = cdigits;
|
||||
for (; cdigits > 0; cdigits--)
|
||||
{
|
||||
da = ((cdigits > (ccdigits - a->cdigit)) ? *pa-- : 0);
|
||||
db = ((cdigits > (ccdigits - b->cdigit)) ? *pb-- : 0);
|
||||
diff = da - db;
|
||||
if (diff)
|
||||
{
|
||||
return (diff < 0);
|
||||
}
|
||||
}
|
||||
// In this case, they are equal.
|
||||
return false;
|
||||
return (diff < 0);
|
||||
}
|
||||
}
|
||||
// In this case, they are equal.
|
||||
return false;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@@ -596,15 +596,13 @@ void _dumprawrat(_In_ const wchar_t* varname, _In_ PRAT rat, wostream& out)
|
||||
void _dumprawnum(_In_ const wchar_t* varname, _In_ PNUMBER num, wostream& out)
|
||||
|
||||
{
|
||||
int i;
|
||||
|
||||
out << L"NUMBER " << varname << L" = {\n";
|
||||
out << L"\t" << num->sign << L",\n";
|
||||
out << L"\t" << num->cdigit << L",\n";
|
||||
out << L"\t" << num->exp << L",\n";
|
||||
out << L"\t{ ";
|
||||
|
||||
for (i = 0; i < num->cdigit; i++)
|
||||
for (int i = 0; i < num->cdigit; i++)
|
||||
{
|
||||
out << L" " << num->mant[i] << L",";
|
||||
}
|
||||
@@ -681,10 +679,9 @@ void trimit(_Inout_ PRAT* px, int32_t precision)
|
||||
{
|
||||
if (!g_ftrueinfinite)
|
||||
{
|
||||
int32_t trim;
|
||||
PNUMBER pp = (*px)->pp;
|
||||
PNUMBER pq = (*px)->pq;
|
||||
trim = g_ratio * (min((pp->cdigit + pp->exp), (pq->cdigit + pq->exp)) - 1) - precision;
|
||||
int32_t trim = g_ratio * (min((pp->cdigit + pp->exp), (pq->cdigit + pq->exp)) - 1) - precision;
|
||||
if (trim > g_ratio)
|
||||
{
|
||||
trim /= g_ratio;
|
||||
|
Reference in New Issue
Block a user