diff --git a/.editorconfig b/.editorconfig
index f3416ab7..a2008871 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -5,7 +5,6 @@ root = true
[*]
indent_style = space
indent_size = 4
-end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
diff --git a/.gitignore b/.gitignore
index 80d64f53..2100dfc1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -290,4 +290,5 @@ __pycache__/
# Calculator specific
Generated Files/
!/build/config/TRexDefs/**
+!src/Calculator/TemporaryKey.pfx
!src/CalculatorUnitTests/CalculatorUnitTests_TemporaryKey.pfx
\ No newline at end of file
diff --git a/README.md b/README.md
index 23afe0de..ffba40c0 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
The Windows Calculator app is a modern Windows app written in C++ that ships pre-installed with Windows.
The app provides standard, scientific, and programmer calculator functionality, as well as a set of converters between various units of measurement and currencies.
-Calculator ships regularly with new features and bug fixes. You can get the latest version of Calculator in the [Microsoft Store.](https://www.microsoft.com/store/apps/9WZDNCRFHVN5)
+Calculator ships regularly with new features and bug fixes. You can get the latest version of Calculator in the [Microsoft Store](https://www.microsoft.com/store/apps/9WZDNCRFHVN5).
[](https://dev.azure.com/ms/calculator/_build/latest?definitionId=57&branchName=master)
@@ -18,14 +18,14 @@ Calculator ships regularly with new features and bug fixes. You can get the late
## Getting started
Prerequisites:
-- Your computer must be running Windows 10, version 1803 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 "Universal Windows Platform Development" workload
- - Install the optional "C++ Universal Windows Platform tools" component
- - Install the latest Windows 10 SDK
+- Your computer must be running Windows 10, version 1803 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 "Universal Windows Platform Development" workload.
+ - Install the optional "C++ Universal Windows Platform tools" component.
+ - Install the latest Windows 10 SDK.

-- Install the [XAML Styler](https://marketplace.visualstudio.com/items?itemName=TeamXavalon.XAMLStyler) Visual Studio extension
+- Install the [XAML Styler](https://marketplace.visualstudio.com/items?itemName=TeamXavalon.XAMLStyler) Visual Studio extension.
- Get the code:
```
diff --git a/build/pipelines/azure-pipelines.loc.yaml b/build/pipelines/azure-pipelines.loc.yaml
index d2bef95e..d1ef8552 100644
--- a/build/pipelines/azure-pipelines.loc.yaml
+++ b/build/pipelines/azure-pipelines.loc.yaml
@@ -15,30 +15,33 @@ name: $(BuildDefinitionName)_$(date:yyMM).$(date:dd)$(rev:rrr)
jobs:
- job: Localize
pool:
- name: Package ES Custom Demands Lab A
- demands:
- - ClientAlias -equals PKGESUTILAPPS
- workspace:
- clean: outputs
+ vmImage: vs2017-win2016
+ variables:
+ skipComponentGovernanceDetection: true
steps:
- - checkout: self
- clean: true
- - task: PkgESSetupBuild@10
- displayName: Initialize Package ES
+ - task: MicrosoftTDBuild.tdbuild-task.tdbuild-task.TouchdownBuildTask@1
+ displayName: Send resources to Touchdown Build
inputs:
- productName: Calculator
- branchVersion: true
+ teamId: 86
+ authId: d3dd8113-65b3-4526-bdca-a00a7d1c37ba
+ authKey: $(LocServiceKey)
+ isPreview: false
+ relativePathRoot: src/Calculator/Resources/en-US/
+ resourceFilePath: '*.resw'
+ outputDirectoryRoot: src/Calculator/Resources/
- - task: PkgESTouchdownLocService@10
- displayName: Package ES Touchdown Loc Service
+ - script: |
+ cd $(Build.SourcesDirectory)
+ git add -A
+ git diff --cached --exit-code
+ echo '##vso[task.setvariable variable=hasChanges]%errorlevel%'
+ git diff --cached > $(Build.ArtifactStagingDirectory)\LocalizedStrings.patch
+ displayName: Check for changes and create patch file
+
+ - task: PublishPipelineArtifact@0
+ displayName: Publish patch file as artifact
+ condition: eq(variables['hasChanges'], '1')
inputs:
- IsCallToServiceStepSelected: true
- IsCheckedInFileSelected: true
- CheckinFilesAtOriginFilePath: true
- GitLocPath: Loc/Resources
- LocConfigFile: build/config/LocConfigPackageEs.xml
- AuthenticationMode: OAuth
- ClientApplicationID: d3dd8113-65b3-4526-bdca-a00a7d1c37ba
- ApplicationKeyID: $(LocServiceKey)
- SendToLoc: true
+ artifactName: Patch
+ targetPath: $(Build.ArtifactStagingDirectory)
\ No newline at end of file
diff --git a/build/pipelines/azure-pipelines.release.yaml b/build/pipelines/azure-pipelines.release.yaml
index 78b4fd90..a4507e21 100644
--- a/build/pipelines/azure-pipelines.release.yaml
+++ b/build/pipelines/azure-pipelines.release.yaml
@@ -9,8 +9,8 @@ pr: none
variables:
versionMajor: 10
- versionMinor: 1902
- versionBuild: $[counter('10.1902.*', 0)]
+ versionMinor: 1903
+ versionBuild: $[counter('10.1903.*', 0)]
versionPatch: 0
name: '$(versionMajor).$(versionMinor).$(versionBuild).$(versionPatch)'
diff --git a/build/pipelines/templates/build-app-internal.yaml b/build/pipelines/templates/build-app-internal.yaml
index 8a75dcec..2de18a01 100644
--- a/build/pipelines/templates/build-app-internal.yaml
+++ b/build/pipelines/templates/build-app-internal.yaml
@@ -29,7 +29,7 @@ jobs:
downloadDirectory: $(Build.SourcesDirectory)
vstsFeed: WindowsApps
vstsFeedPackage: calculator-internals
- vstsPackageVersion: 0.0.7
+ vstsPackageVersion: 0.0.10
- template: ./build-single-architecture.yaml
parameters:
diff --git a/build/pipelines/templates/prepare-release-internalonly.yaml b/build/pipelines/templates/prepare-release-internalonly.yaml
index 6bb3b6cb..bf302a4b 100644
--- a/build/pipelines/templates/prepare-release-internalonly.yaml
+++ b/build/pipelines/templates/prepare-release-internalonly.yaml
@@ -87,7 +87,7 @@ jobs:
downloadDirectory: $(Build.SourcesDirectory)
vstsFeed: WindowsApps
vstsFeedPackage: calculator-internals
- vstsPackageVersion: 0.0.7
+ vstsPackageVersion: 0.0.10
- task: PkgESStoreBrokerPackage@10
displayName: Create StoreBroker Packages
diff --git a/docs/Images/CalculatorScreenshot.png b/docs/Images/CalculatorScreenshot.png
index 302e66b0..a5c32e96 100644
Binary files a/docs/Images/CalculatorScreenshot.png and b/docs/Images/CalculatorScreenshot.png differ
diff --git a/docs/Images/VSInstallationScreenshot.png b/docs/Images/VSInstallationScreenshot.png
index baa85c63..30152691 100644
Binary files a/docs/Images/VSInstallationScreenshot.png and b/docs/Images/VSInstallationScreenshot.png differ
diff --git a/docs/Images/VisualStates/Converter1.gif b/docs/Images/VisualStates/Converter1.gif
index 20923f8e..f8b93a3d 100644
Binary files a/docs/Images/VisualStates/Converter1.gif and b/docs/Images/VisualStates/Converter1.gif differ
diff --git a/docs/Images/VisualStates/Scientific1.gif b/docs/Images/VisualStates/Scientific1.gif
index a797e7cd..0dc53a51 100644
Binary files a/docs/Images/VisualStates/Scientific1.gif and b/docs/Images/VisualStates/Scientific1.gif differ
diff --git a/docs/Images/VisualStates/Standard1.gif b/docs/Images/VisualStates/Standard1.gif
index 2396e8df..d3ba3a7c 100644
Binary files a/docs/Images/VisualStates/Standard1.gif and b/docs/Images/VisualStates/Standard1.gif differ
diff --git a/docs/Roadmap.md b/docs/Roadmap.md
index 93b1428e..0b969c5c 100644
--- a/docs/Roadmap.md
+++ b/docs/Roadmap.md
@@ -9,6 +9,7 @@ In 2019, the Windows Calculator team is focused on:
* Iterating upon the existing app design based on the latest [Fluent Design guidelines](https://developer.microsoft.com/en-us/windows/apps/design)
* Improving testing and diagnostics within the project
* Investigating new features with a focus on addressing top user feedback, including:
+ * Adding graphing mode
* Adding the ability for users to pin Calculator on top of other windows
* Providing additional customization options
* [Your feature idea here] - please review our [new feature development process](https://github.com/Microsoft/calculator/blob/master/docs/NewFeatureProcess.md) to get started!
diff --git a/internal/Calculator.UIAutomationLibrary/Components/Pages/MainPagePom.cs b/internal/Calculator.UIAutomationLibrary/Components/Pages/MainPagePom.cs
index aecca8f7..7fa70bb9 100644
--- a/internal/Calculator.UIAutomationLibrary/Components/Pages/MainPagePom.cs
+++ b/internal/Calculator.UIAutomationLibrary/Components/Pages/MainPagePom.cs
@@ -11,9 +11,6 @@ namespace Calculator.UIAutomationLibrary.Components
///
/// Physical Object Model for the app window.
/// POM is the implementation model of the app.
- /// See following references to POM:
- /// * https://blogs.msdn.microsoft.com/wltester/2011/11/14/object-model-design/
- /// * https://blogs.msdn.microsoft.com/micahel/2005/06/03/how-do-i-invoke-thee-let-me-count-the-ways-the-physical-object-model/
/// See https://en.wikipedia.org/wiki/Model-based_testing for model-based testing.
///
public class MainPagePom : UIObject
diff --git a/src/CalcManager/CEngine/CalcInput.cpp b/src/CalcManager/CEngine/CalcInput.cpp
index f7037aa3..4994e025 100644
--- a/src/CalcManager/CEngine/CalcInput.cpp
+++ b/src/CalcManager/CEngine/CalcInput.cpp
@@ -261,7 +261,7 @@ void CalcInput::SetDecimalSymbol(wchar_t decSymbol)
}
}
-wstring CalcInput::ToString(uint32_t radix, bool isIntegerMode)
+wstring CalcInput::ToString(uint32_t radix)
{
// In theory both the base and exponent could be C_NUM_MAX_DIGITS long.
wstringstream resStream;
diff --git a/src/CalcManager/CEngine/CalcUtils.cpp b/src/CalcManager/CEngine/CalcUtils.cpp
index d9687530..cedd59b2 100644
--- a/src/CalcManager/CEngine/CalcUtils.cpp
+++ b/src/CalcManager/CEngine/CalcUtils.cpp
@@ -3,6 +3,7 @@
#include "pch.h"
#include "Header Files/CalcEngine.h"
+#include "Header Files/CalcUtils.h"
bool IsOpInRange(WPARAM op, uint32_t x, uint32_t y)
{
diff --git a/src/CalcManager/CEngine/History.cpp b/src/CalcManager/CEngine/History.cpp
index fe14425d..e5bb746b 100644
--- a/src/CalcManager/CEngine/History.cpp
+++ b/src/CalcManager/CEngine/History.cpp
@@ -2,18 +2,25 @@
// Licensed under the MIT License.
#include "pch.h"
-#pragma once
#include "Header Files/CalcEngine.h"
#include "Command.h"
#include "CalculatorVector.h"
#include "ExpressionCommand.h"
-#include "CalcException.h"
constexpr int ASCII_0 = 48;
using namespace std;
using namespace CalcEngine;
+namespace {
+ void IFT(HRESULT hr)
+ {
+ if (FAILED(hr))
+ {
+ throw hr;
+ }
+ }
+}
void CHistoryCollector::ReinitHistory()
{
m_lastOpStartIndex = -1;
@@ -129,7 +136,7 @@ void CHistoryCollector::AddBinOpToHistory(int nOpCode, bool fNoRepetition)
}
// This is expected to be called when a binary op in the last say 1+2+ is changing to another one say 1+2* (+ changed to *)
-// It needs to know by this change a Precedence inversion happened. i.e. previous op was lower or equal to its previous op, but the new
+// It needs to know by this change a Precedence inversion happened. i.e. previous op was lower or equal to its previous op, but the new
// one isn't. (Eg. 1*2* to 1*2^). It can add explicit brackets to ensure the precedence is inverted. (Eg. (1*2) ^)
void CHistoryCollector::ChangeLastBinOp(int nOpCode, bool fPrecInvToHigher)
{
@@ -196,7 +203,7 @@ bool CHistoryCollector::FOpndAddedToHistory()
// AddUnaryOpToHistory
//
-// This is does the postfix to prefix translation of the input and adds the text to the history. Eg. doing 2 + 4 (sqrt),
+// This is does the postfix to prefix translation of the input and adds the text to the history. Eg. doing 2 + 4 (sqrt),
// this routine will ensure the last sqrt call unary operator, actually goes back in history and wraps 4 in sqrt(4)
//
void CHistoryCollector::AddUnaryOpToHistory(int nOpCode, bool fInv, ANGLE_TYPE angletype)
@@ -223,11 +230,11 @@ void CHistoryCollector::AddUnaryOpToHistory(int nOpCode, bool fInv, ANGLE_TYPE a
{
angleOpCode = CalculationManager::Command::CommandDEG;
}
- if (angletype == ANGLE_RAD)
+ else if (angletype == ANGLE_RAD)
{
angleOpCode = CalculationManager::Command::CommandRAD;
}
- if (angletype == ANGLE_GRAD)
+ else // (angletype == ANGLE_GRAD)
{
angleOpCode = CalculationManager::Command::CommandGRAD;
}
@@ -290,7 +297,7 @@ void CHistoryCollector::AddUnaryOpToHistory(int nOpCode, bool fInv, ANGLE_TYPE a
}
// Called after = with the result of the equation
-// Responsible for clearing the top line of current running history display, as well as adding yet another element to
+// Responsible for clearing the top line of current running history display, as well as adding yet another element to
// history of equations
void CHistoryCollector::CompleteHistoryLine(wstring_view numStr)
{
@@ -406,37 +413,39 @@ int CHistoryCollector::AddCommand(_In_ const std::shared_ptr
return nCommands - 1;
}
-//To Update the operands in the Expression according to the current Radix
+// To Update the operands in the Expression according to the current Radix
void CHistoryCollector::UpdateHistoryExpression(uint32_t radix, int32_t precision)
{
- if (m_spTokens != nullptr)
+ if (m_spTokens == nullptr)
{
- unsigned int size;
- IFT(m_spTokens->GetSize(&size));
+ return;
+ }
- for (unsigned int i = 0; i < size; ++i)
+ unsigned int size;
+ IFT(m_spTokens->GetSize(&size));
+
+ for (unsigned int i = 0; i < size; ++i)
+ {
+ std::pair token;
+ IFT(m_spTokens->GetAt(i, &token));
+ int commandPosition = token.second;
+ if (commandPosition != -1)
{
- std::pair token;
- IFT(m_spTokens->GetAt(i, &token));
- int commandPosition = token.second;
- if (commandPosition != -1)
+ std::shared_ptr expCommand;
+ IFT(m_spCommands->GetAt(commandPosition, &expCommand));
+ if (expCommand != nullptr && CalculationManager::CommandType::OperandCommand == expCommand->GetCommandType())
{
- std::shared_ptr expCommand;
- IFT(m_spCommands->GetAt(commandPosition, &expCommand));
- if (expCommand != nullptr && CalculationManager::CommandType::OperandCommand == expCommand->GetCommandType())
+ std::shared_ptr opndCommand = std::static_pointer_cast(expCommand);
+ if (opndCommand != nullptr)
{
- std::shared_ptr opndCommand = std::static_pointer_cast(expCommand);
- if (opndCommand != nullptr)
- {
- token.first = opndCommand->GetString(radix, precision, m_decimalSymbol);
- IFT(m_spTokens->SetAt(i, token));
- opndCommand->SetCommands(GetOperandCommandsFromString(token.first));
- }
+ token.first = opndCommand->GetString(radix, precision);
+ IFT(m_spTokens->SetAt(i, token));
+ opndCommand->SetCommands(GetOperandCommandsFromString(token.first));
}
}
}
- SetExpressionDisplay();
}
+ SetExpressionDisplay();
}
void CHistoryCollector::SetDecimalSymbol(wchar_t decimalSymbol)
@@ -444,7 +453,7 @@ void CHistoryCollector::SetDecimalSymbol(wchar_t decimalSymbol)
m_decimalSymbol = decimalSymbol;
}
-//Update the commands corresponding to the passed string Number
+// Update the commands corresponding to the passed string Number
std::shared_ptr> CHistoryCollector::GetOperandCommandsFromString(wstring_view numStr)
{
std::shared_ptr> commands = std::make_shared>();
diff --git a/src/CalcManager/CEngine/scicomm.cpp b/src/CalcManager/CEngine/scicomm.cpp
index ec40bb92..22285ea5 100644
--- a/src/CalcManager/CEngine/scicomm.cpp
+++ b/src/CalcManager/CEngine/scicomm.cpp
@@ -26,39 +26,41 @@
using namespace std;
using namespace CalcEngine;
-// NPrecedenceOfOp
-//
-// returns a virtual number for precedence for the operator. We expect binary operator only, otherwise the lowest number
-// 0 is returned. Higher the number, higher the precedence of the operator.
-INT NPrecedenceOfOp(int nopCode)
-{
- static BYTE rgbPrec[] = { 0,0, IDC_OR,0, IDC_XOR,0, IDC_AND,1,
- IDC_ADD,2, IDC_SUB,2, IDC_RSHF,3, IDC_LSHF,3,
- IDC_MOD,3, IDC_DIV,3, IDC_MUL,3, IDC_PWR,4, IDC_ROOT, 4 };
- int iPrec;
+namespace {
+ // NPrecedenceOfOp
+ //
+ // returns a virtual number for precedence for the operator. We expect binary operator only, otherwise the lowest number
+ // 0 is returned. Higher the number, higher the precedence of the operator.
+ INT NPrecedenceOfOp(int nopCode)
+ {
+ static BYTE rgbPrec[] = { 0,0, IDC_OR,0, IDC_XOR,0, IDC_AND,1,
+ IDC_ADD,2, IDC_SUB,2, IDC_RSHF,3, IDC_LSHF,3,
+ IDC_MOD,3, IDC_DIV,3, IDC_MUL,3, IDC_PWR,4, IDC_ROOT, 4 };
+ unsigned int iPrec;
- iPrec = 0;
- while ((iPrec < ARRAYSIZE(rgbPrec)) && (nopCode != rgbPrec[iPrec]))
- {
- iPrec += 2;
- }
- if (iPrec >= ARRAYSIZE(rgbPrec))
- {
iPrec = 0;
- }
- return rgbPrec[iPrec + 1];
+ while ((iPrec < size(rgbPrec)) && (nopCode != rgbPrec[iPrec]))
+ {
+ iPrec += 2;
+ }
+ if (iPrec >= size(rgbPrec))
+ {
+ iPrec = 0;
+ }
+ return rgbPrec[iPrec + 1];
+ }
}
// HandleErrorCommand
//
-// When it is discovered by the state machine that at this point the input is not valid (eg. "1+)"), we want to proceed as though this input never
+// When it is discovered by the state machine that at this point the input is not valid (eg. "1+)"), we want to proceed as though this input never
// occurred and may be some feedback to user like Beep. The rest of input can then continue by just ignoring this command.
void CCalcEngine::HandleErrorCommand(WPARAM idc)
{
if (!IsGuiSettingOpCode(idc))
{
- // we would have saved the prev command. Need to forget this state
+ // We would have saved the prev command. Need to forget this state
m_nTempCom = m_nLastCom;
}
}
@@ -126,7 +128,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
}
}
- // Toggle Record/Display mode if appropriate.
+ // Toggle Record/Display mode if appropriate.
if (m_bRecord)
{
if (IsOpInRange(wParam, IDC_AND, IDC_MMINUS) ||
@@ -180,7 +182,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
// BINARY OPERATORS:
if (IsBinOpCode(wParam))
{
- /* Change the operation if last input was operation. */
+ // Change the operation if last input was operation.
if (IsBinOpCode(m_nLastCom))
{
INT nPrev;
@@ -544,6 +546,11 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
if ((m_openParenCount >= MAXPRECDEPTH && nx) || (!m_openParenCount && !nx)
|| ((m_precedenceOpCount >= MAXPRECDEPTH && m_nPrecOp[m_precedenceOpCount - 1] != 0)))
{
+ if (!m_openParenCount && !nx)
+ {
+ m_pCalcDisplay->OnNoRightParenAdded();
+ }
+
HandleErrorCommand(wParam);
break;
}
@@ -567,7 +574,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
m_lastVal = 0;
if (IsBinOpCode(m_nLastCom))
{
- // We want 1 + ( to start as 1 + (0. Any number you type replaces 0. But if it is 1 + 3 (, it is
+ // We want 1 + ( to start as 1 + (0. Any number you type replaces 0. But if it is 1 + 3 (, it is
// treated as 1 + (3
m_currentVal = 0;
}
@@ -802,7 +809,7 @@ void CCalcEngine::CheckAndAddLastBinOpToHistory(bool addToHistory)
{
if (m_HistoryCollector.FOpndAddedToHistory())
{
- // if last time opnd was added but the last command was not a binary operator, then it must have come
+ // if last time opnd was added but the last command was not a binary operator, then it must have come
// from commands which add the operand, like unary operator. So history at this is showing 1 + sqrt(4)
// but in reality the sqrt(4) is getting replaced by new number (may be unary op, or MR or SUM etc.)
// So erase the last operand
@@ -854,7 +861,7 @@ void CCalcEngine::DisplayAnnounceBinaryOperator()
}
// Unary operator Function Name table Element
-// since unary operators button names aren't exactly friendly for history purpose,
+// since unary operators button names aren't exactly friendly for history purpose,
// we have this separate table to get its localized name and for its Inv function if it exists.
typedef struct
{
@@ -946,7 +953,7 @@ wstring_view CCalcEngine::OpCodeToUnaryString(int nOpCode, bool fInv, ANGLE_TYPE
// Try to lookup the ID in the UFNE table
int ids = 0;
int iufne = nOpCode - IDC_UNARYFIRST;
- if (iufne >= 0 && iufne < ARRAYSIZE(rgUfne))
+ if (iufne >= 0 && (size_t)iufne < size(rgUfne))
{
if (fInv)
{
@@ -1026,7 +1033,7 @@ wstring CCalcEngine::GetCurrentResultForRadix(uint32_t radix, int32_t precision)
wstring numberString = GetStringForDisplay(rat, radix);
if (!numberString.empty())
{
- //revert the precision to previously stored precision
+ // Revert the precision to previously stored precision
ChangeConstants(m_radix, m_precision);
}
diff --git a/src/CalcManager/CEngine/scidisp.cpp b/src/CalcManager/CEngine/scidisp.cpp
index f3d02453..8fe105dc 100644
--- a/src/CalcManager/CEngine/scidisp.cpp
+++ b/src/CalcManager/CEngine/scidisp.cpp
@@ -107,7 +107,7 @@ void CCalcEngine::DisplayNum(void)
if (m_bRecord)
{
// Display the string and return.
- m_numberString = m_input.ToString(m_radix, m_fIntegerMode);
+ m_numberString = m_input.ToString(m_radix);
}
else
{
diff --git a/src/CalcManager/CEngine/scifunc.cpp b/src/CalcManager/CEngine/scifunc.cpp
index 75fbbfcf..9c7ef7a3 100644
--- a/src/CalcManager/CEngine/scifunc.cpp
+++ b/src/CalcManager/CEngine/scifunc.cpp
@@ -70,7 +70,7 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r
uint64_t w64Bits = result.ToUInt64_t();
uint64_t lsb = ((w64Bits & 0x01) == 1) ? 1 : 0;
- w64Bits >>= 1; //RShift by 1
+ w64Bits >>= 1; // RShift by 1
w64Bits |= (lsb << (m_dwWordBitWidth - 1));
result = w64Bits;
diff --git a/src/CalcManager/CEngine/sciset.cpp b/src/CalcManager/CEngine/sciset.cpp
index 01dd3d3b..95451dc9 100644
--- a/src/CalcManager/CEngine/sciset.cpp
+++ b/src/CalcManager/CEngine/sciset.cpp
@@ -6,15 +6,16 @@
using namespace CalcEngine;
using namespace CalcEngine::RationalMath;
+using namespace std;
// To be called when either the radix or num width changes. You can use -1 in either of these values to mean
// dont change that.
void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwidth)
{
- // When in integer mode, the number is represented in 2's complement form. When a bit width is changing, we can
- // change the number representation back to sign, abs num form in ratpak. Soon when display sees this, it will
- // convert to 2's complement form, but this time all high bits will be propagated. Eg. -127, in byte mode is
- // represented as 1000,0001. This puts it back as sign=-1, 01111111 . But DisplayNum will see this and convert it
+ // When in integer mode, the number is represented in 2's complement form. When a bit width is changing, we can
+ // change the number representation back to sign, abs num form in ratpak. Soon when display sees this, it will
+ // convert to 2's complement form, but this time all high bits will be propagated. Eg. -127, in byte mode is
+ // represented as 1000,0001. This puts it back as sign=-1, 01111111 . But DisplayNum will see this and convert it
// back to 1111,1111,1000,0001 when in Word mode.
if (m_fIntegerMode)
{
@@ -45,7 +46,7 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwid
// inform ratpak that a change in base or precision has occurred
BaseOrPrecisionChanged();
- // display the correct number for the new state (ie convert displayed
+ // display the correct number for the new state (ie convert displayed
// number to correct base)
DisplayNum();
}
@@ -55,7 +56,7 @@ LONG CCalcEngine::DwWordBitWidthFromeNumWidth(NUM_WIDTH /*numwidth*/)
static constexpr int nBitMax[] = { 64, 32, 16, 8 };
LONG wmax = nBitMax[0];
- if (m_numwidth >= 0 && m_numwidth < ARRAYSIZE(nBitMax))
+ if (m_numwidth >= 0 && (size_t)m_numwidth < size(nBitMax))
{
wmax = nBitMax[m_numwidth];
}
@@ -68,7 +69,7 @@ uint32_t CCalcEngine::NRadixFromRadixType(RADIX_TYPE radixtype)
uint32_t radix = 10;
// convert special bases into symbolic values
- if (radixtype >= 0 && radixtype < ARRAYSIZE(rgnRadish))
+ if (radixtype >= 0 && (size_t)radixtype < size(rgnRadish))
{
radix = rgnRadish[radixtype];
}
@@ -142,7 +143,7 @@ void CCalcEngine::UpdateMaxIntDigits()
if (m_fIntegerMode)
{
m_cIntDigitsSav = static_cast(m_maxDecimalValueStrings[m_numwidth].length()) - 1;
- // This is the max digits you can enter a decimal in fixed width mode aka integer mode -1. The last digit
+ // This is the max digits you can enter a decimal in fixed width mode aka integer mode -1. The last digit
// has to be checked separately
}
else
@@ -160,10 +161,10 @@ void CCalcEngine::ChangeBaseConstants(uint32_t radix, int maxIntDigits, int32_t
{
if (10 == radix)
{
- ChangeConstants(radix, precision); // Base 10 precision for internal computing still needs to be 32, to
+ ChangeConstants(radix, precision); // Base 10 precision for internal computing still needs to be 32, to
// take care of decimals precisely. For eg. to get the HI word of a qword, we do a rsh, which depends on getting
- // 18446744073709551615 / 4294967296 = 4294967295.9999917... This is important it works this and doesn't reduce
- // the precision to number of digits allowed to enter. In other words, precision and # of allowed digits to be
+ // 18446744073709551615 / 4294967296 = 4294967295.9999917... This is important it works this and doesn't reduce
+ // the precision to number of digits allowed to enter. In other words, precision and # of allowed digits to be
// entered are different.
}
else
diff --git a/src/CalcManager/CalcException.h b/src/CalcManager/CalcException.h
deleted file mode 100644
index 60d82bbb..00000000
--- a/src/CalcManager/CalcException.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-class CalcException : std::exception
-{
-public:
- CalcException(HRESULT hr)
- {
- m_hr = hr;
- }
- HRESULT GetException()
- {
- return m_hr;
- }
-private:
- HRESULT m_hr;
-};
-
-void IFT(HRESULT hr)
-{
- if (FAILED(hr))
- {
- CalcException exception(hr);
- throw(exception);
- }
-}
diff --git a/src/CalcManager/CalcManager.vcxproj b/src/CalcManager/CalcManager.vcxproj
index 4455336c..4a098141 100644
--- a/src/CalcManager/CalcManager.vcxproj
+++ b/src/CalcManager/CalcManager.vcxproj
@@ -155,6 +155,8 @@
true
/Zm250 /await /std:c++17 /permissive- /Zc:twoPhase- %(AdditionalOptions)
$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)
+ Level4
+ true
Console
@@ -169,6 +171,8 @@
true
/Zm250 /await /std:c++17 /permissive- /Zc:twoPhase- %(AdditionalOptions)
$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)
+ Level4
+ true
Console
@@ -183,6 +187,8 @@
true
/Zm250 /await /std:c++17 /permissive- /Zc:twoPhase- %(AdditionalOptions)
$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)
+ Level4
+ true
Console
@@ -197,6 +203,8 @@
true
/Zm250 /await /std:c++17 /permissive- /Zc:twoPhase- %(AdditionalOptions)
$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)
+ Level4
+ true
Console
@@ -212,6 +220,8 @@
/Zm250 /await /std:c++17 /permissive- /Zc:twoPhase- %(AdditionalOptions)
_UNICODE;UNICODE;%(PreprocessorDefinitions)
$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)
+ Level4
+ true
Console
@@ -226,6 +236,8 @@
true
/Zm250 /await /std:c++17 /permissive- /Zc:twoPhase- %(AdditionalOptions)
$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)
+ Level4
+ true
Console
@@ -240,6 +252,8 @@
true
/Zm250 /await /std:c++17 /permissive- /Zc:twoPhase- %(AdditionalOptions)
$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)
+ Level4
+ true
Console
@@ -254,6 +268,8 @@
true
/Zm250 /await /std:c++17 /permissive- /Zc:twoPhase- %(AdditionalOptions)
$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)
+ Level4
+ true
Console
diff --git a/src/CalcManager/CalcManager.vcxproj.filters b/src/CalcManager/CalcManager.vcxproj.filters
index 5ceff3e3..2ca11666 100644
--- a/src/CalcManager/CalcManager.vcxproj.filters
+++ b/src/CalcManager/CalcManager.vcxproj.filters
@@ -119,7 +119,6 @@
RatPack
-
Header Files
@@ -136,9 +135,6 @@
Header Files
-
- Header Files
-
@@ -165,4 +161,4 @@
Header Files
-
\ No newline at end of file
+
diff --git a/src/CalcManager/CalculatorHistory.cpp b/src/CalcManager/CalculatorHistory.cpp
index a34ca272..31a1dae2 100644
--- a/src/CalcManager/CalculatorHistory.cpp
+++ b/src/CalcManager/CalculatorHistory.cpp
@@ -7,8 +7,7 @@
using namespace std;
using namespace CalculationManager;
-CalculatorHistory::CalculatorHistory(CALCULATOR_MODE eMode, size_t maxSize) :
- m_mode(eMode),
+CalculatorHistory::CalculatorHistory(size_t maxSize) :
m_maxHistorySize(maxSize)
{}
@@ -23,7 +22,7 @@ unsigned int CalculatorHistory::AddToHistory(_In_ shared_ptrGetString(&generatedExpression);
- // Prefixing and suffixing the special Unicode markers to ensure that the expression
+ // Prefixing and suffixing the special Unicode markers to ensure that the expression
// in the history doesn't get broken for RTL languages
spHistoryItem->historyItemVector.expression = L'\u202d' + generatedExpression + L'\u202c';
spHistoryItem->historyItemVector.result = wstring(result);
@@ -35,15 +34,13 @@ unsigned int CalculatorHistory::AddToHistory(_In_ shared_ptr const &spHistoryItem)
{
- int lastIndex;
-
if (m_historyItems.size() >= m_maxHistorySize)
{
m_historyItems.erase(m_historyItems.begin());
}
m_historyItems.push_back(spHistoryItem);
- lastIndex = static_cast(m_historyItems.size() - 1);
+ unsigned int lastIndex = static_cast(m_historyItems.size() - 1);
return lastIndex;
}
diff --git a/src/CalcManager/CalculatorHistory.h b/src/CalcManager/CalculatorHistory.h
index aececbda..8116e9e4 100644
--- a/src/CalcManager/CalculatorHistory.h
+++ b/src/CalcManager/CalculatorHistory.h
@@ -31,7 +31,7 @@ namespace CalculationManager
{
public:
- CalculatorHistory(CALCULATOR_MODE eMode, const size_t maxSize);
+ CalculatorHistory(const size_t maxSize);
unsigned int AddToHistory(_In_ std::shared_ptr>> const &spTokens, _In_ std::shared_ptr>> const &spCommands, std::wstring_view result);
std::vector> const& GetHistory();
std::shared_ptr const& GetHistoryItem(unsigned int uIdx);
@@ -43,7 +43,6 @@ namespace CalculationManager
private:
std::vector> m_historyItems;
- CALCULATOR_MODE m_mode;
const size_t m_maxHistorySize;
};
}
diff --git a/src/CalcManager/CalculatorManager.cpp b/src/CalcManager/CalculatorManager.cpp
index 7b84dec7..a4430482 100644
--- a/src/CalcManager/CalculatorManager.cpp
+++ b/src/CalcManager/CalculatorManager.cpp
@@ -24,16 +24,16 @@ namespace CalculationManager
{
CalculatorManager::CalculatorManager(_In_ ICalcDisplay* displayCallback, _In_ IResourceProvider* resourceProvider) :
m_displayCallback(displayCallback),
+ m_currentCalculatorEngine(nullptr),
m_resourceProvider(resourceProvider),
- m_currentDegreeMode(Command::CommandNULL),
- m_savedDegreeMode(Command::CommandDEG),
+ m_inHistoryItemLoadMode(false),
+ m_persistedPrimaryValue(),
m_isExponentialFormat(false),
m_isAutoExponentialFormat(true),
- m_persistedPrimaryValue(),
- m_currentCalculatorEngine(nullptr),
- m_pStdHistory(new CalculatorHistory(CM_STD, MAX_HISTORY_ITEMS)),
- m_pSciHistory(new CalculatorHistory(CM_SCI, MAX_HISTORY_ITEMS)),
- m_inHistoryItemLoadMode(false)
+ m_currentDegreeMode(Command::CommandNULL),
+ m_savedDegreeMode(Command::CommandDEG),
+ m_pStdHistory(new CalculatorHistory(MAX_HISTORY_ITEMS)),
+ m_pSciHistory(new CalculatorHistory(MAX_HISTORY_ITEMS))
{
CCalcEngine::InitialOneTimeOnlySetup(*m_resourceProvider);
}
@@ -110,7 +110,6 @@ namespace CalculationManager
///
/// Callback from the engine
- /// Used to set the current unmatched open parenthesis count
///
/// string containing the parenthesis count
void CalculatorManager::SetParenDisplayText(const wstring& parenthesisCount)
@@ -118,6 +117,14 @@ namespace CalculationManager
m_displayCallback->SetParenDisplayText(parenthesisCount);
}
+ ///
+ /// Callback from the engine
+ ///
+ void CalculatorManager::OnNoRightParenAdded()
+ {
+ m_displayCallback->OnNoRightParenAdded();
+ }
+
///
/// Reset CalculatorManager.
/// Set the mode to the standard calculator
@@ -289,11 +296,12 @@ namespace CalculationManager
m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandINV));
m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandTANH));
break;
- case Command::CommandFE:
- m_isExponentialFormat = !m_isExponentialFormat;
case Command::CommandAE:
m_isAutoExponentialFormat = !m_isAutoExponentialFormat;
- // fall through
+ break;
+ case Command::CommandFE:
+ m_isExponentialFormat = !m_isExponentialFormat;
+ [[fallthrough]];
default:
m_currentCalculatorEngine->ProcessCommand(static_cast(command));
break;
@@ -301,7 +309,7 @@ namespace CalculationManager
}
///
- /// Convert Command to unsigned char.
+ /// Convert Command to unsigned char.
/// Since some Commands are higher than 255, they are saved after subtracting 255
/// The smallest Command is CommandSIGN = 80, thus, subtracted value does not overlap with other values.
///
@@ -309,7 +317,10 @@ namespace CalculationManager
unsigned char CalculatorManager::MapCommandForSerialize(Command command)
{
unsigned int commandToSave = static_cast(command);
- commandToSave > UCHAR_MAX ? commandToSave -= UCHAR_MAX : commandToSave;
+ if (commandToSave > UCHAR_MAX)
+ {
+ commandToSave -= UCHAR_MAX;
+ }
return static_cast(commandToSave);
}
@@ -361,7 +372,7 @@ namespace CalculationManager
/// Serialized Rational of primary display
void CalculatorManager::DeSerializePrimaryDisplay(const vector &serializedPrimaryDisplay)
{
- if (serializedPrimaryDisplay.size() == 0)
+ if (serializedPrimaryDisplay.empty())
{
return;
}
@@ -436,9 +447,9 @@ namespace CalculationManager
if (*commandItr >= MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::MemorizeNumber) &&
*commandItr <= MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::MemorizedNumberClearAll))
{
- //MemoryCommands(which have values above 255) are pushed on m_savedCommands upon casting to unsigned char.
- //SerializeCommands uses m_savedCommands, which is then used in DeSerializeCommands.
- //Hence, a simple cast to MemoryCommand is not sufficient.
+ // MemoryCommands(which have values above 255) are pushed on m_savedCommands upon casting to unsigned char.
+ // SerializeCommands uses m_savedCommands, which is then used in DeSerializeCommands.
+ // Hence, a simple cast to MemoryCommand is not sufficient.
MemoryCommand memoryCommand = static_cast(*commandItr + UCHAR_MAX + 1);
unsigned int indexOfMemory = 0;
switch (memoryCommand)
@@ -491,22 +502,25 @@ namespace CalculationManager
void CalculatorManager::MemorizeNumber()
{
m_savedCommands.push_back(MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::MemorizeNumber));
- if (!(m_currentCalculatorEngine->FInErrorState()))
+
+ if (m_currentCalculatorEngine->FInErrorState())
{
- m_currentCalculatorEngine->ProcessCommand(IDC_STORE);
-
- auto memoryObjectPtr = m_currentCalculatorEngine->PersistedMemObject();
- if (memoryObjectPtr != nullptr)
- {
- m_memorizedNumbers.insert(m_memorizedNumbers.begin(), *memoryObjectPtr);
- }
-
- if (m_memorizedNumbers.size() > m_maximumMemorySize)
- {
- m_memorizedNumbers.resize(m_maximumMemorySize);
- }
- this->SetMemorizedNumbersString();
+ return;
}
+
+ m_currentCalculatorEngine->ProcessCommand(IDC_STORE);
+
+ auto memoryObjectPtr = m_currentCalculatorEngine->PersistedMemObject();
+ if (memoryObjectPtr != nullptr)
+ {
+ m_memorizedNumbers.insert(m_memorizedNumbers.begin(), *memoryObjectPtr);
+ }
+
+ if (m_memorizedNumbers.size() > m_maximumMemorySize)
+ {
+ m_memorizedNumbers.resize(m_maximumMemorySize);
+ }
+ this->SetMemorizedNumbersString();
}
///
@@ -517,11 +531,14 @@ namespace CalculationManager
void CalculatorManager::MemorizedNumberLoad(_In_ unsigned int indexOfMemory)
{
SaveMemoryCommand(MemoryCommand::MemorizedNumberLoad, indexOfMemory);
- if (!(m_currentCalculatorEngine->FInErrorState()))
+
+ if (m_currentCalculatorEngine->FInErrorState())
{
- this->MemorizedNumberSelect(indexOfMemory);
- m_currentCalculatorEngine->ProcessCommand(IDC_RECALL);
+ return;
}
+
+ this->MemorizedNumberSelect(indexOfMemory);
+ m_currentCalculatorEngine->ProcessCommand(IDC_RECALL);
}
///
@@ -533,24 +550,27 @@ namespace CalculationManager
void CalculatorManager::MemorizedNumberAdd(_In_ unsigned int indexOfMemory)
{
SaveMemoryCommand(MemoryCommand::MemorizedNumberAdd, indexOfMemory);
- if (!(m_currentCalculatorEngine->FInErrorState()))
+
+ if (m_currentCalculatorEngine->FInErrorState())
{
- if (m_memorizedNumbers.empty())
- {
- this->MemorizeNumber();
- }
- else
- {
- this->MemorizedNumberSelect(indexOfMemory);
- m_currentCalculatorEngine->ProcessCommand(IDC_MPLUS);
-
- this->MemorizedNumberChanged(indexOfMemory);
-
- this->SetMemorizedNumbersString();
- }
-
- m_displayCallback->MemoryItemChanged(indexOfMemory);
+ return;
}
+
+ if (m_memorizedNumbers.empty())
+ {
+ this->MemorizeNumber();
+ }
+ else
+ {
+ this->MemorizedNumberSelect(indexOfMemory);
+ m_currentCalculatorEngine->ProcessCommand(IDC_MPLUS);
+
+ this->MemorizedNumberChanged(indexOfMemory);
+
+ this->SetMemorizedNumbersString();
+ }
+
+ m_displayCallback->MemoryItemChanged(indexOfMemory);
}
void CalculatorManager::MemorizedNumberClear(_In_ unsigned int indexOfMemory)
@@ -571,27 +591,30 @@ namespace CalculationManager
void CalculatorManager::MemorizedNumberSubtract(_In_ unsigned int indexOfMemory)
{
SaveMemoryCommand(MemoryCommand::MemorizedNumberSubtract, indexOfMemory);
- if (!(m_currentCalculatorEngine->FInErrorState()))
+
+ if (m_currentCalculatorEngine->FInErrorState())
{
- // To add negative of the number on display to the memory -x = x - 2x
- if (m_memorizedNumbers.empty())
- {
- this->MemorizeNumber();
- this->MemorizedNumberSubtract(0);
- this->MemorizedNumberSubtract(0);
- }
- else
- {
- this->MemorizedNumberSelect(indexOfMemory);
- m_currentCalculatorEngine->ProcessCommand(IDC_MMINUS);
-
- this->MemorizedNumberChanged(indexOfMemory);
-
- this->SetMemorizedNumbersString();
- }
-
- m_displayCallback->MemoryItemChanged(indexOfMemory);
+ return;
}
+
+ // To add negative of the number on display to the memory -x = x - 2x
+ if (m_memorizedNumbers.empty())
+ {
+ this->MemorizeNumber();
+ this->MemorizedNumberSubtract(0);
+ this->MemorizedNumberSubtract(0);
+ }
+ else
+ {
+ this->MemorizedNumberSelect(indexOfMemory);
+ m_currentCalculatorEngine->ProcessCommand(IDC_MMINUS);
+
+ this->MemorizedNumberChanged(indexOfMemory);
+
+ this->SetMemorizedNumbersString();
+ }
+
+ m_displayCallback->MemoryItemChanged(indexOfMemory);
}
///
@@ -614,11 +637,13 @@ namespace CalculationManager
/// Index of the target memory
void CalculatorManager::MemorizedNumberSelect(_In_ unsigned int indexOfMemory)
{
- if (!(m_currentCalculatorEngine->FInErrorState()))
+ if (m_currentCalculatorEngine->FInErrorState())
{
- auto memoryObject = m_memorizedNumbers.at(indexOfMemory);
- m_currentCalculatorEngine->PersistedMemObject(memoryObject);
+ return;
}
+
+ auto memoryObject = m_memorizedNumbers.at(indexOfMemory);
+ m_currentCalculatorEngine->PersistedMemObject(memoryObject);
}
///
@@ -628,13 +653,15 @@ namespace CalculationManager
/// Index of the target memory
void CalculatorManager::MemorizedNumberChanged(_In_ unsigned int indexOfMemory)
{
- if (!(m_currentCalculatorEngine->FInErrorState()))
+ if (m_currentCalculatorEngine->FInErrorState())
{
- auto memoryObject = m_currentCalculatorEngine->PersistedMemObject();
- if (memoryObject != nullptr)
- {
- m_memorizedNumbers.at(indexOfMemory) = *memoryObject;
- }
+ return;
+ }
+
+ auto memoryObject = m_currentCalculatorEngine->PersistedMemObject();
+ if (memoryObject != nullptr)
+ {
+ m_memorizedNumbers.at(indexOfMemory) = *memoryObject;
}
}
@@ -762,7 +789,7 @@ namespace CalculationManager
}
void CalculatorManager::UpdateMaxIntDigits()
- {
+ {
m_currentCalculatorEngine->UpdateMaxIntDigits();
}
@@ -786,7 +813,7 @@ namespace CalculationManager
/// How Rational is serialized :
/// Serialized Rational.P(Number) + Serialized Rational.Q(Number)
/// How Number is saved :
- /// [0] = Rational.P.Sign
+ /// [0] = Rational.P.Sign
/// [1] = Rational.P.Mantissa.size
/// [2] = Rational.P.Exp
/// [3] = Rational.P.Mantissa[0]
@@ -824,7 +851,7 @@ namespace CalculationManager
///
/// Serialize Number to vector of long
/// How Number is saved :
- /// [0] = Number.Sign
+ /// [0] = Number.Sign
/// [1] = Number.Mantissa.size
/// [2] = Number.Exp
/// [3] = Number.Mantissa[0]
@@ -851,7 +878,7 @@ namespace CalculationManager
///
/// DeserializeNumber vector and construct a Number
/// How Number is saved :
- /// [0] = Number.Sign
+ /// [0] = Number.Sign
/// [1] = Number.Mantissa.size
/// [2] = Number.Exp
/// [3] = Number.Mantissa[0]
diff --git a/src/CalcManager/CalculatorManager.h b/src/CalcManager/CalculatorManager.h
index 3d2fbe59..53735389 100644
--- a/src/CalcManager/CalculatorManager.h
+++ b/src/CalcManager/CalculatorManager.h
@@ -27,9 +27,9 @@ namespace CalculationManager
ProgrammerModePrecision = 64
};
- // Numbering continues from the Enum Command from Command.h
+ // Numbering continues from the Enum Command from Command.h
// with some gap to ensure there is no overlap of these ids
- // when static_cast is performed on these ids
+ // when static_cast is performed on these ids
// they shouldn't fall in any number range greater than 80. So never
// make the memory command ids go below 330
enum class MemoryCommand
@@ -42,7 +42,7 @@ namespace CalculationManager
MemorizedNumberClear = 335
};
- class CalculatorManager sealed : public virtual ICalcDisplay
+ class CalculatorManager final : public ICalcDisplay
{
private:
ICalcDisplay* const m_displayCallback;
@@ -95,7 +95,8 @@ namespace CalculationManager
void SetExpressionDisplay(_Inout_ std::shared_ptr>> const &tokens, _Inout_ std::shared_ptr>> const &commands) override;
void SetMemorizedNumbers(_In_ const std::vector& memorizedNumbers) override;
void OnHistoryItemAdded(_In_ unsigned int addedItemIndex) override;
- void SetParenDisplayText(const std::wstring& parenthesisCount);
+ void SetParenDisplayText(const std::wstring& parenthesisCount) override;
+ void OnNoRightParenAdded() override;
void DisplayPasteError();
void MaxDigitsReached() override;
void BinaryOperatorReceived() override;
@@ -141,7 +142,7 @@ namespace CalculationManager
std::shared_ptr const& GetHistoryItem(_In_ unsigned int uIdx);
bool RemoveHistoryItem(_In_ unsigned int uIdx);
void ClearHistory();
- const size_t MaxHistorySize() const { return m_pHistory->MaxHistorySize(); }
+ size_t MaxHistorySize() const { return m_pHistory->MaxHistorySize(); }
CalculationManager::Command GetCurrentDegreeMode();
void SetHistory(_In_ CALCULATOR_MODE eMode, _In_ std::vector> const& history);
void SetInHistoryItemLoadMode(_In_ bool isHistoryItemLoadMode);
diff --git a/src/CalcManager/CalculatorResource.h b/src/CalcManager/CalculatorResource.h
index 51bdd8b6..3493234a 100644
--- a/src/CalcManager/CalculatorResource.h
+++ b/src/CalcManager/CalculatorResource.h
@@ -10,7 +10,7 @@ namespace CalculationManager
public:
virtual ~IResourceProvider() { }
- // Should return a string from the resource table for strings used
+ // Should return a string from the resource table for strings used
// by the calculation engine. The strings that must be defined
// and the ids to define them with can be seen in EngineStrings.h
// with SIDS prefix. Additionally it must provide values for string
diff --git a/src/CalcManager/CalculatorVector.h b/src/CalcManager/CalculatorVector.h
index 9e8c1a72..7fad7e7d 100644
--- a/src/CalcManager/CalculatorVector.h
+++ b/src/CalcManager/CalculatorVector.h
@@ -4,7 +4,7 @@
#pragma once
template
-class CalculatorVector
+class CalculatorVector
{
public:
HRESULT GetAt(_In_opt_ unsigned int index, _Out_ TType *item)
diff --git a/src/CalcManager/Command.h b/src/CalcManager/Command.h
index 390cc5b3..5655b696 100644
--- a/src/CalcManager/Command.h
+++ b/src/CalcManager/Command.h
@@ -94,7 +94,7 @@ namespace CalculationManager
CommandFAC = 113,
CommandREC = 114,
CommandDMS = 115,
- CommandCUBEROOT = 116, //x ^ 1/3
+ CommandCUBEROOT = 116, // x ^ 1/3
CommandPOW10 = 117, // 10 ^ x
CommandPERCENT = 118,
diff --git a/src/CalcManager/ExpressionCommand.cpp b/src/CalcManager/ExpressionCommand.cpp
index fec86d0b..78b4f6ac 100644
--- a/src/CalcManager/ExpressionCommand.cpp
+++ b/src/CalcManager/ExpressionCommand.cpp
@@ -75,19 +75,19 @@ void CUnaryCommand::Accept(_In_ ISerializeCommandVisitor &commandVisitor)
CBinaryCommand::CBinaryCommand(int command) :m_command(command)
{}
-void CBinaryCommand::SetCommand(int command)
-{
- m_command = command;
+void CBinaryCommand::SetCommand(int command)
+{
+ m_command = command;
}
int CBinaryCommand::GetCommand() const
-{
- return m_command;
+{
+ return m_command;
}
CalculationManager::CommandType CBinaryCommand::GetCommandType() const
-{
- return CalculationManager::CommandType::BinaryCommand;
+{
+ return CalculationManager::CommandType::BinaryCommand;
}
void CBinaryCommand::Accept(_In_ ISerializeCommandVisitor &commandVisitor)
@@ -98,8 +98,8 @@ void CBinaryCommand::Accept(_In_ ISerializeCommandVisitor &commandVisitor)
COpndCommand::COpndCommand(shared_ptr> const &commands, bool fNegative, bool fDecimal, bool fSciFmt) :
m_commands(commands),
m_fNegative(fNegative),
- m_fDecimal(fDecimal),
m_fSciFmt(fSciFmt),
+ m_fDecimal(fDecimal),
m_fInitialized(false),
m_value{}
{}
@@ -111,8 +111,8 @@ void COpndCommand::Initialize(Rational const& rat)
}
const shared_ptr> & COpndCommand::GetCommands() const
-{
- return m_commands;
+{
+ return m_commands;
}
void COpndCommand::SetCommands(shared_ptr> const& commands)
@@ -135,7 +135,7 @@ void COpndCommand::AppendCommand(int command)
if (command == IDC_PNT)
{
m_fDecimal = true;
-}
+ }
}
void COpndCommand::ToggleSign()
@@ -166,7 +166,7 @@ void COpndCommand::RemoveFromEnd()
{
unsigned int nCommands;
m_commands->GetSize(&nCommands);
-
+
if (nCommands == 1)
{
ClearAllAndAppendCommand(CalculationManager::Command::Command0);
@@ -178,15 +178,15 @@ void COpndCommand::RemoveFromEnd()
if (nOpCode == IDC_PNT)
{
m_fDecimal = false;
- }
+ }
m_commands->RemoveAt(nCommands - 1);
+ }
}
}
-}
bool COpndCommand::IsNegative() const
-{
- return m_fNegative;
+{
+ return m_fNegative;
}
bool COpndCommand::IsSciFmt() const
@@ -195,13 +195,13 @@ bool COpndCommand::IsSciFmt() const
}
bool COpndCommand::IsDecimalPresent() const
-{
- return m_fDecimal;
+{
+ return m_fDecimal;
}
CalculationManager::CommandType COpndCommand::GetCommandType() const
-{
- return CalculationManager::CommandType::OperandCommand;
+{
+ return CalculationManager::CommandType::OperandCommand;
}
void COpndCommand::ClearAllAndAppendCommand(CalculationManager::Command command)
@@ -283,11 +283,11 @@ const wstring & COpndCommand::GetToken(wchar_t decimalSymbol)
m_token.clear();
m_token.append(&chZero);
}
-
+
return m_token;
}
-wstring COpndCommand::GetString(uint32_t radix, int32_t precision, wchar_t decimalSymbol)
+wstring COpndCommand::GetString(uint32_t radix, int32_t precision)
{
wstring result{};
@@ -303,4 +303,3 @@ void COpndCommand::Accept(_In_ ISerializeCommandVisitor &commandVisitor)
{
commandVisitor.Visit(*this);
}
-
diff --git a/src/CalcManager/ExpressionCommand.h b/src/CalcManager/ExpressionCommand.h
index 275c8da3..2958f4f8 100644
--- a/src/CalcManager/ExpressionCommand.h
+++ b/src/CalcManager/ExpressionCommand.h
@@ -10,9 +10,9 @@ class CParentheses final : public IParenthesisCommand
{
public:
CParentheses(_In_ int command);
- int GetCommand() const;
- CalculationManager::CommandType GetCommandType() const;
- void Accept(_In_ ISerializeCommandVisitor &commandVisitor);
+ int GetCommand() const override;
+ CalculationManager::CommandType GetCommandType() const override;
+ void Accept(_In_ ISerializeCommandVisitor &commandVisitor) override;
private:
int m_command;
@@ -23,11 +23,11 @@ class CUnaryCommand final : public IUnaryCommand
public:
CUnaryCommand(int command);
CUnaryCommand(int command1, int command2);
- const std::shared_ptr> & GetCommands() const;
- CalculationManager::CommandType GetCommandType() const;
- void SetCommand(int command);
- void SetCommands(int command1, int command2);
- void Accept(_In_ ISerializeCommandVisitor &commandVisitor);
+ const std::shared_ptr> & GetCommands() const override;
+ CalculationManager::CommandType GetCommandType() const override;
+ void SetCommand(int command) override;
+ void SetCommands(int command1, int command2) override;
+ void Accept(_In_ ISerializeCommandVisitor &commandVisitor) override;
private:
std::shared_ptr> m_command;
@@ -37,10 +37,10 @@ class CBinaryCommand final : public IBinaryCommand
{
public:
CBinaryCommand(int command);
- void SetCommand(int command);
- int GetCommand() const;
- CalculationManager::CommandType GetCommandType() const;
- void Accept(_In_ ISerializeCommandVisitor &commandVisitor);
+ void SetCommand(int command) override;
+ int GetCommand() const override;
+ CalculationManager::CommandType GetCommandType() const override;
+ void Accept(_In_ ISerializeCommandVisitor &commandVisitor) override;
private:
int m_command;
@@ -56,18 +56,18 @@ public:
bool fSciFmt);
void Initialize(CalcEngine::Rational const& rat);
- const std::shared_ptr> & GetCommands() const;
- void SetCommands(std::shared_ptr> const& commands);
- void AppendCommand(int command);
- void ToggleSign();
- void RemoveFromEnd();
- bool IsNegative() const;
- bool IsSciFmt() const;
- bool IsDecimalPresent() const;
- const std::wstring & GetToken(wchar_t decimalSymbol);
- CalculationManager::CommandType GetCommandType() const;
- void Accept(_In_ ISerializeCommandVisitor &commandVisitor);
- std::wstring GetString(uint32_t radix, int32_t precision, wchar_t decimalSymbol);
+ const std::shared_ptr> & GetCommands() const override;
+ void SetCommands(std::shared_ptr> const& commands) override;
+ void AppendCommand(int command) override;
+ void ToggleSign() override;
+ void RemoveFromEnd() override;
+ bool IsNegative() const override;
+ bool IsSciFmt() const override;
+ bool IsDecimalPresent() const override;
+ const std::wstring & GetToken(wchar_t decimalSymbol) override;
+ CalculationManager::CommandType GetCommandType() const override;
+ void Accept(_In_ ISerializeCommandVisitor &commandVisitor) override;
+ std::wstring GetString(uint32_t radix, int32_t precision);
private:
std::shared_ptr> m_commands;
diff --git a/src/CalcManager/ExpressionCommandInterface.h b/src/CalcManager/ExpressionCommandInterface.h
index bf19bf2f..ce89dd81 100644
--- a/src/CalcManager/ExpressionCommandInterface.h
+++ b/src/CalcManager/ExpressionCommandInterface.h
@@ -30,7 +30,7 @@ public:
class IBinaryCommand : public IOperatorCommand
{
public:
- virtual void SetCommand(int command) = 0;
+ virtual void SetCommand(int command) override = 0;
virtual int GetCommand() const = 0;
};
diff --git a/src/CalcManager/Header Files/CCommand.h b/src/CalcManager/Header Files/CCommand.h
index 33ba6501..1ebf122d 100644
--- a/src/CalcManager/Header Files/CCommand.h
+++ b/src/CalcManager/Header Files/CCommand.h
@@ -45,7 +45,7 @@
// Key IDs:
-// These id's must be consecutive from IDC_FIRSTCONTROL to IDC_LASTCONTROL.
+// These id's must be consecutive from IDC_FIRSTCONTROL to IDC_LASTCONTROL.
// The actual values don't matter but the order and sequence are very important.
// Also, the order of the controls must match the order of the control names
// in the string table.
@@ -97,7 +97,7 @@
#define IDC_FAC 113
#define IDC_REC 114
#define IDC_DMS 115
-#define IDC_CUBEROOT 116 //x ^ 1/3
+#define IDC_CUBEROOT 116 // x ^ 1/3
#define IDC_POW10 117 // 10 ^ x
#define IDC_PERCENT 118
#define IDC_UNARYLAST IDC_PERCENT
diff --git a/src/CalcManager/Header Files/CalcEngine.h b/src/CalcManager/Header Files/CalcEngine.h
index 611036a1..db9dd631 100644
--- a/src/CalcManager/Header Files/CalcEngine.h
+++ b/src/CalcManager/Header Files/CalcEngine.h
@@ -85,7 +85,7 @@ private:
// if it hasn't yet been computed
bool m_bChangeOp; /* Flag for changing operation. */
bool m_bRecord; // Global mode: recording or displaying
- bool m_bSetCalcState; //Flag for setting the engine result state
+ bool m_bSetCalcState; // Flag for setting the engine result state
CalcEngine::CalcInput m_input; // Global calc input object for decimal strings
eNUMOBJ_FMT m_nFE; /* Scientific notation conversion flag. */
eNUMOBJ_AUTOFMT m_nAE; /* Automatic scientific notation conversion flag. */
diff --git a/src/CalcManager/Header Files/CalcInput.h b/src/CalcManager/Header Files/CalcInput.h
index 0f86f4f5..60d628c1 100644
--- a/src/CalcManager/Header Files/CalcInput.h
+++ b/src/CalcManager/Header Files/CalcInput.h
@@ -6,7 +6,7 @@
#include "Rational.h"
// Space to hold enough digits for a quadword binary number (64) plus digit separator strings for that number (20)
-constexpr int MAX_STRLEN = 84;
+constexpr int MAX_STRLEN = 84;
namespace CalcEngine
{
@@ -22,7 +22,7 @@ namespace CalcEngine
bool IsEmpty() { return value.empty(); }
bool IsNegative() { return m_isNegative; }
- void IsNegative(bool value) { m_isNegative = value; }
+ void IsNegative(bool isNegative) { m_isNegative = isNegative; }
std::wstring value;
@@ -53,7 +53,7 @@ namespace CalcEngine
bool TryBeginExponent();
void Backspace();
void SetDecimalSymbol(wchar_t decSymbol);
- std::wstring ToString(uint32_t radix, bool isIntegerMode);
+ std::wstring ToString(uint32_t radix);
Rational ToRational(uint32_t radix, int32_t precision);
private:
diff --git a/src/CalcManager/Header Files/EngineStrings.h b/src/CalcManager/Header Files/EngineStrings.h
index 7a420c8c..2ada6bba 100644
--- a/src/CalcManager/Header Files/EngineStrings.h
+++ b/src/CalcManager/Header Files/EngineStrings.h
@@ -128,7 +128,7 @@
#define SIDS_NFACTORIAL L"33"
#define SIDS_RECIPROCAL L"34"
#define SIDS_DMS L"35"
-#define SIDS_CUBEROOT L"36"
+#define SIDS_CUBEROOT L"36"
#define SIDS_POWTEN L"37"
#define SIDS_PERCENT L"38"
#define SIDS_SCIENTIFIC_NOTATION L"39"
@@ -200,7 +200,7 @@
#define SIDS_NOMEM L"105"
#define SIDS_TOOMANY L"106"
#define SIDS_OVERFLOW L"107"
-#define SIDS_NORESULT L"108"
+#define SIDS_NORESULT L"108"
#define SIDS_INSUFFICIENT_DATA L"109"
// 110 is skipped by CSTRINGSENGMAX
#define SIDS_ERR_UNK_CH L"111"
@@ -214,7 +214,7 @@
#define SIDS_ERR_INPUT_OVERFLOW L"119"
#define SIDS_ERR_OUTPUT_OVERFLOW L"120"
-__declspec(selectany) std::wstring g_sids[] =
+__declspec(selectany) std::wstring g_sids[] =
{
std::wstring(SIDS_PLUS_MINUS),
std::wstring(SIDS_C),
@@ -252,7 +252,7 @@ __declspec(selectany) std::wstring g_sids[] =
std::wstring(SIDS_NFACTORIAL),
std::wstring(SIDS_RECIPROCAL),
std::wstring(SIDS_DMS),
- std::wstring(SIDS_CUBEROOT),
+ std::wstring(SIDS_CUBEROOT),
std::wstring(SIDS_POWTEN),
std::wstring(SIDS_PERCENT),
std::wstring(SIDS_SCIENTIFIC_NOTATION),
@@ -324,7 +324,7 @@ __declspec(selectany) std::wstring g_sids[] =
std::wstring(SIDS_NOMEM),
std::wstring(SIDS_TOOMANY),
std::wstring(SIDS_OVERFLOW),
- std::wstring(SIDS_NORESULT),
+ std::wstring(SIDS_NORESULT),
std::wstring(SIDS_INSUFFICIENT_DATA),
std::wstring(SIDS_ERR_UNK_CH),
std::wstring(SIDS_ERR_UNK_FN),
diff --git a/src/CalcManager/Header Files/History.h b/src/CalcManager/Header Files/History.h
index c8f418cb..4f82088f 100644
--- a/src/CalcManager/Header Files/History.h
+++ b/src/CalcManager/Header Files/History.h
@@ -10,8 +10,8 @@
// maximum depth you can get by precedence. It is just an array's size limit.
static constexpr size_t MAXPRECDEPTH = 25;
-// Helper class really a internal class to CCalcEngine, to accumulate each history line of text by collecting the
-// operands, operator, unary operator etc. Since it is a separate entity, it can be unit tested on its own but does
+// Helper class really a internal class to CCalcEngine, to accumulate each history line of text by collecting the
+// operands, operator, unary operator etc. Since it is a separate entity, it can be unit tested on its own but does
// rely on CCalcEngine calling it in appropriate order.
class CHistoryCollector {
public:
@@ -39,13 +39,13 @@ private:
ICalcDisplay *m_pCalcDisplay;
int m_iCurLineHistStart; // index of the beginning of the current equation
- // a sort of state, set to the index before 2 after 2 in the expression 2 + 3 say. Useful for auto correct portion of history and for
+ // a sort of state, set to the index before 2 after 2 in the expression 2 + 3 say. Useful for auto correct portion of history and for
// attaching the unary op around the last operand
int m_lastOpStartIndex; // index of the beginning of the last operand added to the history
int m_lastBinOpStartIndex; // index of the beginning of the last binary operator added to the history
std::array m_operandIndices; // Stack of index of opnd's beginning for each '('. A parallel array to m_hnoParNum, but abstracted independently of that
int m_curOperandIndex; // Stack index for the above stack
- bool m_bLastOpndBrace; // iff the last opnd in history is already braced so we can avoid putting another one for unary operator
+ bool m_bLastOpndBrace; // iff the last opnd in history is already braced so we can avoid putting another one for unary operator
wchar_t m_decimalSymbol;
std::shared_ptr>> m_spTokens;
std::shared_ptr>> m_spCommands;
diff --git a/src/CalcManager/Header Files/ICalcDisplay.h b/src/CalcManager/Header Files/ICalcDisplay.h
index abafbc3c..2ba57e65 100644
--- a/src/CalcManager/Header Files/ICalcDisplay.h
+++ b/src/CalcManager/Header Files/ICalcDisplay.h
@@ -13,6 +13,7 @@ public:
virtual void SetIsInError(bool isInError) = 0;
virtual void SetExpressionDisplay(_Inout_ std::shared_ptr>> const &tokens, _Inout_ std::shared_ptr>> const &commands) = 0;
virtual void SetParenDisplayText(const std::wstring& pszText) = 0;
+ virtual void OnNoRightParenAdded() = 0;
virtual void MaxDigitsReached() = 0; // not an error but still need to inform UI layer.
virtual void BinaryOperatorReceived() = 0;
virtual void OnHistoryItemAdded(_In_ unsigned int addedItemIndex) = 0;
diff --git a/src/CalcManager/Ratpack/basex.cpp b/src/CalcManager/Ratpack/basex.cpp
index d36d7031..1d4a7303 100644
--- a/src/CalcManager/Ratpack/basex.cpp
+++ b/src/CalcManager/Ratpack/basex.cpp
@@ -2,17 +2,17 @@
// Licensed under the MIT License.
//-----------------------------------------------------------------------------
-// Package Title ratpak
-// File basex.c
-// Copyright (C) 1995-97 Microsoft
-// Date 03-14-97
-//
-//
-// Description
-//
-// Contains number routines for internal base computations, these assume
-// internal base is a power of 2.
-//
+// Package Title ratpak
+// File basex.c
+// Copyright (C) 1995-97 Microsoft
+// Date 03-14-97
+//
+//
+// Description
+//
+// Contains number routines for internal base computations, these assume
+// internal base is a power of 2.
+//
//-----------------------------------------------------------------------------
#include "pch.h"
#include "ratpak.h"
@@ -41,7 +41,7 @@ void __inline mulnumx( PNUMBER *pa, PNUMBER b )
{
// If b is not one we multiply
if ( (*pa)->cdigit > 1 || (*pa)->mant[0] != 1 || (*pa)->exp != 0 )
- {
+ {
// pa and b are both non-one.
_mulnumx( pa, b );
}
@@ -91,7 +91,7 @@ void _mulnumx( PNUMBER *pa, PNUMBER b )
MANTTYPE da=0; // da is the digit from the fist number.
TWO_MANTTYPE cy=0; // cy is the carry resulting from the addition of
// a multiplied row into the result.
- TWO_MANTTYPE mcy=0; // mcy is the resultant from a single
+ TWO_MANTTYPE mcy=0; // mcy is the resultant from a single
// multiply, AND the carry of that multiply.
long icdigit=0; // Index of digit being calculated in final result.
@@ -110,8 +110,8 @@ void _mulnumx( PNUMBER *pa, PNUMBER b )
{
da = *ptra++;
ptrb = b->mant;
-
- // Shift ptrc, and ptrcoffset, one for each digit
+
+ // Shift ptrc, and ptrcoffset, one for each digit
ptrc = ptrcoffset++;
for ( ibdigit = b->cdigit; ibdigit > 0; ibdigit-- )
@@ -126,28 +126,28 @@ void _mulnumx( PNUMBER *pa, PNUMBER b )
c->cdigit++;
}
}
-
+
// If result is nonzero, or while result of carry is nonzero...
while ( mcy || cy )
{
-
+
// update carry from addition(s) and multiply.
cy += (TWO_MANTTYPE)ptrc[icdigit]+((DWORD)mcy&((DWORD)~BASEX));
-
- // update result digit from
+
+ // update result digit from
ptrc[icdigit++]=(MANTTYPE)((DWORD)cy&((DWORD)~BASEX));
-
+
// update carries from
mcy >>= BASEXPWR;
cy >>= BASEXPWR;
}
-
+
ptrb++;
ptrc++;
-
+
}
}
-
+
// prevent different kinds of zeros, by stripping leading duplicate zeros.
// digits are in order of increasing significance.
while ( c->cdigit > 1 && c->mant[c->cdigit-1] == 0 )
@@ -198,7 +198,7 @@ void numpowlongx( _Inout_ PNUMBER *proot, _In_ long power )
}
destroynum( *proot );
*proot=lret;
-
+
}
void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision);
@@ -275,14 +275,14 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
a=*pa;
if ( thismax < a->cdigit )
{
- // a has more digits than precision specified, bump up digits to shoot
+ // a has more digits than precision specified, bump up digits to shoot
// for.
thismax = a->cdigit;
}
if ( thismax < b->cdigit )
{
- // b has more digits than precision specified, bump up digits to shoot
+ // b has more digits than precision specified, bump up digits to shoot
// for.
thismax = b->cdigit;
}
@@ -317,7 +317,7 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
digit *= 2;
}
if ( lessnum( rem, tmp ) )
- {
+ {
// too far, back up...
destroynum( tmp );
digit /= 2;
@@ -326,7 +326,7 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
}
tmp->sign *= -1;
- addnum( &rem, tmp, BASEX );
+ addnum( &rem, tmp, BASEX );
destroynum( tmp );
destroynum( lasttmp );
*ptrc |= digit;
@@ -341,7 +341,7 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
}
if ( !cdigits )
- {
+ {
// A zero, make sure no weird exponents creep in
c->exp = 0;
c->cdigit = 1;
@@ -350,7 +350,7 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
{
c->cdigit = cdigits;
c->exp -= cdigits;
- // prevent different kinds of zeros, by stripping leading duplicate
+ // prevent different kinds of zeros, by stripping leading duplicate
// zeros. digits are in order of increasing significance.
while ( c->cdigit > 1 && c->mant[c->cdigit-1] == 0 )
{
diff --git a/src/CalcManager/Ratpack/conv.cpp b/src/CalcManager/Ratpack/conv.cpp
index 805bc03d..7d2034d0 100644
--- a/src/CalcManager/Ratpack/conv.cpp
+++ b/src/CalcManager/Ratpack/conv.cpp
@@ -61,7 +61,7 @@ void* zmalloc(size_t a)
//
//-----------------------------------------------------------------------------
-void _dupnum(_In_ PNUMBER dest, _In_ PNUMBER src)
+void _dupnum(_In_ PNUMBER dest, _In_ const NUMBER * const src)
{
memcpy(dest, src, (int)(sizeof(NUMBER) + ((src)->cdigit)*(sizeof(MANTTYPE))));
}
@@ -566,7 +566,7 @@ wchar_t NormalizeCharDigit(wchar_t c, uint32_t radix)
// is in the range where this is not ambiguous.
if (size_t{ radix } >= DIGITS.find(L'A') && size_t { radix } <= DIGITS.find(L'Z'))
{
- return toupper(c);
+ return towupper(c);
}
return c;
@@ -612,6 +612,7 @@ PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precis
break;
}
// Drop through in the 'e'-as-a-digit case
+ [[fallthrough]];
default:
state = machine[state][NZ];
break;
@@ -646,7 +647,7 @@ PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precis
break;
case LD:
pnumret->exp++;
- // Fall through
+ [[fallthrough]];
case DD:
{
curChar = NormalizeCharDigit(curChar, radix);
@@ -801,7 +802,7 @@ PNUMBER longtonum( long inlong, uint32_t radix)
// RETURN: number
//
// DESCRIPTION: Returns a number representation in the
-// base requested of the unsigned long value passed in. Being unsigned number it has no
+// base requested of the unsigned long value passed in. Being unsigned number it has no
// negative number and takes the full range of unsigned number
//
//-----------------------------------------------------------------------------
@@ -817,7 +818,7 @@ PNUMBER Ulongtonum(unsigned long inlong, uint32_t radix)
pnumret->cdigit = 0;
pnumret->exp = 0;
pnumret->sign = 1;
-
+
do {
*pmant++ = (MANTTYPE)(inlong % radix);
inlong /= radix;
@@ -1057,10 +1058,6 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, int autoformat, uint32
length = precision;
}
- // 2 for signs, 1 for 'e'(or leading zero), 1 for dp, 1 for null and
- // 10 for maximum exponent size.
- int cchNum = (precision + 16);
-
// If there is a chance a round has to occur, round.
// - if number is zero no rounding
// - if number of digits is less than the maximum output no rounding
@@ -1274,7 +1271,7 @@ PNUMBER RatToNumber(_In_ PRAT prat, uint32_t radix, int32_t precision)
// Convert p and q of rational form from internal base to requested base.
// Scale by largest power of BASEX possible.
long scaleby = min(temprat->pp->exp, temprat->pq->exp);
- scaleby = max(scaleby, 0);
+ scaleby = max(scaleby, 0l);
temprat->pp->exp -= scaleby;
temprat->pq->exp -= scaleby;
diff --git a/src/CalcManager/Ratpack/exp.cpp b/src/CalcManager/Ratpack/exp.cpp
index 97d02c6b..8e0e58af 100644
--- a/src/CalcManager/Ratpack/exp.cpp
+++ b/src/CalcManager/Ratpack/exp.cpp
@@ -46,8 +46,8 @@ void _exprat( PRAT *px, int32_t precision)
{
CREATETAYLOR();
- addnum(&(pret->pp),num_one, BASEX);
- addnum(&(pret->pq),num_one, BASEX);
+ addnum(&(pret->pp),num_one, BASEX);
+ addnum(&(pret->pq),num_one, BASEX);
DUPRAT(thisterm,pret);
n2=longtonum(0L, BASEX);
@@ -81,7 +81,7 @@ void exprat( PRAT *px, uint32_t radix, int32_t precision)
ratpowlong( &pwr, intpwr, precision);
subrat(px, pint, precision);
-
+
// It just so happens to be an integral power of e.
if ( rat_gt( *px, rat_negsmallest, precision) && rat_lt( *px, rat_smallest, precision) )
{
@@ -131,7 +131,7 @@ void _lograt( PRAT *px, int32_t precision)
CREATETAYLOR();
createrat(thisterm);
-
+
// sub one from x
(*px)->pq->sign *= -1;
addnum(&((*px)->pp),(*px)->pq, BASEX);
@@ -158,14 +158,14 @@ void lograt( 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.
-
-
+
+
// Check for someone taking the log of zero or a negative number.
if ( rat_le( *px, rat_zero, precision) )
{
throw( CALC_E_DOMAIN );
}
-
+
// Get number > 1, for scaling
fneglog = rat_lt( *px, rat_one, precision);
if ( fneglog )
@@ -176,12 +176,12 @@ void lograt( PRAT *px, int32_t precision)
(*px)->pp = (*px)->pq;
(*px)->pq = pnumtemp;
}
-
+
// Scale the number within BASEX factor of 1, for the large scale.
// 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
+ // Take advantage of px's base BASEX to scale quickly down to
// a reasonable range.
long intpwr;
intpwr=LOGRAT2(*px)-1;
@@ -206,17 +206,17 @@ void lograt( PRAT *px, int32_t precision)
}
_lograt(px, precision);
-
+
// Add the large and small scaling factors, take into account
// small scaling was done in e_to_one_half chunks.
divrat(&offset, rat_two, precision);
addrat(&pwr, offset, precision);
-
+
// And add the resulting scaling factor to the answer.
addrat(px, pwr, precision);
trimit(px, precision);
-
+
// If number started out < 1 rescale answer to negative.
if ( fneglog )
{
@@ -224,9 +224,9 @@ void lograt( PRAT *px, int32_t precision)
}
destroyrat(offset);
- destroyrat(pwr);
+ destroyrat(pwr);
}
-
+
void log10rat( PRAT *px, int32_t precision)
{
@@ -235,7 +235,7 @@ void log10rat( PRAT *px, int32_t precision)
}
//
-// return if the given x is even number. The assumption here is its denominator is 1 and we are testing the numerator is
+// return if the given x is even number. The assumption here is its denominator is 1 and we are testing the numerator is
// even or not
bool IsEven(PRAT x, uint32_t radix, int32_t precision)
{
@@ -318,7 +318,7 @@ void powratNumeratorDenominator(PRAT *px, PRAT y, uint32_t radix, int32_t precis
// 1. Initialize result.
PRAT pxPow = nullptr;
DUPRAT(pxPow, *px);
-
+
// 2. Calculate pxPow = px ^ yNumerator
// if yNumerator is not 1
if (!rat_equ(yNumerator, rat_one, precision))
@@ -341,7 +341,7 @@ void powratNumeratorDenominator(PRAT *px, PRAT y, uint32_t radix, int32_t precis
PRAT originalResult = nullptr;
DUPRAT(originalResult, pxPow);
powratcomp(&originalResult, oneoveryDenom, radix, precision);
-
+
// ##################################
// Round the originalResult to roundedResult
// ##################################
@@ -375,7 +375,7 @@ void powratNumeratorDenominator(PRAT *px, PRAT y, uint32_t radix, int32_t precis
else
{
DUPRAT(*px, originalResult);
- }
+ }
destroyrat(oneoveryDenom);
destroyrat(originalResult);
@@ -429,7 +429,7 @@ void powratcomp(PRAT *px, PRAT y, uint32_t radix, int32_t precision)
sign = 1;
}
}
- else
+ else
{
PRAT pxint= nullptr;
DUPRAT(pxint,*px);
@@ -491,7 +491,7 @@ void powratcomp(PRAT *px, PRAT y, uint32_t radix, int32_t precision)
PRAT pNumerator = nullptr;
PRAT pDenominator = nullptr;
bool fBadExponent = false;
-
+
// Get the numbers in arbitrary precision rational number format
DUPRAT(pNumerator, rat_zero); // pNumerator->pq is 1 one
DUPRAT(pDenominator, rat_zero); // pDenominator->pq is 1 one
@@ -516,7 +516,7 @@ void powratcomp(PRAT *px, PRAT y, uint32_t radix, int32_t precision)
}
destroyrat(pNumerator);
destroyrat(pDenominator);
-
+
if (fBadExponent)
{
throw( CALC_E_DOMAIN );
diff --git a/src/CalcManager/Ratpack/fact.cpp b/src/CalcManager/Ratpack/fact.cpp
index ab11451f..1a992bc0 100644
--- a/src/CalcManager/Ratpack/fact.cpp
+++ b/src/CalcManager/Ratpack/fact.cpp
@@ -73,17 +73,17 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
PRAT ratprec = nullptr;
PRAT ratRadix = nullptr;
long oldprec;
-
+
// Set up constants and initial conditions
oldprec = precision;
ratprec = longtorat( oldprec );
-
+
// Find the best 'A' for convergence to the required precision.
a=longtorat( radix );
lograt(&a, precision);
mulrat(&a, ratprec, precision);
- // Really is -ln(n)+1, but -ln(n) will be < 1
+ // Really is -ln(n)+1, but -ln(n) will be < 1
// if we scale n between 0.5 and 1.5
addrat(&a, rat_two, precision);
DUPRAT(tmp,a);
@@ -91,9 +91,9 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
mulrat(&tmp, *pn, precision);
addrat(&a, tmp, precision);
addrat(&a, rat_one, precision);
-
+
// Calculate the necessary bump in precision and up the precision.
- // The following code is equivalent to
+ // The following code is equivalent to
// precision += ln(exp(a)*pow(a,n+1.5))-ln(radix));
DUPRAT(tmp,*pn);
one_pt_five=longtorat( 3L );
@@ -110,7 +110,7 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
lograt( &tmp, precision);
subrat( &term, tmp, precision);
precision += rattolong( term, radix, precision);
-
+
// Set up initial terms for series, refer to series in above comment block.
DUPRAT(factorial,rat_one); // Start factorial out with one
count = longtonum( 0L, BASEX );
@@ -120,7 +120,7 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
// a2=a^2
DUPRAT(a2,a);
mulrat(&a2, a, precision);
-
+
// sum=(1/n)-(a/(n+1))
DUPRAT(sum,rat_one);
divrat(&sum, *pn, precision);
@@ -136,14 +136,14 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
divrat(&err, ratRadix, precision);
// Just get something not tiny in term
- DUPRAT(term, rat_two );
+ DUPRAT(term, rat_two );
// Loop until precision is reached, or asked to halt.
while ( !zerrat( term ) && rat_gt( term, err, precision) )
{
addrat(pn, rat_two, precision);
-
- // WARNING: mixing numbers and rationals here.
+
+ // WARNING: mixing numbers and rationals here.
// for speed and efficiency.
INC(count);
mulnumx(&(factorial->pp),count);
@@ -166,15 +166,15 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
DUPRAT(term,rat_one);
divrat( &term, *pn, precision);
subrat( &term, tmp, precision);
-
+
divrat (&term, factorial, precision);
addrat( &sum, term, precision);
ABSRAT(term);
}
-
+
// Multiply by factor.
mulrat( &sum, mpy, precision);
-
+
// And cleanup
precision = oldprec;
destroyrat(ratprec);
@@ -199,13 +199,13 @@ void factrat( PRAT *px, uint32_t radix, int32_t precision)
PRAT fact = nullptr;
PRAT frac = nullptr;
PRAT neg_rat_one = nullptr;
-
+
if ( rat_gt( *px, rat_max_fact, precision) || rat_lt( *px, rat_min_fact, precision) )
{
// Don't attempt factorial of anything too large or small.
throw CALC_E_OVERFLOW;
}
-
+
DUPRAT(fact,rat_one);
DUPRAT(neg_rat_one,rat_one);
@@ -226,7 +226,7 @@ void factrat( PRAT *px, uint32_t radix, int32_t precision)
mulrat( &fact, *px, precision);
subrat( px, rat_one, precision);
}
-
+
// Added to make numbers 'close enough' to integers use integer factorial.
if ( LOGRATRADIX(*px) <= -precision)
{
diff --git a/src/CalcManager/Ratpack/itrans.cpp b/src/CalcManager/Ratpack/itrans.cpp
index 66e6fc62..ef687b93 100644
--- a/src/CalcManager/Ratpack/itrans.cpp
+++ b/src/CalcManager/Ratpack/itrans.cpp
@@ -69,13 +69,13 @@ void _asinrat( PRAT *px, int32_t precision)
{
CREATETAYLOR();
- DUPRAT(pret,*px);
+ DUPRAT(pret,*px);
DUPRAT(thisterm,*px);
DUPNUM(n2,num_one);
do
{
- NEXTTERM(xx,MULNUM(n2) MULNUM(n2)
+ NEXTTERM(xx,MULNUM(n2) MULNUM(n2)
INC(n2) DIVNUM(n2) INC(n2) DIVNUM(n2), precision);
}
while ( !SMALL_ENOUGH_RAT( thisterm, precision) );
@@ -100,7 +100,7 @@ void asinrat( PRAT *px, uint32_t radix, int32_t precision)
(*px)->pp->sign = 1;
(*px)->pq->sign = 1;
-
+
// Avoid the really bad part of the asin curve near +/-1.
DUPRAT(phack,*px);
subrat(&phack, rat_one, precision);
@@ -185,15 +185,15 @@ void _acosrat( PRAT *px, int32_t precision)
{
CREATETAYLOR();
- createrat(thisterm);
+ createrat(thisterm);
thisterm->pp=longtonum( 1L, BASEX );
- thisterm->pq=longtonum( 1L, BASEX );
+ thisterm->pq=longtonum( 1L, BASEX );
DUPNUM(n2,num_one);
do
{
- NEXTTERM(xx,MULNUM(n2) MULNUM(n2)
+ NEXTTERM(xx,MULNUM(n2) MULNUM(n2)
INC(n2) DIVNUM(n2) INC(n2) DIVNUM(n2), precision);
}
while ( !SMALL_ENOUGH_RAT( thisterm, precision) );
@@ -210,7 +210,7 @@ void acosrat( PRAT *px, uint32_t radix, int32_t precision)
(*px)->pp->sign = 1;
(*px)->pq->sign = 1;
-
+
if ( rat_equ( *px, rat_one, precision) )
{
if ( sgn == -1 )
@@ -274,7 +274,7 @@ void _atanrat( PRAT *px, int32_t precision)
{
CREATETAYLOR();
- DUPRAT(pret,*px);
+ DUPRAT(pret,*px);
DUPRAT(thisterm,*px);
DUPNUM(n2,num_one);
@@ -298,7 +298,7 @@ void atanrat( PRAT *px, uint32_t radix, int32_t precision)
(*px)->pp->sign = 1;
(*px)->pq->sign = 1;
-
+
if ( rat_gt( (*px), pt_eight_five, precision) )
{
if ( rat_gt( (*px), rat_two, precision) )
@@ -314,7 +314,7 @@ void atanrat( PRAT *px, uint32_t radix, int32_t precision)
subrat(px, tmpx, precision);
destroyrat( tmpx );
}
- else
+ else
{
(*px)->pp->sign = sgn;
DUPRAT(tmpx,*px);
diff --git a/src/CalcManager/Ratpack/itransh.cpp b/src/CalcManager/Ratpack/itransh.cpp
index 7b75e703..d6734a1f 100644
--- a/src/CalcManager/Ratpack/itransh.cpp
+++ b/src/CalcManager/Ratpack/itransh.cpp
@@ -60,7 +60,7 @@ void asinhrat( PRAT *px, uint32_t radix, int32_t precision)
if ( rat_gt( *px, pt_eight_five, precision) || rat_lt( *px, neg_pt_eight_five, precision) )
{
PRAT ptmp = nullptr;
- DUPRAT(ptmp,(*px));
+ DUPRAT(ptmp,(*px));
mulrat(&ptmp, *px, precision);
addrat(&ptmp, rat_one, precision);
rootrat(&ptmp, rat_two, radix, precision);
@@ -73,14 +73,14 @@ void asinhrat( PRAT *px, uint32_t radix, int32_t precision)
CREATETAYLOR();
xx->pp->sign *= -1;
- DUPRAT(pret,(*px));
+ DUPRAT(pret,(*px));
DUPRAT(thisterm,(*px));
DUPNUM(n2,num_one);
do
{
- NEXTTERM(xx,MULNUM(n2) MULNUM(n2)
+ NEXTTERM(xx,MULNUM(n2) MULNUM(n2)
INC(n2) DIVNUM(n2) INC(n2) DIVNUM(n2), precision);
}
while ( !SMALL_ENOUGH_RAT( thisterm, precision) );
@@ -99,7 +99,7 @@ void asinhrat( PRAT *px, uint32_t radix, int32_t precision)
// hyperbolic cose of
// RETURN: acosh of x in PRAT form.
//
-// EXPLANATION: This uses
+// EXPLANATION: This uses
//
// acosh(x)=ln(x+sqrt(x^2-1))
//
@@ -117,7 +117,7 @@ void acoshrat( PRAT *px, uint32_t radix, int32_t precision)
else
{
PRAT ptmp = nullptr;
- DUPRAT(ptmp,(*px));
+ DUPRAT(ptmp,(*px));
mulrat(&ptmp, *px, precision);
subrat(&ptmp, rat_one, precision);
rootrat(&ptmp,rat_two, radix, precision);
@@ -148,7 +148,7 @@ void atanhrat( PRAT *px, int32_t precision)
{
PRAT ptmp = nullptr;
- DUPRAT(ptmp,(*px));
+ DUPRAT(ptmp,(*px));
subrat(&ptmp, rat_one, precision);
addrat(px, rat_one, precision);
divrat(px, ptmp, precision);
diff --git a/src/CalcManager/Ratpack/logic.cpp b/src/CalcManager/Ratpack/logic.cpp
index ed598eca..c4c26330 100644
--- a/src/CalcManager/Ratpack/logic.cpp
+++ b/src/CalcManager/Ratpack/logic.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//---------------------------------------------------------------------------
@@ -16,7 +16,7 @@
#include "pch.h"
#include "ratpak.h"
-
+using namespace std;
void lshrat( PRAT *pa, PRAT b, uint32_t radix, int32_t precision)
@@ -49,7 +49,7 @@ void rshrat( PRAT *pa, PRAT b, uint32_t radix, int32_t precision)
intrat(pa, radix, precision);
if ( !zernum( (*pa)->pp ) )
- {
+ {
// If input is zero we're done.
if ( rat_lt( b, rat_min_exp, precision) )
{
@@ -155,11 +155,11 @@ void boolnum( PNUMBER *pa, PNUMBER b, int func )
pchc = c->mant;
for ( ;cdigits > 0; cdigits--, mexp++ )
{
- da = ( ( ( mexp >= a->exp ) && ( cdigits + a->exp - c->exp >
- (c->cdigit - a->cdigit) ) ) ?
+ da = ( ( ( mexp >= a->exp ) && ( cdigits + a->exp - c->exp >
+ (c->cdigit - a->cdigit) ) ) ?
*pcha++ : 0 );
- db = ( ( ( mexp >= b->exp ) && ( cdigits + b->exp - c->exp >
- (c->cdigit - b->cdigit) ) ) ?
+ db = ( ( ( mexp >= b->exp ) && ( cdigits + b->exp - c->exp >
+ (c->cdigit - b->cdigit) ) ) ?
*pchb++ : 0 );
switch ( func )
{
@@ -205,15 +205,14 @@ void modrat( PRAT *pa, PRAT b )
throw CALC_E_INDEFINITE;
}
DUPRAT(tmp,b);
-
+
mulnumx( &((*pa)->pp), tmp->pq );
mulnumx( &(tmp->pp), (*pa)->pq );
remnum( &((*pa)->pp), tmp->pp, BASEX );
mulnumx( &((*pa)->pq), tmp->pq );
-
- //Get *pa back in the integer over integer form.
+
+ // Get *pa back in the integer over integer form.
RENORMALIZE(*pa);
destroyrat( tmp );
}
-
diff --git a/src/CalcManager/Ratpack/num.cpp b/src/CalcManager/Ratpack/num.cpp
index 76fa91a1..817fe02c 100644
--- a/src/CalcManager/Ratpack/num.cpp
+++ b/src/CalcManager/Ratpack/num.cpp
@@ -2,20 +2,20 @@
// Licensed under the MIT License.
//-----------------------------------------------------------------------------
-// Package Title ratpak
-// File num.c
-// Copyright (C) 1995-97 Microsoft
-// Date 01-16-95
-//
-//
-// Description
-//
-// Contains number routines for add, mul, div, rem and other support
-// and longs.
-//
-// Special Information
-//
-//
+// Package Title ratpak
+// File num.c
+// Copyright (C) 1995-97 Microsoft
+// Date 01-16-95
+//
+//
+// Description
+//
+// Contains number routines for add, mul, div, rem and other support
+// and longs.
+//
+// Special Information
+//
+//
//-----------------------------------------------------------------------------
#include "pch.h"
#include "ratpak.h"
@@ -76,8 +76,8 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
long fcomplb = 0; // fcomplb is a flag to signal b is negative.
a=*pa;
-
-
+
+
// Calculate the overlap of the numbers after alignment, this includes
// necessary padding 0's
cdigits = max( a->cdigit+a->exp, b->cdigit+b->exp ) -
@@ -90,7 +90,7 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
pcha = a->mant;
pchb = b->mant;
pchc = c->mant;
-
+
// Figure out the sign of the numbers
if ( a->sign != b->sign )
{
@@ -98,21 +98,21 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
fcompla = ( a->sign == -1 );
fcomplb = ( b->sign == -1 );
}
-
+
// Loop over all the digits, real and 0 padded. Here we know a and b are
- // aligned
+ // aligned
for ( ;cdigits > 0; cdigits--, mexp++ )
{
-
+
// Get digit from a, taking padding into account.
- da = ( ( ( mexp >= a->exp ) && ( cdigits + a->exp - c->exp >
- (c->cdigit - a->cdigit) ) ) ?
+ da = ( ( ( mexp >= a->exp ) && ( cdigits + a->exp - c->exp >
+ (c->cdigit - a->cdigit) ) ) ?
*pcha++ : 0 );
// Get digit from b, taking padding into account.
- db = ( ( ( mexp >= b->exp ) && ( cdigits + b->exp - c->exp >
- (c->cdigit - b->cdigit) ) ) ?
+ db = ( ( ( mexp >= b->exp ) && ( cdigits + b->exp - c->exp >
+ (c->cdigit - b->cdigit) ) ) ?
*pchb++ : 0 );
-
+
// Handle complementing for a and b digit. Might be a better way, but
// haven't found it yet.
if ( fcompla )
@@ -123,20 +123,20 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
{
db = (MANTTYPE)(radix) - 1 - db;
}
-
+
// Update carry as necessary
cy = da + db + cy;
*pchc++ = (MANTTYPE)(cy % (MANTTYPE)radix);
cy /= (MANTTYPE)radix;
}
-
+
// Handle carry from last sum as extra digit
if ( cy && !(fcompla || fcomplb) )
{
*pchc++ = cy;
c->cdigit++;
}
-
+
// Compute sign of result
if ( !(fcompla || fcomplb) )
{
@@ -150,14 +150,14 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
}
else
{
- // In this particular case an overflow or underflow has occurred
- // and all the digits need to be complemented, at one time an
- // attempt to handle this above was made, it turned out to be much
+ // In this particular case an overflow or underflow has occurred
+ // and all the digits need to be complemented, at one time an
+ // attempt to handle this above was made, it turned out to be much
// slower on average.
c->sign = -1;
cy = 1;
for ( ( cdigits = c->cdigit ), (pchc = c->mant);
- cdigits > 0;
+ cdigits > 0;
cdigits-- )
{
cy = (MANTTYPE)radix - (MANTTYPE)1 - *pchc + cy;
@@ -166,7 +166,7 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
}
}
}
-
+
// Remove leading zeros, remember digits are in order of
// increasing significance. i.e. 100 would be 0,0,1
while ( c->cdigit > 1 && *(--pchc) == 0 )
@@ -231,7 +231,7 @@ void _mulnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
MANTTYPE da = 0; // da is the digit from the fist number.
TWO_MANTTYPE cy = 0; // cy is the carry resulting from the addition of
// a multiplied row into the result.
- TWO_MANTTYPE mcy = 0; // mcy is the resultant from a single
+ TWO_MANTTYPE mcy = 0; // mcy is the resultant from a single
// multiply, AND the carry of that multiply.
long icdigit = 0; // Index of digit being calculated in final result.
@@ -249,8 +249,8 @@ void _mulnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
{
da = *pcha++;
pchb = b->mant;
-
- // Shift pchc, and pchcoffset, one for each digit
+
+ // Shift pchc, and pchcoffset, one for each digit
pchc = pchcoffset++;
for ( ibdigit = b->cdigit; ibdigit > 0; ibdigit-- )
@@ -268,23 +268,23 @@ void _mulnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
// If result is nonzero, or while result of carry is nonzero...
while ( mcy || cy )
{
-
+
// update carry from addition(s) and multiply.
cy += (TWO_MANTTYPE)pchc[icdigit]+(mcy%(TWO_MANTTYPE)radix);
-
- // update result digit from
+
+ // update result digit from
pchc[icdigit++]=(MANTTYPE)(cy%(TWO_MANTTYPE)radix);
-
+
// update carries from
mcy /= (TWO_MANTTYPE)radix;
cy /= (TWO_MANTTYPE)radix;
}
-
+
pchb++;
pchc++;
}
}
-
+
// prevent different kinds of zeros, by stripping leading duplicate zeros.
// digits are in order of increasing significance.
while ( c->cdigit > 1 && c->mant[c->cdigit-1] == 0 )
@@ -317,7 +317,7 @@ void remnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
{
PNUMBER tmp = nullptr; // tmp is the working remainder.
PNUMBER lasttmp = nullptr; // lasttmp is the last remainder which worked.
-
+
// Once *pa is less than b, *pa is the remainder.
while ( !lessnum( *pa, b ) )
{
@@ -336,20 +336,20 @@ void remnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
destroynum( lasttmp );
lasttmp=longtonum( 0, radix);
- while ( lessnum( tmp, *pa ) )
+ while ( lessnum( tmp, *pa ) )
{
DUPNUM( lasttmp, tmp );
addnum( &tmp, tmp, radix);
}
if ( lessnum( *pa, tmp ) )
- {
+ {
// too far, back up...
destroynum( tmp );
tmp=lasttmp;
lasttmp= nullptr;
}
-
+
// Subtract the working remainder from the remainder holder.
tmp->sign = -1*(*pa)->sign;
addnum( pa, tmp, radix);
@@ -357,7 +357,7 @@ void remnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
destroynum( tmp );
destroynum( lasttmp );
- }
+ }
}
@@ -381,7 +381,7 @@ void __inline divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision)
{
if ( b->cdigit > 1 || b->mant[0] != 1 || b->exp != 0 )
- {
+ {
// b is not one
_divnum( pa, b, radix, precision);
}
@@ -418,7 +418,7 @@ void _divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision)
tmp->sign = a->sign;
rem->exp = b->cdigit + b->exp - rem->cdigit;
- // Build a table of multiplications of the divisor, this is quicker for
+ // Build a table of multiplications of the divisor, this is quicker for
// more than radix 'digits'
list numberList{ longtonum(0L, radix) };
for (unsigned long i = 1; i < radix; i++)
@@ -535,21 +535,21 @@ bool equnum( PNUMBER a, PNUMBER b )
pb += b->cdigit - 1;
cdigits = max( a->cdigit, b->cdigit );
ccdigits = cdigits;
-
+
// Loop over all digits until we run out of digits or there is a
// difference in the digits.
for ( ;cdigits > 0; cdigits-- )
{
- da = ( (cdigits > (ccdigits - a->cdigit) ) ?
+ da = ( (cdigits > (ccdigits - a->cdigit) ) ?
*pa-- : 0 );
- db = ( (cdigits > (ccdigits - b->cdigit) ) ?
+ db = ( (cdigits > (ccdigits - b->cdigit) ) ?
*pb-- : 0 );
if ( da != db )
{
return false;
}
}
-
+
// In this case, they are equal.
return true;
}
@@ -604,9 +604,9 @@ bool lessnum( PNUMBER a, PNUMBER b )
ccdigits = cdigits;
for ( ;cdigits > 0; cdigits-- )
{
- da = ( (cdigits > (ccdigits - a->cdigit) ) ?
+ da = ( (cdigits > (ccdigits - a->cdigit) ) ?
*pa-- : 0 );
- db = ( (cdigits > (ccdigits - b->cdigit) ) ?
+ db = ( (cdigits > (ccdigits - b->cdigit) ) ?
*pb-- : 0 );
diff = da-db;
if ( diff )
@@ -639,8 +639,8 @@ bool zernum( PNUMBER a )
MANTTYPE *pcha;
length = a->cdigit;
pcha = a->mant;
-
- // loop over all the digits until you find a nonzero or until you run
+
+ // loop over all the digits until you find a nonzero or until you run
// out of digits
while ( length-- > 0 )
{
diff --git a/src/CalcManager/Ratpack/rat.cpp b/src/CalcManager/Ratpack/rat.cpp
index 20751fe4..e101458a 100644
--- a/src/CalcManager/Ratpack/rat.cpp
+++ b/src/CalcManager/Ratpack/rat.cpp
@@ -38,7 +38,7 @@ using namespace std;
//
//-----------------------------------------------------------------------------
-void gcdrat( PRAT *pa, uint32_t radix, int32_t precision)
+void gcdrat( PRAT *pa, int32_t precision)
{
PNUMBER pgcd= nullptr;
@@ -56,7 +56,7 @@ void gcdrat( PRAT *pa, uint32_t radix, int32_t precision)
destroynum( pgcd );
*pa=a;
- RENORMALIZE(*pa);
+ RENORMALIZE(*pa);
}
//-----------------------------------------------------------------------------
@@ -82,7 +82,7 @@ void fracrat( PRAT *pa , uint32_t radix, int32_t precision)
remnum( &((*pa)->pp), (*pa)->pq, BASEX );
- //Get *pa back in the integer over integer form.
+ // Get *pa back in the integer over integer form.
RENORMALIZE(*pa);
}
@@ -100,7 +100,7 @@ void fracrat( PRAT *pa , uint32_t radix, int32_t precision)
//-----------------------------------------------------------------------------
void mulrat( PRAT *pa, PRAT b, int32_t precision)
-
+
{
// Only do the multiply if it isn't zero.
if ( !zernum( (*pa)->pp ) )
@@ -170,7 +170,7 @@ void divrat( PRAT *pa, PRAT b, int32_t precision)
#ifdef DIVGCD
gcdrat( pa );
-#endif
+#endif
}
@@ -215,13 +215,13 @@ void addrat( PRAT *pa, PRAT b, int32_t precision)
if ( equnum( (*pa)->pq, b->pq ) )
{
- // Very special case, q's match.,
+ // Very special case, q's match.,
// make sure signs are involved in the calculation
- // we have to do this since the optimization here is only
+ // we have to do this since the optimization here is only
// working with the top half of the rationals.
- (*pa)->pp->sign *= (*pa)->pq->sign;
+ (*pa)->pp->sign *= (*pa)->pq->sign;
(*pa)->pq->sign = 1;
- b->pp->sign *= b->pq->sign;
+ b->pp->sign *= b->pq->sign;
b->pq->sign = 1;
addnum( &((*pa)->pp), b->pp, BASEX );
}
@@ -236,15 +236,15 @@ void addrat( PRAT *pa, PRAT b, int32_t precision)
destroynum( (*pa)->pq );
(*pa)->pq = bot;
trimit(pa, precision);
-
+
// Get rid of negative zeros here.
- (*pa)->pp->sign *= (*pa)->pq->sign;
+ (*pa)->pp->sign *= (*pa)->pq->sign;
(*pa)->pq->sign = 1;
}
#ifdef ADDGCD
gcdrat( pa );
-#endif
+#endif
}
@@ -264,7 +264,7 @@ void addrat( PRAT *pa, PRAT b, int32_t precision)
//-----------------------------------------------------------------------------
void rootrat( PRAT *py, PRAT n, uint32_t radix, int32_t precision)
-{
+{
// Initialize 1/n
PRAT oneovern= nullptr;
DUPRAT(oneovern,rat_one);
diff --git a/src/CalcManager/Ratpack/ratconst.h b/src/CalcManager/Ratpack/ratconst.h
index d208b33c..be24b002 100644
--- a/src/CalcManager/Ratpack/ratconst.h
+++ b/src/CalcManager/Ratpack/ratconst.h
@@ -1,480 +1,482 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_num_one= {
+#pragma once
+
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_num_one= {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_num_two= {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_num_two= {
1,
1,
0,
{ 2,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_num_five= {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_num_five= {
1,
1,
0,
{ 5,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_num_six= {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_num_six= {
1,
1,
0,
{ 6,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_num_ten= {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_num_ten= {
1,
1,
0,
{ 10,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_smallest = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_smallest = {
1,
1,
0,
{ 1,}
};
-NUMBER init_q_rat_smallest = {
+inline const NUMBER init_q_rat_smallest = {
1,
4,
0,
{ 0, 190439170, 901055854, 10097,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_negsmallest = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_negsmallest = {
-1,
1,
0,
{ 1,}
};
-NUMBER init_q_rat_negsmallest = {
+inline const NUMBER init_q_rat_negsmallest = {
1,
4,
0,
{ 0, 190439170, 901055854, 10097,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_pt_eight_five = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_pt_eight_five = {
1,
1,
0,
{ 85,}
};
-NUMBER init_q_pt_eight_five = {
+inline const NUMBER init_q_pt_eight_five = {
1,
1,
0,
{ 100,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_six = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_six = {
1,
1,
0,
{ 6,}
};
-NUMBER init_q_rat_six = {
+inline const NUMBER init_q_rat_six = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_two = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_two = {
1,
1,
0,
{ 2,}
};
-NUMBER init_q_rat_two = {
+inline const NUMBER init_q_rat_two = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_zero = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_zero = {
1,
1,
0,
{ 0,}
};
-NUMBER init_q_rat_zero = {
+inline const NUMBER init_q_rat_zero = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_one = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_one = {
1,
1,
0,
{ 1,}
};
-NUMBER init_q_rat_one = {
+inline const NUMBER init_q_rat_one = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_neg_one = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_neg_one = {
-1,
1,
0,
{ 1,}
};
-NUMBER init_q_rat_neg_one = {
+inline const NUMBER init_q_rat_neg_one = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_half = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_half = {
1,
1,
0,
{ 1,}
};
-NUMBER init_q_rat_half = {
+inline const NUMBER init_q_rat_half = {
1,
1,
0,
{ 2,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_ten = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_ten = {
1,
1,
0,
{ 10,}
};
-NUMBER init_q_rat_ten = {
+inline const NUMBER init_q_rat_ten = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_pi = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_pi = {
1,
6,
0,
{ 125527896, 283898350, 1960493936, 1672850762, 1288168272, 8,}
};
-NUMBER init_q_pi = {
+inline const NUMBER init_q_pi = {
1,
6,
0,
{ 1288380402, 1120116153, 1860424692, 1944118326, 1583591604, 2,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_two_pi = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_two_pi = {
1,
6,
0,
{ 251055792, 567796700, 1773504224, 1198217877, 428852897, 17,}
};
-NUMBER init_q_two_pi = {
+inline const NUMBER init_q_two_pi = {
1,
6,
0,
{ 1288380402, 1120116153, 1860424692, 1944118326, 1583591604, 2,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_pi_over_two = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_pi_over_two = {
1,
6,
0,
{ 125527896, 283898350, 1960493936, 1672850762, 1288168272, 8,}
};
-NUMBER init_q_pi_over_two = {
+inline const NUMBER init_q_pi_over_two = {
1,
6,
0,
{ 429277156, 92748659, 1573365737, 1740753005, 1019699561, 5,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_one_pt_five_pi = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_one_pt_five_pi = {
1,
6,
0,
{ 1241201312, 270061909, 1051574664, 1924965045, 1340320627, 70,}
};
-NUMBER init_q_one_pt_five_pi = {
+inline const NUMBER init_q_one_pt_five_pi = {
1,
6,
0,
{ 1579671539, 1837970263, 1067644340, 523549916, 2119366659, 14,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_e_to_one_half = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_e_to_one_half = {
1,
6,
0,
{ 256945612, 216219427, 223516738, 477442596, 581063757, 23,}
};
-NUMBER init_q_e_to_one_half = {
+inline const NUMBER init_q_e_to_one_half = {
1,
6,
0,
{ 1536828363, 698484484, 1127331835, 224219346, 245499408, 14,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_exp = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_exp = {
1,
6,
0,
{ 943665199, 1606559160, 1094967530, 1759391384, 1671799163, 1123581,}
};
-NUMBER init_q_rat_exp = {
+inline const NUMBER init_q_rat_exp = {
1,
6,
0,
{ 879242208, 2022880100, 617392930, 1374929092, 1367479163, 413342,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_ln_ten = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_ln_ten = {
1,
6,
0,
{ 2086268922, 165794492, 1416063951, 1851428830, 1893239400, 65366841,}
};
-NUMBER init_q_ln_ten = {
+inline const NUMBER init_q_ln_ten = {
1,
6,
0,
{ 26790652, 564532679, 783998273, 216030448, 1564709968, 28388458,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_ln_two = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_ln_two = {
1,
6,
0,
{ 1789230241, 1057927868, 715399197, 908801241, 1411265331, 3,}
};
-NUMBER init_q_ln_two = {
+inline const NUMBER init_q_ln_two = {
1,
6,
0,
{ 1559869847, 1930657510, 1228561531, 219003871, 593099283, 5,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rad_to_deg = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rad_to_deg = {
1,
6,
0,
{ 2127722024, 1904928383, 2016479213, 2048947859, 1578647346, 492,}
};
-NUMBER init_q_rad_to_deg = {
+inline const NUMBER init_q_rad_to_deg = {
1,
6,
0,
{ 125527896, 283898350, 1960493936, 1672850762, 1288168272, 8,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rad_to_grad = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rad_to_grad = {
1,
6,
0,
{ 2125526288, 684931327, 570267400, 129125085, 1038224725, 547,}
};
-NUMBER init_q_rad_to_grad = {
+inline const NUMBER init_q_rad_to_grad = {
1,
6,
0,
{ 125527896, 283898350, 1960493936, 1672850762, 1288168272, 8,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_qword = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_qword = {
1,
3,
0,
{ 2147483647, 2147483647, 3,}
};
-NUMBER init_q_rat_qword = {
+inline const NUMBER init_q_rat_qword = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_dword = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_dword = {
1,
2,
0,
{ 2147483647, 1,}
};
-NUMBER init_q_rat_dword = {
+inline const NUMBER init_q_rat_dword = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_max_long = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_max_long = {
1,
1,
0,
{ 2147483647,}
};
-NUMBER init_q_rat_max_long = {
+inline const NUMBER init_q_rat_max_long = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_min_long = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_min_long = {
-1,
2,
0,
{ 0, 1,}
};
-NUMBER init_q_rat_min_long = {
+inline const NUMBER init_q_rat_min_long = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_word = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_word = {
1,
1,
0,
{ 65535,}
};
-NUMBER init_q_rat_word = {
+inline const NUMBER init_q_rat_word = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_byte = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_byte = {
1,
1,
0,
{ 255,}
};
-NUMBER init_q_rat_byte = {
+inline const NUMBER init_q_rat_byte = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_400 = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_400 = {
1,
1,
0,
{ 400,}
};
-NUMBER init_q_rat_400 = {
+inline const NUMBER init_q_rat_400 = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_360 = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_360 = {
1,
1,
0,
{ 360,}
};
-NUMBER init_q_rat_360 = {
+inline const NUMBER init_q_rat_360 = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_200 = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_200 = {
1,
1,
0,
{ 200,}
};
-NUMBER init_q_rat_200 = {
+inline const NUMBER init_q_rat_200 = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_180 = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_180 = {
1,
1,
0,
{ 180,}
};
-NUMBER init_q_rat_180 = {
+inline const NUMBER init_q_rat_180 = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_max_exp = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_max_exp = {
1,
1,
0,
{ 100000,}
};
-NUMBER init_q_rat_max_exp = {
+inline const NUMBER init_q_rat_max_exp = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_min_exp = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_min_exp = {
-1,
1,
0,
{ 100000,}
};
-NUMBER init_q_rat_min_exp = {
+inline const NUMBER init_q_rat_min_exp = {
1,
1,
0,
{ 1,}
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_max_fact = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_max_fact = {
1,
1,
0,
{ 3249, }
};
-NUMBER init_q_rat_max_fact = {
+inline const NUMBER init_q_rat_max_fact = {
1,
1,
0,
{ 1, }
};
-// Autogenerated by _dumprawrat in support.c
-NUMBER init_p_rat_min_fact = {
+// Autogenerated by _dumprawrat in support.cpp
+inline const NUMBER init_p_rat_min_fact = {
-1,
1,
0,
{ 1000, }
};
-NUMBER init_q_rat_min_fact = {
+inline const NUMBER init_q_rat_min_fact = {
1,
1,
0,
diff --git a/src/CalcManager/Ratpack/ratpak.h b/src/CalcManager/Ratpack/ratpak.h
index 3ff16e84..ba34686c 100644
--- a/src/CalcManager/Ratpack/ratpak.h
+++ b/src/CalcManager/Ratpack/ratpak.h
@@ -231,7 +231,7 @@ memmove( (x)->pp->mant, &((x)->pp->mant[trim]), sizeof(MANTTYPE)*((x)->pp->cdigi
(x)->pp->cdigit -= trim; \
(x)->pp->exp += trim; \
} \
- trim = min((x)->pp->exp,(x)->pq->exp);\
+ trim = std::min((x)->pp->exp,(x)->pq->exp);\
(x)->pp->exp -= trim;\
(x)->pq->exp -= trim;\
}
@@ -417,7 +417,7 @@ extern void tanrat( _Inout_ PRAT *px, uint32_t radix, int32_t precision);
// angle type
extern void tananglerat( _Inout_ PRAT *px, ANGLE_TYPE angletype, uint32_t radix, int32_t precision);
-extern void _dupnum(_In_ PNUMBER dest, _In_ PNUMBER src);
+extern void _dupnum(_In_ PNUMBER dest, _In_ const NUMBER * const src);
extern void _destroynum( _In_ PNUMBER pnum );
extern void _destroyrat( _In_ PRAT prat );
@@ -430,7 +430,7 @@ extern void divrat( _Inout_ PRAT *pa, _In_ PRAT b, int32_t precision);
extern void fracrat( _Inout_ PRAT *pa , uint32_t radix, int32_t precision);
extern void factrat( _Inout_ PRAT *pa, uint32_t radix, int32_t precision);
extern void modrat( _Inout_ PRAT *pa, _In_ PRAT b );
-extern void gcdrat( _Inout_ PRAT *pa, uint32_t radix, int32_t precision);
+extern void gcdrat( _Inout_ PRAT *pa, int32_t precision);
extern void intrat( _Inout_ PRAT *px, uint32_t radix, int32_t precision);
extern void mulnum( _Inout_ PNUMBER *pa, _In_ PNUMBER b, uint32_t radix);
extern void mulnumx( _Inout_ PNUMBER *pa, _In_ PNUMBER b );
diff --git a/src/CalcManager/Ratpack/support.cpp b/src/CalcManager/Ratpack/support.cpp
index d747b4d1..f3b00d2f 100644
--- a/src/CalcManager/Ratpack/support.cpp
+++ b/src/CalcManager/Ratpack/support.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//----------------------------------------------------------------------------
@@ -31,8 +31,8 @@ static int cbitsofprecision = 0;
#define READRAWNUM(v)
#define DUMPRAWRAT(v) _dumprawrat(#v,v, wcout)
#define DUMPRAWNUM(v) fprintf( stderr, \
-"// Autogenerated by _dumprawrat in support.c\n" ); \
- fprintf( stderr, "NUMBER init_" #v "= {\n" ); \
+"// Autogenerated by _dumprawrat in support.cpp\n" ); \
+ fprintf( stderr, "inline const NUMBER init_" #v "= {\n" ); \
_dumprawnum(v, wcout); \
fprintf( stderr, "};\n" )
@@ -58,7 +58,7 @@ static int cbitsofprecision = RATIO_FOR_DECIMAL * DECIMAL * CALC_DECIMAL_DIGITS_
#endif
-bool g_ftrueinfinite = false; // Set to true if you don't want
+bool g_ftrueinfinite = false; // Set to true if you don't want
// chopping internally
// precision used internally
@@ -119,8 +119,8 @@ PRAT rat_max_long= nullptr; // max signed long
void ChangeConstants(uint32_t radix, int32_t precision)
{
- // ratio is set to the number of digits in the current radix, you can get
- // in the internal BASEX radix, this is important for length calculations
+ // ratio is set to the number of digits in the current radix, you can get
+ // in the internal BASEX radix, this is important for length calculations
// in translating from radix to BASEX and back.
uint64_t limit = static_cast(BASEX) / static_cast(radix);
@@ -213,7 +213,7 @@ void ChangeConstants(uint32_t radix, int32_t precision)
cbitsofprecision = g_ratio * radix * precision;
- // Apparently when dividing 180 by pi, another (internal) digit of
+ // Apparently when dividing 180 by pi, another (internal) digit of
// precision is needed.
long extraPrecision = precision + g_ratio;
DUPRAT(pi, rat_half);
@@ -348,7 +348,7 @@ bool rat_ge( PRAT a, PRAT b, int32_t precision)
b->pp->sign *= -1;
addrat( &rattmp, b, precision);
b->pp->sign *= -1;
- bool bret = ( zernum( rattmp->pp ) ||
+ bool bret = ( zernum( rattmp->pp ) ||
rattmp->pp->sign * rattmp->pq->sign == 1 );
destroyrat( rattmp );
return( bret );
@@ -472,10 +472,10 @@ void scale( PRAT *px, PRAT scalefact, uint32_t radix, int32_t precision )
{
PRAT pret = nullptr;
DUPRAT(pret,*px);
-
- // Logscale is a quick way to tell how much extra precision is needed for
+
+ // Logscale is a quick way to tell how much extra precision is needed for
// scaling by scalefact.
- long logscale = g_ratio * ( (pret->pp->cdigit+pret->pp->exp) -
+ long logscale = g_ratio * ( (pret->pp->cdigit+pret->pp->exp) -
(pret->pq->cdigit+pret->pq->exp) );
if ( logscale > 0 )
{
@@ -508,9 +508,9 @@ void scale2pi( PRAT *px, uint32_t radix, int32_t precision )
PRAT my_two_pi = nullptr;
DUPRAT(pret,*px);
- // Logscale is a quick way to tell how much extra precision is needed for
+ // Logscale is a quick way to tell how much extra precision is needed for
// scaling by 2 pi.
- long logscale = g_ratio * ( (pret->pp->cdigit+pret->pp->exp) -
+ long logscale = g_ratio * ( (pret->pp->cdigit+pret->pp->exp) -
(pret->pq->cdigit+pret->pq->exp) );
if ( logscale > 0 )
{
@@ -663,16 +663,16 @@ void _readconstants( void )
// ARGUMENTS: PRAT *px, long precision
//
//
-// DESCRIPTION: Chops off digits from rational numbers to avoid time
-// explosions in calculations of functions using series.
-// It can be shown that it is enough to only keep the first n digits
-// of the largest of p or q in the rational p over q form, and of course
-// scale the smaller by the same number of digits. This will give you
-// n-1 digits of accuracy. This dramatically speeds up calculations
+// DESCRIPTION: Chops off digits from rational numbers to avoid time
+// explosions in calculations of functions using series.
+// It can be shown that it is enough to only keep the first n digits
+// of the largest of p or q in the rational p over q form, and of course
+// scale the smaller by the same number of digits. This will give you
+// n-1 digits of accuracy. This dramatically speeds up calculations
// involving hundreds of digits or more.
// The last part of this trim dealing with exponents never affects accuracy
//
-// RETURN: none, modifies the pointed to PRAT
+// RETURN: none, modifies the pointed to PRAT
//
//---------------------------------------------------------------------------
@@ -680,7 +680,7 @@ void trimit( PRAT *px, int32_t precision)
{
if ( !g_ftrueinfinite )
- {
+ {
long trim;
PNUMBER pp=(*px)->pp;
PNUMBER pq=(*px)->pq;
diff --git a/src/CalcManager/Ratpack/trans.cpp b/src/CalcManager/Ratpack/trans.cpp
index ad82a94d..5b46a936 100644
--- a/src/CalcManager/Ratpack/trans.cpp
+++ b/src/CalcManager/Ratpack/trans.cpp
@@ -47,8 +47,8 @@ void scalerat( _Inout_ PRAT *pa, ANGLE_TYPE angletype, uint32_t radix, int32_t p
// EXPLANATION: This uses Taylor series
//
// n
-// ___ 2j+1
-// \ ] j X
+// ___ 2j+1
+// \ ] j X
// \ -1 * ---------
// / (2j+1)!
// /__]
@@ -73,7 +73,7 @@ void _sinrat( PRAT *px, int32_t precision)
{
CREATETAYLOR();
- DUPRAT(pret,*px);
+ DUPRAT(pret,*px);
DUPRAT(thisterm,*px);
DUPNUM(n2,num_one);
@@ -84,11 +84,11 @@ void _sinrat( PRAT *px, int32_t precision)
} while ( !SMALL_ENOUGH_RAT( thisterm, precision) );
DESTROYTAYLOR();
-
- // Since *px might be epsilon above 1 or below -1, due to TRIMIT we need
+
+ // Since *px might be epsilon above 1 or below -1, due to TRIMIT we need
// this trick here.
inbetween(px, rat_one, precision);
-
+
// Since *px might be epsilon near zero we must set it to zero.
if ( rat_le(*px, rat_smallest, precision) && rat_ge(*px, rat_negsmallest, precision) )
{
@@ -166,13 +166,13 @@ void _cosrat( PRAT *px, uint32_t radix, int32_t precision)
CREATETAYLOR();
destroynum(pret->pp);
- destroynum(pret->pq);
+ destroynum(pret->pq);
pret->pp=longtonum( 1L, radix);
pret->pq=longtonum( 1L, radix);
DUPRAT(thisterm,pret)
-
+
n2=longtonum(0L, radix);
xx->pp->sign *= -1;
@@ -181,7 +181,7 @@ void _cosrat( PRAT *px, uint32_t radix, int32_t precision)
} while ( !SMALL_ENOUGH_RAT( thisterm, precision) );
DESTROYTAYLOR();
- // Since *px might be epsilon above 1 or below -1, due to TRIMIT we need
+ // Since *px might be epsilon above 1 or below -1, due to TRIMIT we need
// this trick here.
inbetween(px, rat_one, precision);
// Since *px might be epsilon near zero we must set it to zero.
diff --git a/src/CalcManager/Ratpack/transh.cpp b/src/CalcManager/Ratpack/transh.cpp
index fb756516..8a835341 100644
--- a/src/CalcManager/Ratpack/transh.cpp
+++ b/src/CalcManager/Ratpack/transh.cpp
@@ -80,7 +80,7 @@ void _sinhrat( PRAT *px, int32_t precision)
CREATETAYLOR();
- DUPRAT(pret,*px);
+ DUPRAT(pret,*px);
DUPRAT(thisterm,pret);
DUPNUM(n2,num_one);
@@ -194,7 +194,7 @@ void coshrat( PRAT *px, uint32_t radix, int32_t precision)
{
_coshrat( px, radix, precision);
}
- // Since *px might be epsilon below 1 due to TRIMIT
+ // Since *px might be epsilon below 1 due to TRIMIT
// we need this trick here.
if ( rat_lt(*px, rat_one, precision) )
{
diff --git a/src/CalcManager/UnitConverter.cpp b/src/CalcManager/UnitConverter.cpp
index 07f75d33..0548719a 100644
--- a/src/CalcManager/UnitConverter.cpp
+++ b/src/CalcManager/UnitConverter.cpp
@@ -46,7 +46,7 @@ UnitConverter::UnitConverter(_In_ const shared_ptr& dataLo
{
m_dataLoader = dataLoader;
m_currencyDataLoader = currencyDataLoader;
- //declaring the delimiter character conversion map
+ // declaring the delimiter character conversion map
quoteConversions[L'|'] = L"{p}";
quoteConversions[L'['] = L"{lc}";
quoteConversions[L']'] = L"{rc}";
@@ -90,7 +90,7 @@ vector UnitConverter::GetCategories()
}
///
-/// Sets the current category in use by this converter,
+/// Sets the current category in use by this converter,
/// and returns a list of unit types that exist under the given category.
///
/// Category struct which we are setting
@@ -109,22 +109,8 @@ CategorySelectionInitializer UnitConverter::SetCurrentCategory(const Category& i
vector& unitVector = m_categoryToUnits[m_currentCategory];
for (unsigned int i = 0; i < unitVector.size(); i++)
{
- if (unitVector[i].id == m_fromType.id)
- {
- unitVector[i].isConversionSource = true;
- }
- else
- {
- unitVector[i].isConversionSource = false;
- }
- if (unitVector[i].id == m_toType.id)
- {
- unitVector[i].isConversionTarget = true;
- }
- else
- {
- unitVector[i].isConversionTarget = false;
- }
+ unitVector[i].isConversionSource = (unitVector[i].id == m_fromType.id);
+ unitVector[i].isConversionTarget = (unitVector[i].id == m_toType.id);
}
m_currentCategory = input;
if (!m_currentCategory.supportsNegative && m_currentDisplay.front() == L'-')
@@ -156,21 +142,23 @@ Category UnitConverter::GetCurrentCategory()
/// Unit struct we are converting to
void UnitConverter::SetCurrentUnitTypes(const Unit& fromType, const Unit& toType)
{
- if (CheckLoad())
+ if (!CheckLoad())
{
- m_fromType = fromType;
- m_toType = toType;
- Calculate();
-
- UpdateCurrencySymbols();
- UpdateViewModel();
+ return;
}
+
+ m_fromType = fromType;
+ m_toType = toType;
+ Calculate();
+
+ UpdateCurrencySymbols();
+ UpdateViewModel();
}
///
/// Switches the active field, indicating that we are now entering data into
/// what was originally the return field, and storing results into what was
-/// originally the current field. We swap appropriate values,
+/// originally the current field. We swap appropriate values,
/// but do not callback, as values have not changed.
///
///
@@ -181,22 +169,24 @@ void UnitConverter::SetCurrentUnitTypes(const Unit& fromType, const Unit& toType
///
void UnitConverter::SwitchActive(const wstring& newValue)
{
- if (CheckLoad())
+ if (!CheckLoad())
{
- swap(m_fromType, m_toType);
- swap(m_currentHasDecimal, m_returnHasDecimal);
- m_returnDisplay = m_currentDisplay;
- m_currentDisplay = newValue;
- m_currentHasDecimal = (m_currentDisplay.find(L'.') != m_currentDisplay.npos);
- m_switchedActive = true;
+ return;
+ }
- if (m_currencyDataLoader != nullptr && m_vmCurrencyCallback != nullptr)
- {
- shared_ptr currencyDataLoader = GetCurrencyConverterDataLoader();
- const pair currencyRatios = currencyDataLoader->GetCurrencyRatioEquality(m_fromType, m_toType);
+ swap(m_fromType, m_toType);
+ swap(m_currentHasDecimal, m_returnHasDecimal);
+ m_returnDisplay = m_currentDisplay;
+ m_currentDisplay = newValue;
+ m_currentHasDecimal = (m_currentDisplay.find(L'.') != m_currentDisplay.npos);
+ m_switchedActive = true;
- m_vmCurrencyCallback->CurrencyRatiosCallback(currencyRatios.first, currencyRatios.second);
- }
+ if (m_currencyDataLoader != nullptr && m_vmCurrencyCallback != nullptr)
+ {
+ shared_ptr currencyDataLoader = GetCurrencyConverterDataLoader();
+ const pair currencyRatios = currencyDataLoader->GetCurrencyRatioEquality(m_fromType, m_toType);
+
+ m_vmCurrencyCallback->CurrencyRatiosCallback(currencyRatios.first, currencyRatios.second);
}
}
@@ -291,55 +281,53 @@ wstring UnitConverter::ConversionDataToString(ConversionData d, const wchar_t *
///
wstring UnitConverter::Serialize()
{
- if (CheckLoad())
- {
- wstringstream out(wstringstream::out);
- const wchar_t * delimiter = L";";
-
- out << UnitToString(m_fromType, delimiter) << "|";
- out << UnitToString(m_toType, delimiter) << "|";
- out << CategoryToString(m_currentCategory, delimiter) << "|";
- out << std::to_wstring(m_currentHasDecimal) << delimiter << std::to_wstring(m_returnHasDecimal) << delimiter << std::to_wstring(m_switchedActive) << delimiter;
- out << m_currentDisplay << delimiter << m_returnDisplay << delimiter << "|";
- wstringstream categoryString(wstringstream::out);
- wstringstream categoryToUnitString(wstringstream::out);;
- wstringstream unitToUnitToDoubleString(wstringstream::out);;
- for (const Category& c : m_categories)
- {
- categoryString << CategoryToString(c, delimiter) << ",";
- }
-
- for (const auto& cur : m_categoryToUnits)
- {
- categoryToUnitString << CategoryToString(cur.first, delimiter) << "[";
- for (const Unit& u : cur.second)
- {
- categoryToUnitString << UnitToString(u, delimiter) << ",";
- }
- categoryToUnitString << "[" << "]";
- }
-
- for (const auto& cur : m_ratioMap)
- {
- unitToUnitToDoubleString << UnitToString(cur.first, delimiter) << "[";
- for (const auto& curConversion : cur.second)
- {
- unitToUnitToDoubleString << UnitToString(curConversion.first, delimiter) << ":";
- unitToUnitToDoubleString << ConversionDataToString(curConversion.second, delimiter) << ":,";
- }
- unitToUnitToDoubleString << "[" << "]";
- }
-
- out << categoryString.str() << "|";
- out << categoryToUnitString.str() << "|";
- out << unitToUnitToDoubleString.str() << "|";
- wstring test = out.str();
- return test;
- }
- else
+ if (!CheckLoad())
{
return wstring();
}
+
+ wstringstream out(wstringstream::out);
+ const wchar_t * delimiter = L";";
+
+ out << UnitToString(m_fromType, delimiter) << "|";
+ out << UnitToString(m_toType, delimiter) << "|";
+ out << CategoryToString(m_currentCategory, delimiter) << "|";
+ out << std::to_wstring(m_currentHasDecimal) << delimiter << std::to_wstring(m_returnHasDecimal) << delimiter << std::to_wstring(m_switchedActive) << delimiter;
+ out << m_currentDisplay << delimiter << m_returnDisplay << delimiter << "|";
+ wstringstream categoryString(wstringstream::out);
+ wstringstream categoryToUnitString(wstringstream::out);
+ wstringstream unitToUnitToDoubleString(wstringstream::out);
+ for (const Category& c : m_categories)
+ {
+ categoryString << CategoryToString(c, delimiter) << ",";
+ }
+
+ for (const auto& cur : m_categoryToUnits)
+ {
+ categoryToUnitString << CategoryToString(cur.first, delimiter) << "[";
+ for (const Unit& u : cur.second)
+ {
+ categoryToUnitString << UnitToString(u, delimiter) << ",";
+ }
+ categoryToUnitString << "[" << "]";
+ }
+
+ for (const auto& cur : m_ratioMap)
+ {
+ unitToUnitToDoubleString << UnitToString(cur.first, delimiter) << "[";
+ for (const auto& curConversion : cur.second)
+ {
+ unitToUnitToDoubleString << UnitToString(curConversion.first, delimiter) << ":";
+ unitToUnitToDoubleString << ConversionDataToString(curConversion.second, delimiter) << ":,";
+ }
+ unitToUnitToDoubleString << "[" << "]";
+ }
+
+ out << categoryString.str() << "|";
+ out << categoryToUnitString.str() << "|";
+ out << unitToUnitToDoubleString.str() << "|";
+ wstring test = out.str();
+ return test;
}
///
@@ -349,55 +337,58 @@ wstring UnitConverter::Serialize()
void UnitConverter::DeSerialize(const wstring& serializedData)
{
Reset();
- if (!serializedData.empty())
+
+ if (serializedData.empty())
{
- vector outerTokens = StringToVector(serializedData, L"|");
- assert(outerTokens.size() == EXPECTEDSERIALIZEDTOKENCOUNT);
- m_fromType = StringToUnit(outerTokens[0]);
- m_toType = StringToUnit(outerTokens[1]);
- m_currentCategory = StringToCategory(outerTokens[2]);
- vector stateDataTokens = StringToVector(outerTokens[3], L";");
- assert(stateDataTokens.size() == EXPECTEDSTATEDATATOKENCOUNT);
- m_currentHasDecimal = (stateDataTokens[0].compare(L"1") == 0);
- m_returnHasDecimal = (stateDataTokens[1].compare(L"1") == 0);
- m_switchedActive = (stateDataTokens[2].compare(L"1") == 0);
- m_currentDisplay = stateDataTokens[3];
- m_returnDisplay = stateDataTokens[4];
- vector categoryListTokens = StringToVector(outerTokens[4], L",");
- for (wstring token : categoryListTokens)
- {
- m_categories.push_back(StringToCategory(token));
- }
- vector unitVectorTokens = StringToVector(outerTokens[5], L"]");
- for (wstring unitVector : unitVectorTokens)
- {
- vector mapcomponents = StringToVector(unitVector, L"[");
- assert(mapcomponents.size() == EXPECTEDMAPCOMPONENTTOKENCOUNT);
- Category key = StringToCategory(mapcomponents[0]);
- vector units = StringToVector(mapcomponents[1], L",");
- for (wstring unit : units)
- {
- m_categoryToUnits[key].push_back(StringToUnit(unit));
- }
- }
- vector ratioMapTokens = StringToVector(outerTokens[6], L"]");
- for (wstring token : ratioMapTokens)
- {
- vector ratioMapComponentTokens = StringToVector(token, L"[");
- assert(ratioMapComponentTokens.size() == EXPECTEDMAPCOMPONENTTOKENCOUNT);
- Unit key = StringToUnit(ratioMapComponentTokens[0]);
- vector ratioMapList = StringToVector(ratioMapComponentTokens[1], L",");
- for (wstring subtoken : ratioMapList)
- {
- vector ratioMapSubComponentTokens = StringToVector(subtoken, L":");
- assert(ratioMapSubComponentTokens.size() == EXPECTEDMAPCOMPONENTTOKENCOUNT);
- Unit subkey = StringToUnit(ratioMapSubComponentTokens[0]);
- ConversionData conversion = StringToConversionData(ratioMapSubComponentTokens[1]);
- m_ratioMap[key][subkey] = conversion;
- }
- }
- UpdateViewModel();
+ return;
}
+
+ vector outerTokens = StringToVector(serializedData, L"|");
+ assert(outerTokens.size() == EXPECTEDSERIALIZEDTOKENCOUNT);
+ m_fromType = StringToUnit(outerTokens[0]);
+ m_toType = StringToUnit(outerTokens[1]);
+ m_currentCategory = StringToCategory(outerTokens[2]);
+ vector stateDataTokens = StringToVector(outerTokens[3], L";");
+ assert(stateDataTokens.size() == EXPECTEDSTATEDATATOKENCOUNT);
+ m_currentHasDecimal = (stateDataTokens[0].compare(L"1") == 0);
+ m_returnHasDecimal = (stateDataTokens[1].compare(L"1") == 0);
+ m_switchedActive = (stateDataTokens[2].compare(L"1") == 0);
+ m_currentDisplay = stateDataTokens[3];
+ m_returnDisplay = stateDataTokens[4];
+ vector categoryListTokens = StringToVector(outerTokens[4], L",");
+ for (wstring token : categoryListTokens)
+ {
+ m_categories.push_back(StringToCategory(token));
+ }
+ vector unitVectorTokens = StringToVector(outerTokens[5], L"]");
+ for (wstring unitVector : unitVectorTokens)
+ {
+ vector mapcomponents = StringToVector(unitVector, L"[");
+ assert(mapcomponents.size() == EXPECTEDMAPCOMPONENTTOKENCOUNT);
+ Category key = StringToCategory(mapcomponents[0]);
+ vector units = StringToVector(mapcomponents[1], L",");
+ for (wstring unit : units)
+ {
+ m_categoryToUnits[key].push_back(StringToUnit(unit));
+ }
+ }
+ vector ratioMapTokens = StringToVector(outerTokens[6], L"]");
+ for (wstring token : ratioMapTokens)
+ {
+ vector ratioMapComponentTokens = StringToVector(token, L"[");
+ assert(ratioMapComponentTokens.size() == EXPECTEDMAPCOMPONENTTOKENCOUNT);
+ Unit key = StringToUnit(ratioMapComponentTokens[0]);
+ vector ratioMapList = StringToVector(ratioMapComponentTokens[1], L",");
+ for (wstring subtoken : ratioMapList)
+ {
+ vector ratioMapSubComponentTokens = StringToVector(subtoken, L":");
+ assert(ratioMapSubComponentTokens.size() == EXPECTEDMAPCOMPONENTTOKENCOUNT);
+ Unit subkey = StringToUnit(ratioMapSubComponentTokens[0]);
+ ConversionData conversion = StringToConversionData(ratioMapSubComponentTokens[1]);
+ m_ratioMap[key][subkey] = conversion;
+ }
+ }
+ UpdateViewModel();
}
///
@@ -406,21 +397,23 @@ void UnitConverter::DeSerialize(const wstring& serializedData)
/// wstring holding the serialized data. If it does not have expected number of parameters, we will ignore it
void UnitConverter::RestoreUserPreferences(const wstring& userPreferences)
{
- if (!userPreferences.empty())
+ if (userPreferences.empty())
{
- vector outerTokens = StringToVector(userPreferences, L"|");
- if (outerTokens.size() == 3)
- {
- m_fromType = StringToUnit(outerTokens[0]);
- m_toType = StringToUnit(outerTokens[1]);
- m_currentCategory = StringToCategory(outerTokens[2]);
- }
+ return;
+ }
+
+ vector outerTokens = StringToVector(userPreferences, L"|");
+ if (outerTokens.size() == 3)
+ {
+ m_fromType = StringToUnit(outerTokens[0]);
+ m_toType = StringToUnit(outerTokens[1]);
+ m_currentCategory = StringToCategory(outerTokens[2]);
}
}
///
/// Serializes the Category and Associated Units in the converter and returns it as a string
-///
+///
wstring UnitConverter::SaveUserPreferences()
{
wstringstream out(wstringstream::out);
@@ -441,7 +434,7 @@ wstring UnitConverter::Quote(const wstring& s)
{
wstringstream quotedString(wstringstream::out);
- //Iterate over the delimiter characters we need to quote
+ // Iterate over the delimiter characters we need to quote
wstring::const_iterator cursor = s.begin();
while(cursor != s.end())
{
@@ -479,7 +472,7 @@ wstring UnitConverter::Unquote(const wstring& s)
}
if (cursor == s.end())
{
- //badly formatted
+ // Badly formatted
break;
}
else
@@ -503,144 +496,146 @@ wstring UnitConverter::Unquote(const wstring& s)
/// Command enum representing the command that was entered
void UnitConverter::SendCommand(Command command)
{
- if (CheckLoad())
+ if (!CheckLoad())
{
- //TODO: Localization of characters
- bool clearFront = false;
- if (m_currentDisplay == L"0")
+ return;
+ }
+
+ // TODO: Localization of characters
+ bool clearFront = false;
+ if (m_currentDisplay == L"0")
+ {
+ clearFront = true;
+ }
+ bool clearBack = false;
+ if ((m_currentHasDecimal && m_currentDisplay.size() - 1 >= MAXIMUMDIGITSALLOWED) || (!m_currentHasDecimal && m_currentDisplay.size() >= MAXIMUMDIGITSALLOWED))
+ {
+ clearBack = true;
+ }
+ if (command != Command::Negate && m_switchedActive)
+ {
+ ClearValues();
+ m_switchedActive = false;
+ clearFront = true;
+ clearBack = false;
+ }
+ switch (command)
+ {
+ case Command::Zero:
+ m_currentDisplay += L"0";
+ break;
+
+ case Command::One:
+ m_currentDisplay += L"1";
+ break;
+
+ case Command::Two:
+ m_currentDisplay += L"2";
+ break;
+
+ case Command::Three:
+ m_currentDisplay += L"3";
+ break;
+
+ case Command::Four:
+ m_currentDisplay += L"4";
+ break;
+
+ case Command::Five:
+ m_currentDisplay += L"5";
+ break;
+
+ case Command::Six:
+ m_currentDisplay += L"6";
+ break;
+
+ case Command::Seven:
+ m_currentDisplay += L"7";
+ break;
+
+ case Command::Eight:
+ m_currentDisplay += L"8";
+ break;
+
+ case Command::Nine:
+ m_currentDisplay += L"9";
+ break;
+
+ case Command::Decimal:
+ clearFront = false;
+ clearBack = false;
+ if (!m_currentHasDecimal)
{
- clearFront = true;
+ m_currentDisplay += L".";
+ m_currentHasDecimal = true;
}
- bool clearBack = false;
- if ((m_currentHasDecimal && m_currentDisplay.size() - 1 >= MAXIMUMDIGITSALLOWED) || (!m_currentHasDecimal && m_currentDisplay.size() >= MAXIMUMDIGITSALLOWED))
+ break;
+
+ case Command::Backspace:
+ clearFront = false;
+ clearBack = false;
+ if ((m_currentDisplay.front() != '-' && m_currentDisplay.size() > 1) || m_currentDisplay.size() > 2)
{
- clearBack = true;
- }
- if (command != Command::Negate && m_switchedActive)
- {
- ClearValues();
- m_switchedActive = false;
- clearFront = true;
- clearBack = false;
- }
- switch (command)
- {
- case Command::Zero:
- m_currentDisplay += L"0";
- break;
-
- case Command::One:
- m_currentDisplay += L"1";
- break;
-
- case Command::Two:
- m_currentDisplay += L"2";
- break;
-
- case Command::Three:
- m_currentDisplay += L"3";
- break;
-
- case Command::Four:
- m_currentDisplay += L"4";
- break;
-
- case Command::Five:
- m_currentDisplay += L"5";
- break;
-
- case Command::Six:
- m_currentDisplay += L"6";
- break;
-
- case Command::Seven:
- m_currentDisplay += L"7";
- break;
-
- case Command::Eight:
- m_currentDisplay += L"8";
- break;
-
- case Command::Nine:
- m_currentDisplay += L"9";
- break;
-
- case Command::Decimal:
- clearFront = false;
- clearBack = false;
- if (!m_currentHasDecimal)
+ if (m_currentDisplay.back() == '.')
{
- m_currentDisplay += L".";
- m_currentHasDecimal = true;
+ m_currentHasDecimal = false;
}
- break;
+ m_currentDisplay.pop_back();
+ }
+ else
+ {
+ m_currentDisplay = L"0";
+ m_currentHasDecimal = false;
+ }
+ break;
- case Command::Backspace:
- clearFront = false;
- clearBack = false;
- if ((m_currentDisplay.front() != '-' && m_currentDisplay.size() > 1) || m_currentDisplay.size() > 2)
+ case Command::Negate:
+ clearFront = false;
+ clearBack = false;
+ if (m_currentCategory.supportsNegative)
+ {
+ if (m_currentDisplay.front() == '-')
{
- if (m_currentDisplay.back() == '.')
- {
- m_currentHasDecimal = false;
- }
- m_currentDisplay.pop_back();
+ m_currentDisplay.erase(0, 1);
}
else
{
- m_currentDisplay = L"0";
- m_currentHasDecimal = false;
+ m_currentDisplay.insert(0, 1, '-');
}
- break;
-
- case Command::Negate:
- clearFront = false;
- clearBack = false;
- if (m_currentCategory.supportsNegative)
- {
- if (m_currentDisplay.front() == '-')
- {
- m_currentDisplay.erase(0, 1);
- }
- else
- {
- m_currentDisplay.insert(0, 1, '-');
- }
- }
- break;
-
- case Command::Clear:
- clearFront = false;
- clearBack = false;
- ClearValues();
- break;
-
- case Command::Reset:
- clearFront = false;
- clearBack = false;
- ClearValues();
- Reset();
- break;
-
- default:
- break;
}
-
+ break;
- if (clearFront)
- {
- m_currentDisplay.erase(0, 1);
- }
- if (clearBack)
- {
- m_currentDisplay.erase(m_currentDisplay.size() - 1, 1);
- m_vmCallback->MaxDigitsReached();
- }
+ case Command::Clear:
+ clearFront = false;
+ clearBack = false;
+ ClearValues();
+ break;
- Calculate();
+ case Command::Reset:
+ clearFront = false;
+ clearBack = false;
+ ClearValues();
+ Reset();
+ break;
- UpdateViewModel();
+ default:
+ break;
}
+
+
+ if (clearFront)
+ {
+ m_currentDisplay.erase(0, 1);
+ }
+ if (clearBack)
+ {
+ m_currentDisplay.erase(m_currentDisplay.size() - 1, 1);
+ m_vmCallback->MaxDigitsReached();
+ }
+
+ Calculate();
+
+ UpdateViewModel();
}
///
@@ -728,7 +723,7 @@ vector> UnitConverter::CalculateSuggested()
vector intermediateVector;
vector intermediateWhimsicalVector;
unordered_map ratios = m_ratioMap[m_fromType];
- //Calculate converted values for every other unit type in this category, along with their magnitude
+ // Calculate converted values for every other unit type in this category, along with their magnitude
for (const auto& cur : ratios)
{
if (cur.first != m_fromType && cur.first != m_toType)
@@ -745,21 +740,21 @@ vector> UnitConverter::CalculateSuggested()
}
}
- //Sort the resulting list by absolute magnitude, breaking ties by choosing the positive value
+ // Sort the resulting list by absolute magnitude, breaking ties by choosing the positive value
sort(intermediateVector.begin(), intermediateVector.end(), []
(SuggestedValueIntermediate first, SuggestedValueIntermediate second)
- {
- if (abs(first.magnitude) == abs(second.magnitude))
- {
- return first.magnitude > second.magnitude;
- }
- else
- {
+ {
+ if (abs(first.magnitude) == abs(second.magnitude))
+ {
+ return first.magnitude > second.magnitude;
+ }
+ else
+ {
return abs(first.magnitude) < abs(second.magnitude);
}
});
- //Now that the list is sorted, iterate over it and populate the return vector with properly rounded and formatted return strings
+ // Now that the list is sorted, iterate over it and populate the return vector with properly rounded and formatted return strings
for (const auto& entry : intermediateVector)
{
wstring roundedString;
@@ -783,7 +778,7 @@ vector> UnitConverter::CalculateSuggested()
}
// The Whimsicals are determined differently
- //Sort the resulting list by absolute magnitude, breaking ties by choosing the positive value
+ // Sort the resulting list by absolute magnitude, breaking ties by choosing the positive value
sort(intermediateWhimsicalVector.begin(), intermediateWhimsicalVector.end(), []
(SuggestedValueIntermediate first, SuggestedValueIntermediate second)
{
@@ -797,7 +792,7 @@ vector> UnitConverter::CalculateSuggested()
}
});
- //Now that the list is sorted, iterate over it and populate the return vector with properly rounded and formatted return strings
+ // Now that the list is sorted, iterate over it and populate the return vector with properly rounded and formatted return strings
vector> whimsicalReturnVector;
for (const auto& entry : intermediateWhimsicalVector)
@@ -844,47 +839,49 @@ void UnitConverter::Reset()
ClearValues();
m_switchedActive = false;
- if (!m_categories.empty())
+ if (m_categories.empty())
{
- m_currentCategory = m_categories[0];
+ return;
+ }
- m_categoryToUnits.clear();
- m_ratioMap.clear();
- bool readyCategoryFound = false;
- for (const Category& category : m_categories)
+ m_currentCategory = m_categories[0];
+
+ m_categoryToUnits.clear();
+ m_ratioMap.clear();
+ bool readyCategoryFound = false;
+ for (const Category& category : m_categories)
+ {
+ shared_ptr activeDataLoader = GetDataLoaderForCategory(category);
+ if (activeDataLoader == nullptr)
{
- shared_ptr activeDataLoader = GetDataLoaderForCategory(category);
- if (activeDataLoader == nullptr)
- {
- // The data loader is different depending on the category, e.g. currency data loader
- // is different from the static data loader.
- // If there is no data loader for this category, continue.
- continue;
- }
-
- vector units = activeDataLoader->LoadOrderedUnits(category);
- m_categoryToUnits[category] = units;
-
- // Just because the units are empty, doesn't mean the user can't select this category,
- // we just want to make sure we don't let an unready category be the default.
- if (!units.empty())
- {
- for (Unit u : units)
- {
- m_ratioMap[u] = activeDataLoader->LoadOrderedRatios(u);
- }
-
- if (!readyCategoryFound)
- {
- m_currentCategory = category;
- readyCategoryFound = true;
- }
- }
+ // The data loader is different depending on the category, e.g. currency data loader
+ // is different from the static data loader.
+ // If there is no data loader for this category, continue.
+ continue;
}
- InitializeSelectedUnits();
- Calculate();
+ vector units = activeDataLoader->LoadOrderedUnits(category);
+ m_categoryToUnits[category] = units;
+
+ // Just because the units are empty, doesn't mean the user can't select this category,
+ // we just want to make sure we don't let an unready category be the default.
+ if (!units.empty())
+ {
+ for (Unit u : units)
+ {
+ m_ratioMap[u] = activeDataLoader->LoadOrderedRatios(u);
+ }
+
+ if (!readyCategoryFound)
+ {
+ m_currentCategory = category;
+ readyCategoryFound = true;
+ }
+ }
}
+
+ InitializeSelectedUnits();
+ Calculate();
}
///
@@ -1029,22 +1026,24 @@ void UnitConverter::Calculate()
/// wstring to trim
void UnitConverter::TrimString(wstring& returnString)
{
- if (returnString.find(L'.') != m_returnDisplay.npos)
+ if (returnString.find(L'.') == m_returnDisplay.npos)
{
- wstring::iterator iter;
- for (iter = returnString.end() - 1; ;iter--)
+ return;
+ }
+
+ wstring::iterator iter;
+ for (iter = returnString.end() - 1; ;iter--)
+ {
+ if (*iter != L'0')
{
- if (*iter != L'0')
- {
- returnString.erase(iter + 1, returnString.end());
- break;
- }
- }
- if (*(returnString.end()-1) == L'.')
- {
- returnString.erase(returnString.end()-1, returnString.end());
+ returnString.erase(iter + 1, returnString.end());
+ break;
}
}
+ if (*(returnString.end()-1) == L'.')
+ {
+ returnString.erase(returnString.end()-1, returnString.end());
+ }
}
///
diff --git a/src/CalcManager/UnitConverter.h b/src/CalcManager/UnitConverter.h
index 3f323c35..4e130d12 100644
--- a/src/CalcManager/UnitConverter.h
+++ b/src/CalcManager/UnitConverter.h
@@ -51,7 +51,7 @@ namespace UnitConversionManager
// null checks.
//
// unitId, name, abbreviation, isConversionSource, isConversionTarget, isWhimsical
- const Unit EMPTY_UNIT = Unit{ -1, L"", L"", true, true, false };
+ inline const Unit EMPTY_UNIT = Unit{ -1, L"", L"", true, true, false };
struct Category
{
diff --git a/src/CalcManager/pch.h b/src/CalcManager/pch.h
index 27e01ff3..ff0ca451 100644
--- a/src/CalcManager/pch.h
+++ b/src/CalcManager/pch.h
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
@@ -7,11 +7,16 @@
#define WIN32_LEAN_AND_MEAN
#endif
+// Windows headers define min/max macros.
+// Disable it for project code.
+#define NOMINMAX
+
#include
#include
#include
#include
#include
+#include
#include
#include
#include
diff --git a/src/CalcViewModel/ApplicationViewModel.cpp b/src/CalcViewModel/ApplicationViewModel.cpp
index 4df5bac3..f99ce036 100644
--- a/src/CalcViewModel/ApplicationViewModel.cpp
+++ b/src/CalcViewModel/ApplicationViewModel.cpp
@@ -32,14 +32,11 @@ using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
-namespace CalculatorApp::ViewModel::ApplicationViewModelProperties
+namespace
{
- StringReference Mode(L"Mode");
- StringReference PreviousMode(L"PreviousMode");
- StringReference ClearMemoryVisibility(L"ClearMemoryVisibility");
- StringReference AppBarVisibility(L"AppBarVisibility");
- StringReference CategoryName(L"CategoryName");
- StringReference Categories(L"Categories");
+ StringReference CategoriesPropertyName(L"Categories");
+ StringReference ClearMemoryVisibilityPropertyName(L"ClearMemoryVisibility");
+ StringReference AppBarVisibilityPropertyName(L"AppBarVisibility");
}
ApplicationViewModel::ApplicationViewModel() :
@@ -60,7 +57,7 @@ void ApplicationViewModel::Mode::set(ViewMode value)
PreviousMode = m_mode;
m_mode = value;
OnModeChanged();
- RaisePropertyChanged(ApplicationViewModelProperties::Mode);
+ RaisePropertyChanged(ModePropertyName);
}
}
@@ -69,7 +66,7 @@ void ApplicationViewModel::Categories::set(IObservableVector^
if (m_categories != value)
{
m_categories = value;
- RaisePropertyChanged(ApplicationViewModelProperties::Categories);
+ RaisePropertyChanged(CategoriesPropertyName);
}
}
@@ -163,11 +160,11 @@ void ApplicationViewModel::OnModeChanged()
//
// Save the changed mode, so that the new window launches in this mode.
// Don't save until after we have adjusted to the new mode, so we don't save a mode that fails to load.
- ApplicationData::Current->LocalSettings->Values->Insert(ApplicationViewModelProperties::Mode, NavCategory::Serialize(m_mode));
+ ApplicationData::Current->LocalSettings->Values->Insert(ModePropertyName, NavCategory::Serialize(m_mode));
TraceLogger::GetInstance().LogModeChangeEnd(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()));
- RaisePropertyChanged(ApplicationViewModelProperties::ClearMemoryVisibility);
- RaisePropertyChanged(ApplicationViewModelProperties::AppBarVisibility);
+ RaisePropertyChanged(ClearMemoryVisibilityPropertyName);
+ RaisePropertyChanged(AppBarVisibilityPropertyName);
}
void ApplicationViewModel::OnCopyCommand(Object^ parameter)
diff --git a/src/CalcViewModel/ApplicationViewModel.h b/src/CalcViewModel/ApplicationViewModel.h
index a8d459f7..f13e00ad 100644
--- a/src/CalcViewModel/ApplicationViewModel.h
+++ b/src/CalcViewModel/ApplicationViewModel.h
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
@@ -11,16 +11,6 @@ namespace CalculatorApp
{
namespace ViewModel
{
- namespace ApplicationViewModelProperties
- {
- extern Platform::StringReference Mode;
- extern Platform::StringReference PreviousMode;
- extern Platform::StringReference ClearMemoryVisibility;
- extern Platform::StringReference AppBarVisibility;
- extern Platform::StringReference CategoryName;
- extern Platform::StringReference Categories;
- }
-
[Windows::UI::Xaml::Data::Bindable]
public ref class ApplicationViewModel sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged
{
@@ -32,9 +22,9 @@ namespace CalculatorApp
OBSERVABLE_OBJECT();
OBSERVABLE_PROPERTY_RW(StandardCalculatorViewModel^, CalculatorViewModel);
OBSERVABLE_PROPERTY_RW(DateCalculatorViewModel^, DateCalcViewModel);
- OBSERVABLE_PROPERTY_RW(CalculatorApp::ViewModel::UnitConverterViewModel^, ConverterViewModel);
+ OBSERVABLE_PROPERTY_RW(UnitConverterViewModel^, ConverterViewModel);
OBSERVABLE_PROPERTY_RW(CalculatorApp::Common::ViewMode, PreviousMode);
- OBSERVABLE_PROPERTY_RW(Platform::String^, CategoryName);
+ OBSERVABLE_NAMED_PROPERTY_RW(Platform::String^, CategoryName);
COMMAND_FOR_METHOD(CopyCommand, ApplicationViewModel::OnCopyCommand);
COMMAND_FOR_METHOD(PasteCommand, ApplicationViewModel::OnPasteCommand);
@@ -48,6 +38,13 @@ namespace CalculatorApp
void set(CalculatorApp::Common::ViewMode value);
}
+ static property Platform::String^ ModePropertyName
+ {
+ Platform::String^ get()
+ {
+ return Platform::StringReference(L"Mode");
+ }
+ }
property Windows::Foundation::Collections::IObservableVector^ Categories
{
diff --git a/src/CalcViewModel/CalcViewModel.vcxproj b/src/CalcViewModel/CalcViewModel.vcxproj
index 33715487..e2e98ab9 100644
--- a/src/CalcViewModel/CalcViewModel.vcxproj
+++ b/src/CalcViewModel/CalcViewModel.vcxproj
@@ -154,6 +154,8 @@
$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)
4453
/bigobj /await /std:c++17 %(AdditionalOptions)
+ Level4
+ true
Console
@@ -172,6 +174,8 @@
$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)
4453
/bigobj /await /std:c++17 %(AdditionalOptions)
+ Level4
+ true
Console
@@ -190,6 +194,8 @@
$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)
4453
/bigobj /await /std:c++17 %(AdditionalOptions)
+ Level4
+ true
Console
@@ -208,6 +214,8 @@
$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)
4453
/bigobj /await /std:c++17 %(AdditionalOptions)
+ Level4
+ true
Console
@@ -226,6 +234,8 @@
$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)
4453
/bigobj /await /std:c++17 %(AdditionalOptions)
+ Level4
+ true
Console
@@ -244,6 +254,8 @@
$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)
4453
/bigobj /await /std:c++17 %(AdditionalOptions)
+ Level4
+ true
Console
@@ -262,6 +274,8 @@
$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)
4453
/bigobj /await /std:c++17 %(AdditionalOptions)
+ Level4
+ true
Console
@@ -280,6 +294,8 @@
$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)
4453
/bigobj /await /std:c++17 %(AdditionalOptions)
+ Level4
+ true
Console
diff --git a/src/CalcViewModel/Common/AlwaysSelectedCollectionView.h b/src/CalcViewModel/Common/AlwaysSelectedCollectionView.h
index 40dd5cf3..54c3b67c 100644
--- a/src/CalcViewModel/Common/AlwaysSelectedCollectionView.h
+++ b/src/CalcViewModel/Common/AlwaysSelectedCollectionView.h
@@ -3,9 +3,9 @@
#pragma once
-namespace CalculatorApp { namespace Common
+namespace CalculatorApp { namespace Common
{
- ref class AlwaysSelectedCollectionView sealed:
+ ref class AlwaysSelectedCollectionView sealed:
public Windows::UI::Xaml::DependencyObject,
public Windows::UI::Xaml::Data::ICollectionView
{
@@ -14,11 +14,11 @@ namespace CalculatorApp { namespace Common
m_currentPosition(-1)
{
m_source = source;
-
+
Windows::UI::Xaml::Interop::IBindableObservableVector^ observable = dynamic_cast(source);
if (observable)
{
- observable->VectorChanged +=
+ observable->VectorChanged +=
ref new Windows::UI::Xaml::Interop::BindableVectorChangedEventHandler(this, &AlwaysSelectedCollectionView::OnSourceBindableVectorChanged);
}
}
@@ -53,7 +53,7 @@ namespace CalculatorApp { namespace Common
return ref new Platform::Collections::Vector();
}
}
- property bool HasMoreItems
+ property bool HasMoreItems
{
virtual bool get() = Windows::UI::Xaml::Data::ICollectionView::HasMoreItems::get
{
@@ -77,7 +77,7 @@ namespace CalculatorApp { namespace Common
}
// The item is not in the collection
- // We're going to schedule a call back later so we
+ // We're going to schedule a call back later so we
// restore the selection to the way we wanted it to begin with
if (m_currentPosition >= 0 && m_currentPosition < static_cast(m_source->Size))
{
@@ -161,7 +161,7 @@ namespace CalculatorApp { namespace Common
m_currentChanging -= token;
}
}
-
+
// IVector