Merge initializers and assignments (#1088)
This commit is contained in:
parent
319f0e850c
commit
d14423d0f1
@ -36,19 +36,16 @@ namespace
|
|||||||
IDC_RSHF,3, IDC_LSHF,3, IDC_RSHFL,3,
|
IDC_RSHF,3, IDC_LSHF,3, IDC_RSHFL,3,
|
||||||
IDC_MOD,3, IDC_DIV,3, IDC_MUL,3,
|
IDC_MOD,3, IDC_DIV,3, IDC_MUL,3,
|
||||||
IDC_PWR,4, IDC_ROOT,4, IDC_LOGBASEX,4 };
|
IDC_PWR,4, IDC_ROOT,4, IDC_LOGBASEX,4 };
|
||||||
unsigned int iPrec;
|
|
||||||
|
|
||||||
iPrec = 0;
|
for (unsigned int iPrec = 0; iPrec < size(rgbPrec); iPrec += 2)
|
||||||
while ((iPrec < size(rgbPrec)) && (nopCode != rgbPrec[iPrec]))
|
|
||||||
{
|
{
|
||||||
iPrec += 2;
|
if (nopCode == rgbPrec[iPrec])
|
||||||
}
|
|
||||||
if (iPrec >= size(rgbPrec))
|
|
||||||
{
|
{
|
||||||
iPrec = 0;
|
|
||||||
}
|
|
||||||
return rgbPrec[iPrec + 1];
|
return rgbPrec[iPrec + 1];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleErrorCommand
|
// HandleErrorCommand
|
||||||
@ -104,8 +101,6 @@ void CCalcEngine::ProcessCommand(OpCode wParam)
|
|||||||
|
|
||||||
void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
||||||
{
|
{
|
||||||
int nx, ni;
|
|
||||||
|
|
||||||
// Save the last command. Some commands are not saved in this manor, these
|
// Save the last command. Some commands are not saved in this manor, these
|
||||||
// commands are:
|
// commands are:
|
||||||
// Inv, Deg, Rad, Grad, Stat, FE, MClear, Back, and Exp. The excluded
|
// Inv, Deg, Rad, Grad, Stat, FE, MClear, Back, and Exp. The excluded
|
||||||
@ -163,15 +158,12 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
|||||||
DisplayNum(); // Causes 3.000 to shrink to 3. on first op.
|
DisplayNum(); // Causes 3.000 to shrink to 3. on first op.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (IsDigitOpCode(wParam) || wParam == IDC_PNT)
|
||||||
{
|
|
||||||
if (IsDigitOpCode(wParam) || wParam == IDC_PNT)
|
|
||||||
{
|
{
|
||||||
m_bRecord = true;
|
m_bRecord = true;
|
||||||
m_input.Clear();
|
m_input.Clear();
|
||||||
CheckAndAddLastBinOpToHistory();
|
CheckAndAddLastBinOpToHistory();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Interpret digit keys.
|
// Interpret digit keys.
|
||||||
if (IsDigitOpCode(wParam))
|
if (IsDigitOpCode(wParam))
|
||||||
@ -203,7 +195,6 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
|||||||
// Change the operation if last input was operation.
|
// Change the operation if last input was operation.
|
||||||
if (IsBinOpCode(m_nLastCom))
|
if (IsBinOpCode(m_nLastCom))
|
||||||
{
|
{
|
||||||
int nPrev;
|
|
||||||
bool fPrecInvToHigher = false; // Is Precedence Inversion from lower to higher precedence happening ??
|
bool fPrecInvToHigher = false; // Is Precedence Inversion from lower to higher precedence happening ??
|
||||||
|
|
||||||
m_nOpCode = (int)wParam;
|
m_nOpCode = (int)wParam;
|
||||||
@ -214,9 +205,9 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
|||||||
// Here * is m_nPrevOpCode, m_currentVal is 2 (by 1*2), m_nLastCom is +, m_nOpCode is ^
|
// Here * is m_nPrevOpCode, m_currentVal is 2 (by 1*2), m_nLastCom is +, m_nOpCode is ^
|
||||||
if (m_fPrecedence && 0 != m_nPrevOpCode)
|
if (m_fPrecedence && 0 != m_nPrevOpCode)
|
||||||
{
|
{
|
||||||
nPrev = NPrecedenceOfOp(m_nPrevOpCode);
|
int nPrev = NPrecedenceOfOp(m_nPrevOpCode);
|
||||||
nx = NPrecedenceOfOp(m_nLastCom);
|
int nx = NPrecedenceOfOp(m_nLastCom);
|
||||||
ni = NPrecedenceOfOp(m_nOpCode);
|
int ni = NPrecedenceOfOp(m_nOpCode);
|
||||||
if (nx <= nPrev && ni > nPrev) // condition for Precedence Inversion
|
if (nx <= nPrev && ni > nPrev) // condition for Precedence Inversion
|
||||||
{
|
{
|
||||||
fPrecInvToHigher = true;
|
fPrecInvToHigher = true;
|
||||||
@ -243,8 +234,8 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
|||||||
{
|
{
|
||||||
DoPrecedenceCheckAgain:
|
DoPrecedenceCheckAgain:
|
||||||
|
|
||||||
nx = NPrecedenceOfOp((int)wParam);
|
int nx = NPrecedenceOfOp((int)wParam);
|
||||||
ni = NPrecedenceOfOp(m_nOpCode);
|
int ni = NPrecedenceOfOp(m_nOpCode);
|
||||||
|
|
||||||
if ((nx > ni) && m_fPrecedence)
|
if ((nx > ni) && m_fPrecedence)
|
||||||
{
|
{
|
||||||
@ -492,8 +483,8 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
|||||||
m_lastVal = m_precedenceVals[m_precedenceOpCount];
|
m_lastVal = m_precedenceVals[m_precedenceOpCount];
|
||||||
|
|
||||||
// Precedence Inversion check
|
// Precedence Inversion check
|
||||||
ni = NPrecedenceOfOp(m_nPrevOpCode);
|
int ni = NPrecedenceOfOp(m_nPrevOpCode);
|
||||||
nx = NPrecedenceOfOp(m_nOpCode);
|
int nx = NPrecedenceOfOp(m_nOpCode);
|
||||||
if (ni <= nx)
|
if (ni <= nx)
|
||||||
{
|
{
|
||||||
m_HistoryCollector.EnclosePrecInversionBrackets();
|
m_HistoryCollector.EnclosePrecInversionBrackets();
|
||||||
@ -518,20 +509,15 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
|||||||
|
|
||||||
case IDC_OPENP:
|
case IDC_OPENP:
|
||||||
case IDC_CLOSEP:
|
case IDC_CLOSEP:
|
||||||
nx = 0;
|
|
||||||
if (wParam == IDC_OPENP)
|
|
||||||
{
|
|
||||||
nx = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -IF- the Paren holding array is full and we try to add a paren
|
// -IF- the Paren holding array is full and we try to add a paren
|
||||||
// -OR- the paren holding array is empty and we try to remove a
|
// -OR- the paren holding array is empty and we try to remove a
|
||||||
// paren
|
// paren
|
||||||
// -OR- the precedence holding array is full
|
// -OR- the precedence holding array is full
|
||||||
if ((m_openParenCount >= MAXPRECDEPTH && nx) || (!m_openParenCount && !nx)
|
if ((m_openParenCount >= MAXPRECDEPTH && (wParam == IDC_OPENP)) || (!m_openParenCount && (wParam != IDC_OPENP))
|
||||||
|| ((m_precedenceOpCount >= MAXPRECDEPTH && m_nPrecOp[m_precedenceOpCount - 1] != 0)))
|
|| ((m_precedenceOpCount >= MAXPRECDEPTH && m_nPrecOp[m_precedenceOpCount - 1] != 0)))
|
||||||
{
|
{
|
||||||
if (!m_openParenCount && !nx)
|
if (!m_openParenCount && (wParam != IDC_OPENP))
|
||||||
{
|
{
|
||||||
m_pCalcDisplay->OnNoRightParenAdded();
|
m_pCalcDisplay->OnNoRightParenAdded();
|
||||||
}
|
}
|
||||||
@ -540,7 +526,7 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nx)
|
if (wParam == IDC_OPENP)
|
||||||
{
|
{
|
||||||
CheckAndAddLastBinOpToHistory();
|
CheckAndAddLastBinOpToHistory();
|
||||||
m_HistoryCollector.AddOpenBraceToHistory();
|
m_HistoryCollector.AddOpenBraceToHistory();
|
||||||
@ -588,8 +574,8 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
|||||||
for (m_nOpCode = m_nPrecOp[--m_precedenceOpCount]; m_nOpCode; m_nOpCode = m_nPrecOp[--m_precedenceOpCount])
|
for (m_nOpCode = m_nPrecOp[--m_precedenceOpCount]; m_nOpCode; m_nOpCode = m_nPrecOp[--m_precedenceOpCount])
|
||||||
{
|
{
|
||||||
// Precedence Inversion check
|
// Precedence Inversion check
|
||||||
ni = NPrecedenceOfOp(m_nPrevOpCode);
|
int ni = NPrecedenceOfOp(m_nPrevOpCode);
|
||||||
nx = NPrecedenceOfOp(m_nOpCode);
|
int nx = NPrecedenceOfOp(m_nOpCode);
|
||||||
if (ni <= nx)
|
if (ni <= nx)
|
||||||
{
|
{
|
||||||
m_HistoryCollector.EnclosePrecInversionBrackets();
|
m_HistoryCollector.EnclosePrecInversionBrackets();
|
||||||
@ -971,8 +957,8 @@ static const std::unordered_map<int, FunctionNameElement> operatorStringTable =
|
|||||||
{ IDC_RSHFL, { SIDS_RSH } },
|
{ IDC_RSHFL, { SIDS_RSH } },
|
||||||
{ IDC_RORC, { SIDS_ROR } },
|
{ IDC_RORC, { SIDS_ROR } },
|
||||||
{ IDC_ROLC, { SIDS_ROL } },
|
{ IDC_ROLC, { SIDS_ROL } },
|
||||||
{ IDC_CUBEROOT, {SIDS_CUBEROOT} },
|
{ IDC_CUBEROOT, { SIDS_CUBEROOT } },
|
||||||
{ IDC_MOD, {SIDS_MOD, L"", L"", L"", L"", L"", SIDS_PROGRAMMER_MOD} },
|
{ IDC_MOD, { SIDS_MOD, L"", L"", L"", L"", L"", SIDS_PROGRAMMER_MOD } },
|
||||||
};
|
};
|
||||||
|
|
||||||
wstring_view CCalcEngine::OpCodeToUnaryString(int nOpCode, bool fInv, ANGLE_TYPE angletype)
|
wstring_view CCalcEngine::OpCodeToUnaryString(int nOpCode, bool fInv, ANGLE_TYPE angletype)
|
||||||
|
@ -41,7 +41,6 @@ unsigned int CalculatorHistory::AddToHistory(
|
|||||||
_In_ shared_ptr<vector<shared_ptr<IExpressionCommand>>> const& commands,
|
_In_ shared_ptr<vector<shared_ptr<IExpressionCommand>>> const& commands,
|
||||||
wstring_view result)
|
wstring_view result)
|
||||||
{
|
{
|
||||||
unsigned int addedIndex;
|
|
||||||
shared_ptr<HISTORYITEM> spHistoryItem = make_shared<HISTORYITEM>();
|
shared_ptr<HISTORYITEM> spHistoryItem = make_shared<HISTORYITEM>();
|
||||||
|
|
||||||
spHistoryItem->historyItemVector.spTokens = tokens;
|
spHistoryItem->historyItemVector.spTokens = tokens;
|
||||||
@ -53,9 +52,7 @@ unsigned int CalculatorHistory::AddToHistory(
|
|||||||
// in the history doesn't get broken for RTL languages
|
// in the history doesn't get broken for RTL languages
|
||||||
spHistoryItem->historyItemVector.expression = L'\u202d' + generatedExpression + L'\u202c';
|
spHistoryItem->historyItemVector.expression = L'\u202d' + generatedExpression + L'\u202c';
|
||||||
spHistoryItem->historyItemVector.result = wstring(result);
|
spHistoryItem->historyItemVector.result = wstring(result);
|
||||||
addedIndex = AddItem(spHistoryItem);
|
return AddItem(spHistoryItem);
|
||||||
|
|
||||||
return addedIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CalculatorHistory::AddItem(_In_ shared_ptr<HISTORYITEM> const& spHistoryItem)
|
unsigned int CalculatorHistory::AddItem(_In_ shared_ptr<HISTORYITEM> const& spHistoryItem)
|
||||||
@ -66,19 +63,18 @@ unsigned int CalculatorHistory::AddItem(_In_ shared_ptr<HISTORYITEM> const& spHi
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_historyItems.push_back(spHistoryItem);
|
m_historyItems.push_back(spHistoryItem);
|
||||||
unsigned int lastIndex = static_cast<unsigned>(m_historyItems.size() - 1);
|
return static_cast<unsigned>(m_historyItems.size() - 1);
|
||||||
return lastIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CalculatorHistory::RemoveItem(unsigned int uIdx)
|
bool CalculatorHistory::RemoveItem(unsigned int uIdx)
|
||||||
{
|
{
|
||||||
if (uIdx > m_historyItems.size() - 1)
|
if (uIdx < m_historyItems.size())
|
||||||
{
|
{
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_historyItems.erase(m_historyItems.begin() + uIdx);
|
m_historyItems.erase(m_historyItems.begin() + uIdx);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<shared_ptr<HISTORYITEM>> const& CalculatorHistory::GetHistory()
|
vector<shared_ptr<HISTORYITEM>> const& CalculatorHistory::GetHistory()
|
||||||
|
@ -303,17 +303,13 @@ PRAT numtorat(_In_ PNUMBER pin, uint32_t radix)
|
|||||||
PNUMBER nRadixxtonum(_In_ PNUMBER a, uint32_t radix, int32_t precision)
|
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 sum = i32tonum(0, radix);
|
||||||
PNUMBER powofnRadix = i32tonum(BASEX, radix);
|
PNUMBER powofnRadix = i32tonum(BASEX, radix);
|
||||||
|
|
||||||
// A large penalty is paid for conversion of digits no one will see anyway.
|
// 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
|
// limit the digits to the minimum of the existing precision or the
|
||||||
// requested precision.
|
// requested precision.
|
||||||
cdigits = precision + 1;
|
uint32_t cdigits = precision + 1;
|
||||||
if (cdigits > (uint32_t)a->cdigit)
|
if (cdigits > (uint32_t)a->cdigit)
|
||||||
{
|
{
|
||||||
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);
|
numpowi32(&powofnRadix, a->exp + (a->cdigit - cdigits), radix, precision);
|
||||||
|
|
||||||
// Loop over all the relative digits from MSD to LSD
|
// 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
|
// 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);
|
addnum(&sum, sum, radix);
|
||||||
if (*ptr & bitmask)
|
if (*ptr & bitmask)
|
||||||
@ -368,9 +364,7 @@ PNUMBER numtonRadixx(_In_ PNUMBER a, uint32_t radix)
|
|||||||
ptrdigit += a->cdigit - 1;
|
ptrdigit += a->cdigit - 1;
|
||||||
|
|
||||||
PNUMBER thisdigit = nullptr; // thisdigit holds the current digit of a
|
PNUMBER thisdigit = nullptr; // thisdigit holds the current digit of a
|
||||||
// being summed into result.
|
for (int32_t idigit = 0; idigit < a->cdigit; idigit++)
|
||||||
int32_t idigit; // idigit is the iterate of digits in a.
|
|
||||||
for (idigit = 0; idigit < a->cdigit; idigit++)
|
|
||||||
{
|
{
|
||||||
mulnumx(&pnumret, num_radix);
|
mulnumx(&pnumret, num_radix);
|
||||||
// WARNING:
|
// WARNING:
|
||||||
@ -628,11 +622,10 @@ PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precis
|
|||||||
MANTTYPE* pmant = pnumret->mant + numberString.length() - 1;
|
MANTTYPE* pmant = pnumret->mant + numberString.length() - 1;
|
||||||
|
|
||||||
uint8_t state = START; // state is the state of the input state machine.
|
uint8_t state = START; // state is the state of the input state machine.
|
||||||
wchar_t curChar;
|
|
||||||
for (const auto& c : numberString)
|
for (const auto& c : numberString)
|
||||||
{
|
{
|
||||||
// If the character is the decimal separator, use L'.' for the purposes of the state machine.
|
// 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 states based on the character we encountered
|
||||||
switch (curChar)
|
switch (curChar)
|
||||||
@ -1032,13 +1025,10 @@ int32_t numtoi32(_In_ PNUMBER pnum, uint32_t radix)
|
|||||||
|
|
||||||
bool stripzeroesnum(_Inout_ PNUMBER pnum, int32_t starting)
|
bool stripzeroesnum(_Inout_ PNUMBER pnum, int32_t starting)
|
||||||
{
|
{
|
||||||
MANTTYPE* pmant;
|
|
||||||
int32_t cdigits;
|
|
||||||
bool fstrip = false;
|
bool fstrip = false;
|
||||||
|
|
||||||
// point pmant to the LeastCalculatedDigit
|
// point pmant to the LeastCalculatedDigit
|
||||||
pmant = pnum->mant;
|
MANTTYPE* pmant = pnum->mant;
|
||||||
cdigits = pnum->cdigit;
|
int32_t cdigits = pnum->cdigit;
|
||||||
// point pmant to the LSD
|
// point pmant to the LSD
|
||||||
if (cdigits > starting)
|
if (cdigits > starting)
|
||||||
{
|
{
|
||||||
|
@ -63,7 +63,6 @@ void exprat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
|
|||||||
{
|
{
|
||||||
PRAT pwr = nullptr;
|
PRAT pwr = nullptr;
|
||||||
PRAT pint = nullptr;
|
PRAT pint = nullptr;
|
||||||
int32_t intpwr;
|
|
||||||
|
|
||||||
if (rat_gt(*px, rat_max_exp, precision) || rat_lt(*px, rat_min_exp, precision))
|
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);
|
intrat(&pint, radix, precision);
|
||||||
|
|
||||||
intpwr = rattoi32(pint, radix, precision);
|
const int32_t intpwr = rattoi32(pint, radix, precision);
|
||||||
ratpowi32(&pwr, intpwr, precision);
|
ratpowi32(&pwr, intpwr, precision);
|
||||||
|
|
||||||
subrat(px, pint, precision);
|
subrat(px, pint, precision);
|
||||||
@ -153,7 +152,6 @@ void _lograt(PRAT* px, int32_t precision)
|
|||||||
void lograt(_Inout_ 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 pwr = nullptr; // pwr is the large scaling factor.
|
||||||
PRAT offset = nullptr; // offset is the incremental 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
|
// Get number > 1, for scaling
|
||||||
fneglog = rat_lt(*px, rat_one, precision);
|
bool fneglog = rat_lt(*px, rat_one, precision);
|
||||||
if (fneglog)
|
if (fneglog)
|
||||||
{
|
{
|
||||||
// WARNING: This is equivalent to doing *px = 1 / *px
|
PNUMBER pnumtemp = (*px)->pp;
|
||||||
PNUMBER pnumtemp = nullptr;
|
|
||||||
pnumtemp = (*px)->pp;
|
|
||||||
(*px)->pp = (*px)->pq;
|
(*px)->pp = (*px)->pq;
|
||||||
(*px)->pq = pnumtemp;
|
(*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)
|
// log(x*2^(BASEXPWR*k)) = BASEXPWR*k*log(2)+log(x)
|
||||||
if (LOGRAT2(*px) > 1)
|
if (LOGRAT2(*px) > 1)
|
||||||
{
|
{
|
||||||
// Take advantage of px's base BASEX to scale quickly down to
|
const int32_t intpwr = LOGRAT2(*px) - 1;
|
||||||
// a reasonable range.
|
|
||||||
int32_t intpwr;
|
|
||||||
intpwr = LOGRAT2(*px) - 1;
|
|
||||||
(*px)->pq->exp += intpwr;
|
(*px)->pq->exp += intpwr;
|
||||||
pwr = i32torat(intpwr * BASEXPWR);
|
pwr = i32torat(intpwr * BASEXPWR);
|
||||||
mulrat(&pwr, ln_two, precision);
|
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.
|
// If power is an integer let ratpowi32 deal with it.
|
||||||
PRAT iy = nullptr;
|
PRAT iy = nullptr;
|
||||||
int32_t inty;
|
|
||||||
DUPRAT(iy, y);
|
DUPRAT(iy, y);
|
||||||
subrat(&iy, podd, precision);
|
subrat(&iy, podd, precision);
|
||||||
inty = rattoi32(iy, radix, precision);
|
int32_t inty = rattoi32(iy, radix, precision);
|
||||||
|
|
||||||
PRAT plnx = nullptr;
|
PRAT plnx = nullptr;
|
||||||
DUPRAT(plnx, *px);
|
DUPRAT(plnx, *px);
|
||||||
|
@ -67,13 +67,9 @@ void _gamma(PRAT* pn, uint32_t radix, int32_t precision)
|
|||||||
PRAT sum = nullptr;
|
PRAT sum = nullptr;
|
||||||
PRAT err = nullptr;
|
PRAT err = nullptr;
|
||||||
PRAT mpy = nullptr;
|
PRAT mpy = nullptr;
|
||||||
PRAT ratprec = nullptr;
|
|
||||||
PRAT ratRadix = nullptr;
|
|
||||||
int32_t oldprec;
|
|
||||||
|
|
||||||
// Set up constants and initial conditions
|
// Set up constants and initial conditions
|
||||||
oldprec = precision;
|
PRAT ratprec = i32torat(precision);
|
||||||
ratprec = i32torat(oldprec);
|
|
||||||
|
|
||||||
// Find the best 'A' for convergence to the required precision.
|
// Find the best 'A' for convergence to the required precision.
|
||||||
a = i32torat(radix);
|
a = i32torat(radix);
|
||||||
@ -102,7 +98,7 @@ void _gamma(PRAT* pn, uint32_t radix, int32_t precision)
|
|||||||
exprat(&tmp, radix, precision);
|
exprat(&tmp, radix, precision);
|
||||||
mulrat(&term, tmp, precision);
|
mulrat(&term, tmp, precision);
|
||||||
lograt(&term, precision);
|
lograt(&term, precision);
|
||||||
ratRadix = i32torat(radix);
|
const auto ratRadix = i32torat(radix);
|
||||||
DUPRAT(tmp, ratRadix);
|
DUPRAT(tmp, ratRadix);
|
||||||
lograt(&tmp, precision);
|
lograt(&tmp, precision);
|
||||||
subrat(&term, tmp, precision);
|
subrat(&term, tmp, precision);
|
||||||
@ -173,7 +169,6 @@ void _gamma(PRAT* pn, uint32_t radix, int32_t precision)
|
|||||||
mulrat(&sum, mpy, precision);
|
mulrat(&sum, mpy, precision);
|
||||||
|
|
||||||
// And cleanup
|
// And cleanup
|
||||||
precision = oldprec;
|
|
||||||
destroyrat(ratprec);
|
destroyrat(ratprec);
|
||||||
destroyrat(err);
|
destroyrat(err);
|
||||||
destroyrat(term);
|
destroyrat(term);
|
||||||
|
@ -21,7 +21,6 @@ void lshrat(_Inout_ PRAT* pa, _In_ PRAT b, uint32_t radix, int32_t precision)
|
|||||||
|
|
||||||
{
|
{
|
||||||
PRAT pwr = nullptr;
|
PRAT pwr = nullptr;
|
||||||
int32_t intb;
|
|
||||||
|
|
||||||
intrat(pa, radix, precision);
|
intrat(pa, radix, precision);
|
||||||
if (!zernum((*pa)->pp))
|
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
|
// Don't attempt lsh of anything big
|
||||||
throw(CALC_E_DOMAIN);
|
throw(CALC_E_DOMAIN);
|
||||||
}
|
}
|
||||||
intb = rattoi32(b, radix, precision);
|
const int32_t intb = rattoi32(b, radix, precision);
|
||||||
DUPRAT(pwr, rat_two);
|
DUPRAT(pwr, rat_two);
|
||||||
ratpowi32(&pwr, intb, precision);
|
ratpowi32(&pwr, intb, precision);
|
||||||
mulrat(pa, pwr, 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;
|
PRAT pwr = nullptr;
|
||||||
int32_t intb;
|
|
||||||
|
|
||||||
intrat(pa, radix, precision);
|
intrat(pa, radix, precision);
|
||||||
if (!zernum((*pa)->pp))
|
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.
|
// Don't attempt rsh of anything big and negative.
|
||||||
throw(CALC_E_DOMAIN);
|
throw(CALC_E_DOMAIN);
|
||||||
}
|
}
|
||||||
intb = rattoi32(b, radix, precision);
|
const int32_t intb = rattoi32(b, radix, precision);
|
||||||
DUPRAT(pwr, rat_two);
|
DUPRAT(pwr, rat_two);
|
||||||
ratpowi32(&pwr, intb, precision);
|
ratpowi32(&pwr, intb, precision);
|
||||||
divrat(pa, pwr, 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* pcha; // pcha is a pointer to the mantissa of a.
|
||||||
MANTTYPE* pchb; // pchb is a pointer to the mantissa of b.
|
MANTTYPE* pchb; // pchb is a pointer to the mantissa of b.
|
||||||
MANTTYPE* pchc; // pchc is a pointer to the mantissa of c.
|
MANTTYPE* pchc; // pchc is a pointer to the mantissa of c.
|
||||||
int32_t cdigits; // cdigits is the max count of the digits results
|
int32_t cdigits; // cdigits is the max count of the digits results used as a counter.
|
||||||
// used as a counter.
|
|
||||||
int32_t mexp; // mexp is the exponent of the result.
|
int32_t mexp; // mexp is the exponent of the result.
|
||||||
MANTTYPE da; // da is a single 'digit' after possible padding.
|
MANTTYPE da; // da is a single 'digit' after possible padding.
|
||||||
MANTTYPE db; // db is a single 'digit' after possible padding.
|
MANTTYPE db; // db is a single 'digit' after possible padding.
|
||||||
@ -558,38 +557,26 @@ bool equnum(_In_ PNUMBER a, _In_ PNUMBER b)
|
|||||||
bool lessnum(_In_ PNUMBER a, _In_ PNUMBER b)
|
bool lessnum(_In_ PNUMBER a, _In_ PNUMBER b)
|
||||||
|
|
||||||
{
|
{
|
||||||
int32_t diff;
|
int32_t diff = (a->cdigit + a->exp) - (b->cdigit + b->exp);
|
||||||
MANTTYPE* pa;
|
|
||||||
MANTTYPE* pb;
|
|
||||||
int32_t cdigits;
|
|
||||||
int32_t ccdigits;
|
|
||||||
MANTTYPE da;
|
|
||||||
MANTTYPE db;
|
|
||||||
|
|
||||||
diff = (a->cdigit + a->exp) - (b->cdigit + b->exp);
|
|
||||||
if (diff < 0)
|
if (diff < 0)
|
||||||
{
|
{
|
||||||
// The exponent of a is less than b
|
// The exponent of a is less than b
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if (diff > 0)
|
if (diff > 0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
MANTTYPE* pa = a->mant;
|
||||||
{
|
MANTTYPE* pb = b->mant;
|
||||||
pa = a->mant;
|
|
||||||
pb = b->mant;
|
|
||||||
pa += a->cdigit - 1;
|
pa += a->cdigit - 1;
|
||||||
pb += b->cdigit - 1;
|
pb += b->cdigit - 1;
|
||||||
cdigits = max(a->cdigit, b->cdigit);
|
int32_t cdigits = max(a->cdigit, b->cdigit);
|
||||||
ccdigits = cdigits;
|
int32_t ccdigits = cdigits;
|
||||||
for (; cdigits > 0; cdigits--)
|
for (; cdigits > 0; cdigits--)
|
||||||
{
|
{
|
||||||
da = ((cdigits > (ccdigits - a->cdigit)) ? *pa-- : 0);
|
MANTTYPE da = ((cdigits > (ccdigits - a->cdigit)) ? *pa-- : 0);
|
||||||
db = ((cdigits > (ccdigits - b->cdigit)) ? *pb-- : 0);
|
MANTTYPE db = ((cdigits > (ccdigits - b->cdigit)) ? *pb-- : 0);
|
||||||
diff = da - db;
|
diff = da - db;
|
||||||
if (diff)
|
if (diff)
|
||||||
{
|
{
|
||||||
@ -598,8 +585,6 @@ bool lessnum(_In_ PNUMBER a, _In_ PNUMBER b)
|
|||||||
}
|
}
|
||||||
// In this case, they are equal.
|
// In this case, they are equal.
|
||||||
return false;
|
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)
|
void _dumprawnum(_In_ const wchar_t* varname, _In_ PNUMBER num, wostream& out)
|
||||||
|
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
out << L"NUMBER " << varname << L" = {\n";
|
out << L"NUMBER " << varname << L" = {\n";
|
||||||
out << L"\t" << num->sign << L",\n";
|
out << L"\t" << num->sign << L",\n";
|
||||||
out << L"\t" << num->cdigit << L",\n";
|
out << L"\t" << num->cdigit << L",\n";
|
||||||
out << L"\t" << num->exp << L",\n";
|
out << L"\t" << num->exp << L",\n";
|
||||||
out << L"\t{ ";
|
out << L"\t{ ";
|
||||||
|
|
||||||
for (i = 0; i < num->cdigit; i++)
|
for (int i = 0; i < num->cdigit; i++)
|
||||||
{
|
{
|
||||||
out << L" " << num->mant[i] << L",";
|
out << L" " << num->mant[i] << L",";
|
||||||
}
|
}
|
||||||
@ -681,10 +679,9 @@ void trimit(_Inout_ PRAT* px, int32_t precision)
|
|||||||
{
|
{
|
||||||
if (!g_ftrueinfinite)
|
if (!g_ftrueinfinite)
|
||||||
{
|
{
|
||||||
int32_t trim;
|
|
||||||
PNUMBER pp = (*px)->pp;
|
PNUMBER pp = (*px)->pp;
|
||||||
PNUMBER pq = (*px)->pq;
|
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)
|
if (trim > g_ratio)
|
||||||
{
|
{
|
||||||
trim /= g_ratio;
|
trim /= g_ratio;
|
||||||
|
Loading…
Reference in New Issue
Block a user