Skip to content

Commit

Permalink
Use Ui32tonum instead of i32tonum
Browse files Browse the repository at this point in the history
It is more appropriate considering we are dealing with unsigned numbers in the context of the code.

Make m_dwWordBitWidth unsigned

Also adjust parameter types to accommodate this
  • Loading branch information
AreaZR committed Nov 15, 2022
1 parent 1796cd0 commit ba3c3ee
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 96 deletions.
2 changes: 1 addition & 1 deletion src/CalcManager/CEngine/CalcInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool CalcInput::TryToggleSign(bool isIntegerMode, wstring_view maxNumStr)
return true;
}

bool CalcInput::TryAddDigit(unsigned int value, uint32_t radix, bool isIntegerMode, wstring_view maxNumStr, int32_t wordBitWidth, int maxDigits)
bool CalcInput::TryAddDigit(unsigned int value, uint32_t radix, bool isIntegerMode, wstring_view maxNumStr, uint32_t wordBitWidth, int maxDigits)
{
// Convert from an integer into a character
// This includes both normal digits and alpha 'digits' for radixes > 10
Expand Down
8 changes: 4 additions & 4 deletions src/CalcManager/CEngine/scifunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

using namespace std;
using namespace CalcEngine;
using namespace CalcEngine::RationalMath;
using namespace RationalMath;

/* Routines for more complex mathematical functions/error checking. */
CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& rat, uint32_t op)
Rational CCalcEngine::SciCalcFunctions(Rational const& rat, uint32_t op)
{
Rational result{};
try
Expand All @@ -39,7 +39,7 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r
case IDC_COM:
if (m_radix == 10 && !m_fIntegerMode)
{
result = -(RationalMath::Integer(rat) + 1);
result = -(Integer(rat) + 1);
}
else
{
Expand Down Expand Up @@ -78,7 +78,7 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r
result = Integer(rat);

uint64_t w64Bits = result.ToUInt64_t();
uint64_t lsb = ((w64Bits & 0x01) == 1) ? 1 : 0;
uint64_t lsb = w64Bits & 0x01;
w64Bits >>= 1; // RShift by 1

if (op == IDC_ROR)
Expand Down
2 changes: 1 addition & 1 deletion src/CalcManager/CEngine/sciset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RadixType radixtype, NUM_WIDTH numwidt
DisplayNum();
}

int32_t CCalcEngine::DwWordBitWidthFromNumWidth(NUM_WIDTH numwidth)
uint32_t CCalcEngine::DwWordBitWidthFromNumWidth(NUM_WIDTH numwidth)
{
switch (numwidth)
{
Expand Down
4 changes: 2 additions & 2 deletions src/CalcManager/Header Files/CalcEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class CCalcEngine
int m_nLastCom; // Last command entered.
AngleType m_angletype; // Current Angle type when in dec mode. one of deg, rad or grad
NUM_WIDTH m_numwidth; // one of qword, dword, word or byte mode.
int32_t m_dwWordBitWidth; // # of bits in currently selected word size
uint32_t m_dwWordBitWidth; // # of bits in currently selected word size

std::unique_ptr<std::mt19937> m_randomGeneratorEngine;
std::unique_ptr<std::uniform_real_distribution<>> m_distr;
Expand Down Expand Up @@ -179,7 +179,7 @@ class CCalcEngine
CalcEngine::Rational SciCalcFunctions(CalcEngine::Rational const& rat, uint32_t op);
CalcEngine::Rational DoOperation(int operation, CalcEngine::Rational const& lhs, CalcEngine::Rational const& rhs);
void SetRadixTypeAndNumWidth(RadixType radixtype, NUM_WIDTH numwidth);
int32_t DwWordBitWidthFromNumWidth(NUM_WIDTH numwidth);
uint32_t DwWordBitWidthFromNumWidth(NUM_WIDTH numwidth);
uint32_t NRadixFromRadixType(RadixType radixtype);
double GenerateRandomNumber();

Expand Down
2 changes: 1 addition & 1 deletion src/CalcManager/Header Files/CalcInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace CalcEngine

void Clear();
bool TryToggleSign(bool isIntegerMode, std::wstring_view maxNumStr);
bool TryAddDigit(unsigned int value, uint32_t radix, bool isIntegerMode, std::wstring_view maxNumStr, int32_t wordBitWidth, int maxDigits);
bool TryAddDigit(unsigned int value, uint32_t radix, bool isIntegerMode, std::wstring_view maxNumStr, uint32_t wordBitWidth, int maxDigits);
bool TryAddDecimalPt();
bool HasDecimalPt();
bool TryBeginExponent();
Expand Down
7 changes: 3 additions & 4 deletions src/CalcManager/Ratpack/basex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,12 @@ void _divnumx(PNUMBER* pa, PNUMBER b, int32_t precision)
c->sign = a->sign * b->sign;

ptrc = c->mant + thismax;
cdigits = 0;

DUPNUM(rem, a);
rem->sign = b->sign;
rem->exp = b->cdigit + b->exp - rem->cdigit;

while (cdigits++ < thismax && !zernum(rem))
for (cdigits = 0; cdigits < thismax && !zernum(rem); cdigits++)
{
int32_t digit = 0;
*ptrc = 0;
Expand Down Expand Up @@ -331,10 +330,10 @@ void _divnumx(PNUMBER* pa, PNUMBER b, int32_t precision)
rem->exp++;
ptrc--;
}
cdigits--;

if (c->mant != ++ptrc)
{
memmove(c->mant, ptrc, (int)(cdigits * sizeof(MANTTYPE)));
memmove(c->mant, ptrc, cdigits * sizeof(MANTTYPE));
}

if (!cdigits)
Expand Down
Loading

0 comments on commit ba3c3ee

Please sign in to comment.