fixed decimal resetting upon category change

This commit is contained in:
Declan Gazil 2022-09-26 08:17:34 -04:00
commit 2b3e4f4aad
16 changed files with 48 additions and 51 deletions

View file

@ -22,7 +22,7 @@ Calculator ships regularly with new features and bug fixes. You can get the late
## Getting started ## Getting started
Prerequisites: Prerequisites:
- Your computer must be running Windows 10, version 1809 or newer. Windows 11 is recommended. - Your computer must be running Windows 11, build 22000 or newer.
- Install the latest version of [Visual Studio](https://developer.microsoft.com/en-us/windows/downloads) (the free community edition is sufficient). - Install the latest version of [Visual Studio](https://developer.microsoft.com/en-us/windows/downloads) (the free community edition is sufficient).
- Install the "Universal Windows Platform Development" workload. - Install the "Universal Windows Platform Development" workload.
- Install the optional "C++ Universal Windows Platform tools" component. - Install the optional "C++ Universal Windows Platform tools" component.

View file

@ -22,10 +22,9 @@ namespace CalcEngine
Number::Number(PNUMBER p) noexcept Number::Number(PNUMBER p) noexcept
: m_sign{ p->sign } : m_sign{ p->sign }
, m_exp{ p->exp } , m_exp{ p->exp }
, m_mantissa{}
{ {
m_mantissa.reserve(p->cdigit); m_mantissa.reserve(p->cdigit);
copy(p->mant, p->mant + p->cdigit, back_inserter(m_mantissa)); copy_n(p->mant, p->cdigit, back_inserter(m_mantissa));
} }
PNUMBER Number::ToPNUMBER() const PNUMBER Number::ToPNUMBER() const

View file

@ -101,7 +101,7 @@ CCalcEngine::CCalcEngine(
{ {
InitChopNumbers(); InitChopNumbers();
m_dwWordBitWidth = DwWordBitWidthFromeNumWidth(m_numwidth); m_dwWordBitWidth = DwWordBitWidthFromNumWidth(m_numwidth);
m_maxTrigonometricNum = RationalMath::Pow(10, 100); m_maxTrigonometricNum = RationalMath::Pow(10, 100);

View file

@ -30,17 +30,31 @@ namespace
// 0 is returned. Higher the number, higher the precedence of the operator. // 0 is returned. Higher the number, higher the precedence of the operator.
int NPrecedenceOfOp(int nopCode) int NPrecedenceOfOp(int nopCode)
{ {
static uint16_t rgbPrec[] = { 0, 0, IDC_OR, 0, IDC_XOR, 0, IDC_AND, 1, IDC_NAND, 1, IDC_NOR, 1, IDC_ADD, 2, IDC_SUB, 2, IDC_RSHF, 3, switch (nopCode)
IDC_LSHF, 3, IDC_RSHFL, 3, IDC_MOD, 3, IDC_DIV, 3, IDC_MUL, 3, IDC_PWR, 4, IDC_ROOT, 4, IDC_LOGBASEY, 4 };
for (unsigned int iPrec = 0; iPrec < size(rgbPrec); iPrec += 2)
{ {
if (nopCode == rgbPrec[iPrec]) default:
{ case IDC_OR:
return rgbPrec[iPrec + 1]; case IDC_XOR:
} return 0;
case IDC_AND:
case IDC_NAND:
case IDC_NOR:
return 1;
case IDC_ADD:
case IDC_SUB:
return 2;
case IDC_LSHF:
case IDC_RSHF:
case IDC_RSHFL:
case IDC_MOD:
case IDC_DIV:
case IDC_MUL:
return 3;
case IDC_PWR:
case IDC_ROOT:
case IDC_LOGBASEY:
return 4;
} }
return 0;
} }
} }
@ -518,7 +532,7 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
if (wParam == IDC_OPENP) if (wParam == IDC_OPENP)
{ {
// if there's an omitted multiplication sign // if there's an omitted multiplication sign
if (IsDigitOpCode(m_nLastCom) || IsUnaryOpCode(m_nLastCom) || m_nLastCom == IDC_PNT || m_nLastCom == IDC_CLOSEP) if (IsDigitOpCode(m_nLastCom) || IsUnaryOpCode(m_nLastCom) || m_nLastCom == IDC_PNT || m_nLastCom == IDC_CLOSEP)
{ {
ProcessCommand(IDC_MUL); ProcessCommand(IDC_MUL);

View file

@ -39,7 +39,7 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RadixType radixtype, NUM_WIDTH numwidt
if (numwidth >= NUM_WIDTH::QWORD_WIDTH && numwidth <= NUM_WIDTH::BYTE_WIDTH) if (numwidth >= NUM_WIDTH::QWORD_WIDTH && numwidth <= NUM_WIDTH::BYTE_WIDTH)
{ {
m_numwidth = numwidth; m_numwidth = numwidth;
m_dwWordBitWidth = DwWordBitWidthFromeNumWidth(numwidth); m_dwWordBitWidth = DwWordBitWidthFromNumWidth(numwidth);
} }
// inform ratpak that a change in base or precision has occurred // inform ratpak that a change in base or precision has occurred
@ -50,7 +50,7 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RadixType radixtype, NUM_WIDTH numwidt
DisplayNum(); DisplayNum();
} }
int32_t CCalcEngine::DwWordBitWidthFromeNumWidth(NUM_WIDTH numwidth) int32_t CCalcEngine::DwWordBitWidthFromNumWidth(NUM_WIDTH numwidth)
{ {
switch (numwidth) switch (numwidth)
{ {
@ -85,7 +85,7 @@ uint32_t CCalcEngine::NRadixFromRadixType(RadixType radixtype)
// Toggles a given bit into the number representation. returns true if it changed it actually. // Toggles a given bit into the number representation. returns true if it changed it actually.
bool CCalcEngine::TryToggleBit(CalcEngine::Rational& rat, uint32_t wbitno) bool CCalcEngine::TryToggleBit(CalcEngine::Rational& rat, uint32_t wbitno)
{ {
uint32_t wmax = DwWordBitWidthFromeNumWidth(m_numwidth); uint32_t wmax = DwWordBitWidthFromNumWidth(m_numwidth);
if (wbitno >= wmax) if (wbitno >= wmax)
{ {
return false; // ignore error cant happen return false; // ignore error cant happen

View file

@ -179,7 +179,7 @@ private:
CalcEngine::Rational SciCalcFunctions(CalcEngine::Rational const& rat, uint32_t op); CalcEngine::Rational SciCalcFunctions(CalcEngine::Rational const& rat, uint32_t op);
CalcEngine::Rational DoOperation(int operation, CalcEngine::Rational const& lhs, CalcEngine::Rational const& rhs); CalcEngine::Rational DoOperation(int operation, CalcEngine::Rational const& lhs, CalcEngine::Rational const& rhs);
void SetRadixTypeAndNumWidth(RadixType radixtype, NUM_WIDTH numwidth); void SetRadixTypeAndNumWidth(RadixType radixtype, NUM_WIDTH numwidth);
int32_t DwWordBitWidthFromeNumWidth(NUM_WIDTH numwidth); int32_t DwWordBitWidthFromNumWidth(NUM_WIDTH numwidth);
uint32_t NRadixFromRadixType(RadixType radixtype); uint32_t NRadixFromRadixType(RadixType radixtype);
double GenerateRandomNumber(); double GenerateRandomNumber();

View file

@ -38,7 +38,7 @@
// This format is based loosely on an OLE HRESULT and is compatible with the // This format is based loosely on an OLE HRESULT and is compatible with the
// SUCCEEDED and FAILED macros as well as the HRESULT_CODE macro // SUCCEEDED and FAILED macros as well as the HRESULT_CODE macro
typedef int32_t ResultCode; using ResultCode = int32_t;
// CALC_E_DIVIDEBYZERO // CALC_E_DIVIDEBYZERO
// //

View file

@ -156,13 +156,12 @@ namespace UnitConversionManager
std::wstring targetCurrencyCode; std::wstring targetCurrencyCode;
}; };
typedef std::tuple<std::vector<UnitConversionManager::Unit>, UnitConversionManager::Unit, UnitConversionManager::Unit> CategorySelectionInitializer; using CategorySelectionInitializer = std::tuple<std::vector<UnitConversionManager::Unit>, UnitConversionManager::Unit, UnitConversionManager::Unit>;
typedef std::unordered_map< using UnitToUnitToConversionDataMap = std::unordered_map<
UnitConversionManager::Unit, UnitConversionManager::Unit,
std::unordered_map<UnitConversionManager::Unit, UnitConversionManager::ConversionData, UnitConversionManager::UnitHash>, std::unordered_map<UnitConversionManager::Unit, UnitConversionManager::ConversionData, UnitConversionManager::UnitHash>,
UnitConversionManager::UnitHash> UnitConversionManager::UnitHash>;
UnitToUnitToConversionDataMap; using CategoryToUnitVectorMap = std::unordered_map<int, std::vector<UnitConversionManager::Unit>>;
typedef std::unordered_map<int, std::vector<UnitConversionManager::Unit>> CategoryToUnitVectorMap;
class IViewModelCurrencyCallback class IViewModelCurrencyCallback
{ {

View file

@ -16,7 +16,7 @@ namespace CalculatorApp::ViewModel
{ {
std::wstring returnString = L""; std::wstring returnString = L"";
const UINT32 length = 1024; const UINT32 length = 1024;
std::unique_ptr<wchar_t[]> spBuffer = std::unique_ptr<wchar_t[]>(new wchar_t[length]); std::unique_ptr<wchar_t[]> spBuffer = std::make_unique<wchar_t[]>(length);
va_list args = NULL; va_list args = NULL;
va_start(args, pMessage); va_start(args, pMessage);
DWORD fmtReturnVal = FormatMessage(FORMAT_MESSAGE_FROM_STRING, pMessage->Data(), 0, 0, spBuffer.get(), length, &args); DWORD fmtReturnVal = FormatMessage(FORMAT_MESSAGE_FROM_STRING, pMessage->Data(), 0, 0, spBuffer.get(), length, &args);

View file

@ -174,11 +174,11 @@ void UnitConverterViewModel::ResetCategory()
m_isInputBlocked = false; m_isInputBlocked = false;
SetSelectedUnits(); SetSelectedUnits();
UpdateIsDecimalEnabled();
IsCurrencyLoadingVisible = m_IsCurrencyCurrentCategory && !m_isCurrencyDataLoaded; IsCurrencyLoadingVisible = m_IsCurrencyCurrentCategory && !m_isCurrencyDataLoaded;
IsDropDownEnabled = m_Units->GetAt(0) != EMPTY_UNIT; IsDropDownEnabled = m_Units->GetAt(0) != EMPTY_UNIT;
UpdateIsDecimalEnabled();
UnitChanged->Execute(nullptr); UnitChanged->Execute(nullptr);
} }

View file

@ -42,14 +42,3 @@
#include "winrt/Windows.UI.Xaml.h" #include "winrt/Windows.UI.Xaml.h"
#include "winrt/Windows.Foundation.Metadata.h" #include "winrt/Windows.Foundation.Metadata.h"
#include "winrt/Windows.Management.Policies.h" #include "winrt/Windows.Management.Policies.h"
// The following namespaces exist as a convenience to resolve
// ambiguity for Windows types in the Windows::UI::Xaml::Automation::Peers
// namespace that only exist on RS3.
// Once the app switches to min version RS3, the namespaces can be removed.
// TODO - MSFT 12735088
namespace StandardPeers = Windows::UI::Xaml::Automation::Peers;
namespace CalculatorApp::ViewModel::Common::Automation
{
}
namespace CustomPeers = CalculatorApp::ViewModel::Common::Automation;

View file

@ -792,9 +792,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform"> <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.10</Version> <Version>6.2.14</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.UI.Xaml" Version="2.8.0" /> <PackageReference Include="Microsoft.UI.Xaml" Version="2.8.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\CalcViewModel\CalcViewModel.vcxproj"> <ProjectReference Include="..\CalcViewModel\CalcViewModel.vcxproj">

View file

@ -3,7 +3,7 @@
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="4.3.1" /> <PackageReference Include="Appium.WebDriver" Version="4.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" /> <PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -45,10 +45,6 @@ namespace CalculatorUITestFramework
public WindowsDriverServiceBuilder WithStartUpTimeOut(TimeSpan startUpTimeout) public WindowsDriverServiceBuilder WithStartUpTimeOut(TimeSpan startUpTimeout)
{ {
if (startUpTimeout == null)
{
throw new ArgumentNullException("A startup timeout should not be NULL");
}
this.StartUpTimeout = startUpTimeout; this.StartUpTimeout = startUpTimeout;
return this; return this;
} }

View file

@ -4,10 +4,10 @@
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" /> <PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" /> <PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="Appium.WebDriver" Version="4.3.1" /> <PackageReference Include="Appium.WebDriver" Version="4.3.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\CalculatorUITestFramework\CalculatorUITestFramework.csproj" /> <ProjectReference Include="..\CalculatorUITestFramework\CalculatorUITestFramework.csproj" />

View file

@ -11,7 +11,7 @@
namespace Graphing::Analyzer namespace Graphing::Analyzer
{ {
typedef unsigned int NativeAnalysisType; // PerformAnalysisType using NativeAnalysisType = unsigned int; // PerformAnalysisType
struct IGraphAnalyzer : public NonCopyable, public NonMoveable struct IGraphAnalyzer : public NonCopyable, public NonMoveable
{ {