Updating comments per the C++ core guidelines and removing trailing whitespace (#194)

Fixed comments that were inconsistent with the style guidelines described in C++ core guidelines and the modern C++/WinRT language projections and removed trailing whitespace.

Inserted a space after the beginning of the comment so the text wasn't touching the // on all occurrences.

Removed all occurrences of trailing whitespace
This commit is contained in:
Will 2019-03-15 02:30:07 -04:00 committed by Howard Wolosky
parent 62317fd63b
commit 1113ff4b86
82 changed files with 509 additions and 510 deletions

View File

@ -413,7 +413,7 @@ int CHistoryCollector::AddCommand(_In_ const std::shared_ptr<IExpressionCommand>
return nCommands - 1; 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) void CHistoryCollector::UpdateHistoryExpression(uint32_t radix, int32_t precision)
{ {
if (m_spTokens != nullptr) if (m_spTokens != nullptr)
@ -451,7 +451,7 @@ void CHistoryCollector::SetDecimalSymbol(wchar_t decimalSymbol)
m_decimalSymbol = 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<CalculatorVector<int>> CHistoryCollector::GetOperandCommandsFromString(wstring_view numStr) std::shared_ptr<CalculatorVector<int>> CHistoryCollector::GetOperandCommandsFromString(wstring_view numStr)
{ {
std::shared_ptr<CalculatorVector<int>> commands = std::make_shared<CalculatorVector<int>>(); std::shared_ptr<CalculatorVector<int>> commands = std::make_shared<CalculatorVector<int>>();

View File

@ -29,7 +29,7 @@ using namespace CalcEngine;
namespace { namespace {
// NPrecedenceOfOp // NPrecedenceOfOp
// //
// returns a virtual number for precedence for the operator. We expect binary operator only, otherwise the lowest number // 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. // 0 is returned. Higher the number, higher the precedence of the operator.
INT NPrecedenceOfOp(int nopCode) INT NPrecedenceOfOp(int nopCode)
{ {
@ -54,13 +54,13 @@ namespace {
// HandleErrorCommand // 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. // 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) void CCalcEngine::HandleErrorCommand(WPARAM idc)
{ {
if (!IsGuiSettingOpCode(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; m_nTempCom = m_nLastCom;
} }
} }
@ -128,7 +128,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
} }
} }
// Toggle Record/Display mode if appropriate. // Toggle Record/Display mode if appropriate.
if (m_bRecord) if (m_bRecord)
{ {
if (IsOpInRange(wParam, IDC_AND, IDC_MMINUS) || if (IsOpInRange(wParam, IDC_AND, IDC_MMINUS) ||
@ -182,7 +182,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
// BINARY OPERATORS: // BINARY OPERATORS:
if (IsBinOpCode(wParam)) if (IsBinOpCode(wParam))
{ {
/* Change the operation if last input was operation. */ // Change the operation if last input was operation.
if (IsBinOpCode(m_nLastCom)) if (IsBinOpCode(m_nLastCom))
{ {
INT nPrev; INT nPrev;
@ -574,7 +574,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
m_lastVal = 0; m_lastVal = 0;
if (IsBinOpCode(m_nLastCom)) 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 // treated as 1 + (3
m_currentVal = 0; m_currentVal = 0;
} }
@ -803,7 +803,7 @@ void CCalcEngine::CheckAndAddLastBinOpToHistory(bool addToHistory)
{ {
if (m_HistoryCollector.FOpndAddedToHistory()) 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) // 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.) // 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 // So erase the last operand
@ -855,7 +855,7 @@ void CCalcEngine::DisplayAnnounceBinaryOperator()
} }
// Unary operator Function Name table Element // 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. // we have this separate table to get its localized name and for its Inv function if it exists.
typedef struct typedef struct
{ {
@ -1027,7 +1027,7 @@ wstring CCalcEngine::GetCurrentResultForRadix(uint32_t radix, int32_t precision)
wstring numberString = GetStringForDisplay(rat, radix); wstring numberString = GetStringForDisplay(rat, radix);
if (!numberString.empty()) if (!numberString.empty())
{ {
//revert the precision to previously stored precision // Revert the precision to previously stored precision
ChangeConstants(m_radix, m_precision); ChangeConstants(m_radix, m_precision);
} }

View File

@ -70,7 +70,7 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r
uint64_t w64Bits = result.ToUInt64_t(); uint64_t w64Bits = result.ToUInt64_t();
uint64_t lsb = ((w64Bits & 0x01) == 1) ? 1 : 0; uint64_t lsb = ((w64Bits & 0x01) == 1) ? 1 : 0;
w64Bits >>= 1; //RShift by 1 w64Bits >>= 1; // RShift by 1
w64Bits |= (lsb << (m_dwWordBitWidth - 1)); w64Bits |= (lsb << (m_dwWordBitWidth - 1));
result = w64Bits; result = w64Bits;

View File

@ -12,10 +12,10 @@ using namespace std;
// dont change that. // dont change that.
void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwidth) 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 // 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 // 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 // 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 // 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. // back to 1111,1111,1000,0001 when in Word mode.
if (m_fIntegerMode) if (m_fIntegerMode)
{ {
@ -46,7 +46,7 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwid
// inform ratpak that a change in base or precision has occurred // inform ratpak that a change in base or precision has occurred
BaseOrPrecisionChanged(); 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) // number to correct base)
DisplayNum(); DisplayNum();
} }
@ -143,7 +143,7 @@ void CCalcEngine::UpdateMaxIntDigits()
if (m_fIntegerMode) if (m_fIntegerMode)
{ {
m_cIntDigitsSav = static_cast<int>(m_maxDecimalValueStrings[m_numwidth].length()) - 1; m_cIntDigitsSav = static_cast<int>(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 // has to be checked separately
} }
else else
@ -161,10 +161,10 @@ void CCalcEngine::ChangeBaseConstants(uint32_t radix, int maxIntDigits, int32_t
{ {
if (10 == radix) 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 // 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 // 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 // the precision to number of digits allowed to enter. In other words, precision and # of allowed digits to be
// entered are different. // entered are different.
} }
else else

View File

@ -23,7 +23,7 @@ unsigned int CalculatorHistory::AddToHistory(_In_ shared_ptr<CalculatorVector <p
// to be changed when pszexp is back // to be changed when pszexp is back
tokens->GetString(&generatedExpression); tokens->GetString(&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 // in the history doesn't get broken for RTL languages
spHistoryItem->historyItemVector.expression = L'\u202d' + generatedExpression + L'\u202c'; spHistoryItem->historyItemVector.expression = L'\u202d' + generatedExpression + L'\u202c';
spHistoryItem->historyItemVector.result = wstring(result); spHistoryItem->historyItemVector.result = wstring(result);

View File

@ -300,7 +300,7 @@ namespace CalculationManager
} }
/// <summary> /// <summary>
/// Convert Command to unsigned char. /// Convert Command to unsigned char.
/// Since some Commands are higher than 255, they are saved after subtracting 255 /// 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. /// The smallest Command is CommandSIGN = 80, thus, subtracted value does not overlap with other values.
/// </summary> /// </summary>
@ -435,9 +435,9 @@ namespace CalculationManager
if (*commandItr >= MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::MemorizeNumber) && if (*commandItr >= MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::MemorizeNumber) &&
*commandItr <= MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::MemorizedNumberClearAll)) *commandItr <= MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::MemorizedNumberClearAll))
{ {
//MemoryCommands(which have values above 255) are pushed on m_savedCommands upon casting to unsigned char. // 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. // SerializeCommands uses m_savedCommands, which is then used in DeSerializeCommands.
//Hence, a simple cast to MemoryCommand is not sufficient. // Hence, a simple cast to MemoryCommand is not sufficient.
MemoryCommand memoryCommand = static_cast<MemoryCommand>(*commandItr + UCHAR_MAX + 1); MemoryCommand memoryCommand = static_cast<MemoryCommand>(*commandItr + UCHAR_MAX + 1);
unsigned int indexOfMemory = 0; unsigned int indexOfMemory = 0;
switch (memoryCommand) switch (memoryCommand)
@ -761,7 +761,7 @@ namespace CalculationManager
} }
void CalculatorManager::UpdateMaxIntDigits() void CalculatorManager::UpdateMaxIntDigits()
{ {
m_currentCalculatorEngine->UpdateMaxIntDigits(); m_currentCalculatorEngine->UpdateMaxIntDigits();
} }
@ -785,7 +785,7 @@ namespace CalculationManager
/// How Rational is serialized : /// How Rational is serialized :
/// Serialized Rational.P(Number) + Serialized Rational.Q(Number) /// Serialized Rational.P(Number) + Serialized Rational.Q(Number)
/// How Number is saved : /// How Number is saved :
/// [0] = Rational.P.Sign /// [0] = Rational.P.Sign
/// [1] = Rational.P.Mantissa.size /// [1] = Rational.P.Mantissa.size
/// [2] = Rational.P.Exp /// [2] = Rational.P.Exp
/// [3] = Rational.P.Mantissa[0] /// [3] = Rational.P.Mantissa[0]
@ -823,7 +823,7 @@ namespace CalculationManager
/// <summary> /// <summary>
/// Serialize Number to vector of long /// Serialize Number to vector of long
/// How Number is saved : /// How Number is saved :
/// [0] = Number.Sign /// [0] = Number.Sign
/// [1] = Number.Mantissa.size /// [1] = Number.Mantissa.size
/// [2] = Number.Exp /// [2] = Number.Exp
/// [3] = Number.Mantissa[0] /// [3] = Number.Mantissa[0]
@ -850,7 +850,7 @@ namespace CalculationManager
/// <summary> /// <summary>
/// DeserializeNumber vector and construct a Number /// DeserializeNumber vector and construct a Number
/// How Number is saved : /// How Number is saved :
/// [0] = Number.Sign /// [0] = Number.Sign
/// [1] = Number.Mantissa.size /// [1] = Number.Mantissa.size
/// [2] = Number.Exp /// [2] = Number.Exp
/// [3] = Number.Mantissa[0] /// [3] = Number.Mantissa[0]

View File

@ -27,9 +27,9 @@ namespace CalculationManager
ProgrammerModePrecision = 64 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 // with some gap to ensure there is no overlap of these ids
// when static_cast<unsigned char> is performed on these ids // when static_cast<unsigned char> is performed on these ids
// they shouldn't fall in any number range greater than 80. So never // they shouldn't fall in any number range greater than 80. So never
// make the memory command ids go below 330 // make the memory command ids go below 330
enum class MemoryCommand enum class MemoryCommand

View File

@ -10,7 +10,7 @@ namespace CalculationManager
public: public:
virtual ~IResourceProvider() { } 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 // by the calculation engine. The strings that must be defined
// and the ids to define them with can be seen in EngineStrings.h // and the ids to define them with can be seen in EngineStrings.h
// with SIDS prefix. Additionally it must provide values for string // with SIDS prefix. Additionally it must provide values for string

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
template <typename TType> template <typename TType>
class CalculatorVector class CalculatorVector
{ {
public: public:
HRESULT GetAt(_In_opt_ unsigned int index, _Out_ TType *item) HRESULT GetAt(_In_opt_ unsigned int index, _Out_ TType *item)

View File

@ -94,7 +94,7 @@ namespace CalculationManager
CommandFAC = 113, CommandFAC = 113,
CommandREC = 114, CommandREC = 114,
CommandDMS = 115, CommandDMS = 115,
CommandCUBEROOT = 116, //x ^ 1/3 CommandCUBEROOT = 116, // x ^ 1/3
CommandPOW10 = 117, // 10 ^ x CommandPOW10 = 117, // 10 ^ x
CommandPERCENT = 118, CommandPERCENT = 118,

View File

@ -75,19 +75,19 @@ void CUnaryCommand::Accept(_In_ ISerializeCommandVisitor &commandVisitor)
CBinaryCommand::CBinaryCommand(int command) :m_command(command) CBinaryCommand::CBinaryCommand(int command) :m_command(command)
{} {}
void CBinaryCommand::SetCommand(int command) void CBinaryCommand::SetCommand(int command)
{ {
m_command = command; m_command = command;
} }
int CBinaryCommand::GetCommand() const int CBinaryCommand::GetCommand() const
{ {
return m_command; return m_command;
} }
CalculationManager::CommandType CBinaryCommand::GetCommandType() const CalculationManager::CommandType CBinaryCommand::GetCommandType() const
{ {
return CalculationManager::CommandType::BinaryCommand; return CalculationManager::CommandType::BinaryCommand;
} }
void CBinaryCommand::Accept(_In_ ISerializeCommandVisitor &commandVisitor) void CBinaryCommand::Accept(_In_ ISerializeCommandVisitor &commandVisitor)
@ -111,8 +111,8 @@ void COpndCommand::Initialize(Rational const& rat)
} }
const shared_ptr<CalculatorVector<int>> & COpndCommand::GetCommands() const const shared_ptr<CalculatorVector<int>> & COpndCommand::GetCommands() const
{ {
return m_commands; return m_commands;
} }
void COpndCommand::SetCommands(shared_ptr<CalculatorVector<int>> const& commands) void COpndCommand::SetCommands(shared_ptr<CalculatorVector<int>> const& commands)
@ -166,7 +166,7 @@ void COpndCommand::RemoveFromEnd()
{ {
unsigned int nCommands; unsigned int nCommands;
m_commands->GetSize(&nCommands); m_commands->GetSize(&nCommands);
if (nCommands == 1) if (nCommands == 1)
{ {
ClearAllAndAppendCommand(CalculationManager::Command::Command0); ClearAllAndAppendCommand(CalculationManager::Command::Command0);
@ -185,8 +185,8 @@ void COpndCommand::RemoveFromEnd()
} }
bool COpndCommand::IsNegative() const bool COpndCommand::IsNegative() const
{ {
return m_fNegative; return m_fNegative;
} }
bool COpndCommand::IsSciFmt() const bool COpndCommand::IsSciFmt() const
@ -195,13 +195,13 @@ bool COpndCommand::IsSciFmt() const
} }
bool COpndCommand::IsDecimalPresent() const bool COpndCommand::IsDecimalPresent() const
{ {
return m_fDecimal; return m_fDecimal;
} }
CalculationManager::CommandType COpndCommand::GetCommandType() const CalculationManager::CommandType COpndCommand::GetCommandType() const
{ {
return CalculationManager::CommandType::OperandCommand; return CalculationManager::CommandType::OperandCommand;
} }
void COpndCommand::ClearAllAndAppendCommand(CalculationManager::Command command) void COpndCommand::ClearAllAndAppendCommand(CalculationManager::Command command)
@ -283,7 +283,7 @@ const wstring & COpndCommand::GetToken(wchar_t decimalSymbol)
m_token.clear(); m_token.clear();
m_token.append(&chZero); m_token.append(&chZero);
} }
return m_token; return m_token;
} }

View File

@ -45,7 +45,7 @@
// Key IDs: // 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. // 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 // Also, the order of the controls must match the order of the control names
// in the string table. // in the string table.
@ -97,7 +97,7 @@
#define IDC_FAC 113 #define IDC_FAC 113
#define IDC_REC 114 #define IDC_REC 114
#define IDC_DMS 115 #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_POW10 117 // 10 ^ x
#define IDC_PERCENT 118 #define IDC_PERCENT 118
#define IDC_UNARYLAST IDC_PERCENT #define IDC_UNARYLAST IDC_PERCENT

View File

@ -85,7 +85,7 @@ private:
// if it hasn't yet been computed // if it hasn't yet been computed
bool m_bChangeOp; /* Flag for changing operation. */ bool m_bChangeOp; /* Flag for changing operation. */
bool m_bRecord; // Global mode: recording or displaying 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 CalcEngine::CalcInput m_input; // Global calc input object for decimal strings
eNUMOBJ_FMT m_nFE; /* Scientific notation conversion flag. */ eNUMOBJ_FMT m_nFE; /* Scientific notation conversion flag. */
CalcEngine::Rational m_maxTrigonometricNum; CalcEngine::Rational m_maxTrigonometricNum;

View File

@ -6,7 +6,7 @@
#include "Rational.h" #include "Rational.h"
// Space to hold enough digits for a quadword binary number (64) plus digit separator strings for that number (20) // 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 namespace CalcEngine
{ {

View File

@ -128,7 +128,7 @@
#define SIDS_NFACTORIAL L"33" #define SIDS_NFACTORIAL L"33"
#define SIDS_RECIPROCAL L"34" #define SIDS_RECIPROCAL L"34"
#define SIDS_DMS L"35" #define SIDS_DMS L"35"
#define SIDS_CUBEROOT L"36" #define SIDS_CUBEROOT L"36"
#define SIDS_POWTEN L"37" #define SIDS_POWTEN L"37"
#define SIDS_PERCENT L"38" #define SIDS_PERCENT L"38"
#define SIDS_SCIENTIFIC_NOTATION L"39" #define SIDS_SCIENTIFIC_NOTATION L"39"
@ -200,7 +200,7 @@
#define SIDS_NOMEM L"105" #define SIDS_NOMEM L"105"
#define SIDS_TOOMANY L"106" #define SIDS_TOOMANY L"106"
#define SIDS_OVERFLOW L"107" #define SIDS_OVERFLOW L"107"
#define SIDS_NORESULT L"108" #define SIDS_NORESULT L"108"
#define SIDS_INSUFFICIENT_DATA L"109" #define SIDS_INSUFFICIENT_DATA L"109"
// 110 is skipped by CSTRINGSENGMAX // 110 is skipped by CSTRINGSENGMAX
#define SIDS_ERR_UNK_CH L"111" #define SIDS_ERR_UNK_CH L"111"
@ -214,7 +214,7 @@
#define SIDS_ERR_INPUT_OVERFLOW L"119" #define SIDS_ERR_INPUT_OVERFLOW L"119"
#define SIDS_ERR_OUTPUT_OVERFLOW L"120" #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_PLUS_MINUS),
std::wstring(SIDS_C), std::wstring(SIDS_C),
@ -252,7 +252,7 @@ __declspec(selectany) std::wstring g_sids[] =
std::wstring(SIDS_NFACTORIAL), std::wstring(SIDS_NFACTORIAL),
std::wstring(SIDS_RECIPROCAL), std::wstring(SIDS_RECIPROCAL),
std::wstring(SIDS_DMS), std::wstring(SIDS_DMS),
std::wstring(SIDS_CUBEROOT), std::wstring(SIDS_CUBEROOT),
std::wstring(SIDS_POWTEN), std::wstring(SIDS_POWTEN),
std::wstring(SIDS_PERCENT), std::wstring(SIDS_PERCENT),
std::wstring(SIDS_SCIENTIFIC_NOTATION), std::wstring(SIDS_SCIENTIFIC_NOTATION),
@ -324,7 +324,7 @@ __declspec(selectany) std::wstring g_sids[] =
std::wstring(SIDS_NOMEM), std::wstring(SIDS_NOMEM),
std::wstring(SIDS_TOOMANY), std::wstring(SIDS_TOOMANY),
std::wstring(SIDS_OVERFLOW), std::wstring(SIDS_OVERFLOW),
std::wstring(SIDS_NORESULT), std::wstring(SIDS_NORESULT),
std::wstring(SIDS_INSUFFICIENT_DATA), std::wstring(SIDS_INSUFFICIENT_DATA),
std::wstring(SIDS_ERR_UNK_CH), std::wstring(SIDS_ERR_UNK_CH),
std::wstring(SIDS_ERR_UNK_FN), std::wstring(SIDS_ERR_UNK_FN),

View File

@ -10,8 +10,8 @@
// maximum depth you can get by precedence. It is just an array's size limit. // maximum depth you can get by precedence. It is just an array's size limit.
static constexpr size_t MAXPRECDEPTH = 25; static constexpr size_t MAXPRECDEPTH = 25;
// Helper class really a internal class to CCalcEngine, to accumulate each history line of text by collecting the // 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 // 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. // rely on CCalcEngine calling it in appropriate order.
class CHistoryCollector { class CHistoryCollector {
public: public:
@ -39,13 +39,13 @@ private:
ICalcDisplay *m_pCalcDisplay; ICalcDisplay *m_pCalcDisplay;
int m_iCurLineHistStart; // index of the beginning of the current equation 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 // 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_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 int m_lastBinOpStartIndex; // index of the beginning of the last binary operator added to the history
std::array<int, MAXPRECDEPTH> m_operandIndices; // Stack of index of opnd's beginning for each '('. A parallel array to m_hnoParNum, but abstracted independently of that std::array<int, MAXPRECDEPTH> 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 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; wchar_t m_decimalSymbol;
std::shared_ptr<CalculatorVector <std::pair<std::wstring, int>>> m_spTokens; std::shared_ptr<CalculatorVector <std::pair<std::wstring, int>>> m_spTokens;
std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> m_spCommands; std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> m_spCommands;

View File

@ -2,17 +2,17 @@
// Licensed under the MIT License. // Licensed under the MIT License.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Package Title ratpak // Package Title ratpak
// File basex.c // File basex.c
// Copyright (C) 1995-97 Microsoft // Copyright (C) 1995-97 Microsoft
// Date 03-14-97 // Date 03-14-97
// //
// //
// Description // Description
// //
// Contains number routines for internal base computations, these assume // Contains number routines for internal base computations, these assume
// internal base is a power of 2. // internal base is a power of 2.
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "pch.h" #include "pch.h"
#include "ratpak.h" #include "ratpak.h"
@ -41,7 +41,7 @@ void __inline mulnumx( PNUMBER *pa, PNUMBER b )
{ {
// If b is not one we multiply // If b is not one we multiply
if ( (*pa)->cdigit > 1 || (*pa)->mant[0] != 1 || (*pa)->exp != 0 ) if ( (*pa)->cdigit > 1 || (*pa)->mant[0] != 1 || (*pa)->exp != 0 )
{ {
// pa and b are both non-one. // pa and b are both non-one.
_mulnumx( pa, b ); _mulnumx( pa, b );
} }
@ -91,7 +91,7 @@ void _mulnumx( PNUMBER *pa, PNUMBER b )
MANTTYPE da=0; // da is the digit from the fist number. MANTTYPE da=0; // da is the digit from the fist number.
TWO_MANTTYPE cy=0; // cy is the carry resulting from the addition of TWO_MANTTYPE cy=0; // cy is the carry resulting from the addition of
// a multiplied row into the result. // 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. // multiply, AND the carry of that multiply.
long icdigit=0; // Index of digit being calculated in final result. long icdigit=0; // Index of digit being calculated in final result.
@ -110,8 +110,8 @@ void _mulnumx( PNUMBER *pa, PNUMBER b )
{ {
da = *ptra++; da = *ptra++;
ptrb = b->mant; ptrb = b->mant;
// Shift ptrc, and ptrcoffset, one for each digit // Shift ptrc, and ptrcoffset, one for each digit
ptrc = ptrcoffset++; ptrc = ptrcoffset++;
for ( ibdigit = b->cdigit; ibdigit > 0; ibdigit-- ) for ( ibdigit = b->cdigit; ibdigit > 0; ibdigit-- )
@ -126,28 +126,28 @@ void _mulnumx( PNUMBER *pa, PNUMBER b )
c->cdigit++; c->cdigit++;
} }
} }
// If result is nonzero, or while result of carry is nonzero... // If result is nonzero, or while result of carry is nonzero...
while ( mcy || cy ) while ( mcy || cy )
{ {
// update carry from addition(s) and multiply. // update carry from addition(s) and multiply.
cy += (TWO_MANTTYPE)ptrc[icdigit]+((DWORD)mcy&((DWORD)~BASEX)); cy += (TWO_MANTTYPE)ptrc[icdigit]+((DWORD)mcy&((DWORD)~BASEX));
// update result digit from // update result digit from
ptrc[icdigit++]=(MANTTYPE)((DWORD)cy&((DWORD)~BASEX)); ptrc[icdigit++]=(MANTTYPE)((DWORD)cy&((DWORD)~BASEX));
// update carries from // update carries from
mcy >>= BASEXPWR; mcy >>= BASEXPWR;
cy >>= BASEXPWR; cy >>= BASEXPWR;
} }
ptrb++; ptrb++;
ptrc++; ptrc++;
} }
} }
// prevent different kinds of zeros, by stripping leading duplicate zeros. // prevent different kinds of zeros, by stripping leading duplicate zeros.
// digits are in order of increasing significance. // digits are in order of increasing significance.
while ( c->cdigit > 1 && c->mant[c->cdigit-1] == 0 ) while ( c->cdigit > 1 && c->mant[c->cdigit-1] == 0 )
@ -198,7 +198,7 @@ void numpowlongx( _Inout_ PNUMBER *proot, _In_ long power )
} }
destroynum( *proot ); destroynum( *proot );
*proot=lret; *proot=lret;
} }
void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision); void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision);
@ -275,14 +275,14 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
a=*pa; a=*pa;
if ( thismax < a->cdigit ) 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. // for.
thismax = a->cdigit; thismax = a->cdigit;
} }
if ( thismax < b->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. // for.
thismax = b->cdigit; thismax = b->cdigit;
} }
@ -317,7 +317,7 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
digit *= 2; digit *= 2;
} }
if ( lessnum( rem, tmp ) ) if ( lessnum( rem, tmp ) )
{ {
// too far, back up... // too far, back up...
destroynum( tmp ); destroynum( tmp );
digit /= 2; digit /= 2;
@ -326,7 +326,7 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
} }
tmp->sign *= -1; tmp->sign *= -1;
addnum( &rem, tmp, BASEX ); addnum( &rem, tmp, BASEX );
destroynum( tmp ); destroynum( tmp );
destroynum( lasttmp ); destroynum( lasttmp );
*ptrc |= digit; *ptrc |= digit;
@ -341,7 +341,7 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
} }
if ( !cdigits ) if ( !cdigits )
{ {
// A zero, make sure no weird exponents creep in // A zero, make sure no weird exponents creep in
c->exp = 0; c->exp = 0;
c->cdigit = 1; c->cdigit = 1;
@ -350,7 +350,7 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
{ {
c->cdigit = cdigits; c->cdigit = cdigits;
c->exp -= 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. // zeros. digits are in order of increasing significance.
while ( c->cdigit > 1 && c->mant[c->cdigit-1] == 0 ) while ( c->cdigit > 1 && c->mant[c->cdigit-1] == 0 )
{ {

View File

@ -801,7 +801,7 @@ PNUMBER longtonum( long inlong, uint32_t radix)
// RETURN: number // RETURN: number
// //
// DESCRIPTION: Returns a number representation in the // 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 // negative number and takes the full range of unsigned number
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -817,7 +817,7 @@ PNUMBER Ulongtonum(unsigned long inlong, uint32_t radix)
pnumret->cdigit = 0; pnumret->cdigit = 0;
pnumret->exp = 0; pnumret->exp = 0;
pnumret->sign = 1; pnumret->sign = 1;
do { do {
*pmant++ = (MANTTYPE)(inlong % radix); *pmant++ = (MANTTYPE)(inlong % radix);
inlong /= radix; inlong /= radix;

View File

@ -46,8 +46,8 @@ void _exprat( PRAT *px, int32_t precision)
{ {
CREATETAYLOR(); CREATETAYLOR();
addnum(&(pret->pp),num_one, BASEX); addnum(&(pret->pp),num_one, BASEX);
addnum(&(pret->pq),num_one, BASEX); addnum(&(pret->pq),num_one, BASEX);
DUPRAT(thisterm,pret); DUPRAT(thisterm,pret);
n2=longtonum(0L, BASEX); n2=longtonum(0L, BASEX);
@ -81,7 +81,7 @@ void exprat( PRAT *px, uint32_t radix, int32_t precision)
ratpowlong( &pwr, intpwr, precision); ratpowlong( &pwr, intpwr, precision);
subrat(px, pint, precision); subrat(px, pint, precision);
// It just so happens to be an integral power of e. // It just so happens to be an integral power of e.
if ( rat_gt( *px, rat_negsmallest, precision) && rat_lt( *px, rat_smallest, precision) ) 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(); CREATETAYLOR();
createrat(thisterm); createrat(thisterm);
// sub one from x // sub one from x
(*px)->pq->sign *= -1; (*px)->pq->sign *= -1;
addnum(&((*px)->pp),(*px)->pq, BASEX); addnum(&((*px)->pp),(*px)->pq, BASEX);
@ -158,14 +158,14 @@ void lograt( PRAT *px, int32_t precision)
bool fneglog; bool fneglog;
PRAT pwr = nullptr; // pwr is the large scaling factor. PRAT pwr = nullptr; // pwr is the large scaling factor.
PRAT offset = nullptr; // offset is the incremental scaling factor. PRAT offset = nullptr; // offset is the incremental scaling factor.
// Check for someone taking the log of zero or a negative number. // Check for someone taking the log of zero or a negative number.
if ( rat_le( *px, rat_zero, precision) ) if ( rat_le( *px, rat_zero, precision) )
{ {
throw( CALC_E_DOMAIN ); throw( CALC_E_DOMAIN );
} }
// Get number > 1, for scaling // Get number > 1, for scaling
fneglog = rat_lt( *px, rat_one, precision); fneglog = rat_lt( *px, rat_one, precision);
if ( fneglog ) if ( fneglog )
@ -176,12 +176,12 @@ void lograt( PRAT *px, int32_t precision)
(*px)->pp = (*px)->pq; (*px)->pp = (*px)->pq;
(*px)->pq = pnumtemp; (*px)->pq = pnumtemp;
} }
// Scale the number within BASEX factor of 1, for the large scale. // Scale the number within BASEX factor of 1, for the large scale.
// log(x*2^(BASEXPWR*k)) = BASEXPWR*k*log(2)+log(x) // log(x*2^(BASEXPWR*k)) = BASEXPWR*k*log(2)+log(x)
if ( LOGRAT2(*px) > 1 ) if ( LOGRAT2(*px) > 1 )
{ {
// Take advantage of px's base BASEX to scale quickly down to // Take advantage of px's base BASEX to scale quickly down to
// a reasonable range. // a reasonable range.
long intpwr; long intpwr;
intpwr=LOGRAT2(*px)-1; intpwr=LOGRAT2(*px)-1;
@ -206,17 +206,17 @@ void lograt( PRAT *px, int32_t precision)
} }
_lograt(px, precision); _lograt(px, precision);
// Add the large and small scaling factors, take into account // Add the large and small scaling factors, take into account
// small scaling was done in e_to_one_half chunks. // small scaling was done in e_to_one_half chunks.
divrat(&offset, rat_two, precision); divrat(&offset, rat_two, precision);
addrat(&pwr, offset, precision); addrat(&pwr, offset, precision);
// And add the resulting scaling factor to the answer. // And add the resulting scaling factor to the answer.
addrat(px, pwr, precision); addrat(px, pwr, precision);
trimit(px, precision); trimit(px, precision);
// If number started out < 1 rescale answer to negative. // If number started out < 1 rescale answer to negative.
if ( fneglog ) if ( fneglog )
{ {
@ -224,9 +224,9 @@ void lograt( PRAT *px, int32_t precision)
} }
destroyrat(offset); destroyrat(offset);
destroyrat(pwr); destroyrat(pwr);
} }
void log10rat( PRAT *px, int32_t precision) 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 // even or not
bool IsEven(PRAT x, uint32_t radix, int32_t precision) 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. // 1. Initialize result.
PRAT pxPow = nullptr; PRAT pxPow = nullptr;
DUPRAT(pxPow, *px); DUPRAT(pxPow, *px);
// 2. Calculate pxPow = px ^ yNumerator // 2. Calculate pxPow = px ^ yNumerator
// if yNumerator is not 1 // if yNumerator is not 1
if (!rat_equ(yNumerator, rat_one, precision)) 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; PRAT originalResult = nullptr;
DUPRAT(originalResult, pxPow); DUPRAT(originalResult, pxPow);
powratcomp(&originalResult, oneoveryDenom, radix, precision); powratcomp(&originalResult, oneoveryDenom, radix, precision);
// ################################## // ##################################
// Round the originalResult to roundedResult // Round the originalResult to roundedResult
// ################################## // ##################################
@ -375,7 +375,7 @@ void powratNumeratorDenominator(PRAT *px, PRAT y, uint32_t radix, int32_t precis
else else
{ {
DUPRAT(*px, originalResult); DUPRAT(*px, originalResult);
} }
destroyrat(oneoveryDenom); destroyrat(oneoveryDenom);
destroyrat(originalResult); destroyrat(originalResult);
@ -429,7 +429,7 @@ void powratcomp(PRAT *px, PRAT y, uint32_t radix, int32_t precision)
sign = 1; sign = 1;
} }
} }
else else
{ {
PRAT pxint= nullptr; PRAT pxint= nullptr;
DUPRAT(pxint,*px); DUPRAT(pxint,*px);
@ -491,7 +491,7 @@ void powratcomp(PRAT *px, PRAT y, uint32_t radix, int32_t precision)
PRAT pNumerator = nullptr; PRAT pNumerator = nullptr;
PRAT pDenominator = nullptr; PRAT pDenominator = nullptr;
bool fBadExponent = false; bool fBadExponent = false;
// Get the numbers in arbitrary precision rational number format // Get the numbers in arbitrary precision rational number format
DUPRAT(pNumerator, rat_zero); // pNumerator->pq is 1 one DUPRAT(pNumerator, rat_zero); // pNumerator->pq is 1 one
DUPRAT(pDenominator, rat_zero); // pDenominator->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(pNumerator);
destroyrat(pDenominator); destroyrat(pDenominator);
if (fBadExponent) if (fBadExponent)
{ {
throw( CALC_E_DOMAIN ); throw( CALC_E_DOMAIN );

View File

@ -73,17 +73,17 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
PRAT ratprec = nullptr; PRAT ratprec = nullptr;
PRAT ratRadix = nullptr; PRAT ratRadix = nullptr;
long oldprec; long oldprec;
// Set up constants and initial conditions // Set up constants and initial conditions
oldprec = precision; oldprec = precision;
ratprec = longtorat( oldprec ); ratprec = longtorat( oldprec );
// Find the best 'A' for convergence to the required precision. // Find the best 'A' for convergence to the required precision.
a=longtorat( radix ); a=longtorat( radix );
lograt(&a, precision); lograt(&a, precision);
mulrat(&a, ratprec, 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 // if we scale n between 0.5 and 1.5
addrat(&a, rat_two, precision); addrat(&a, rat_two, precision);
DUPRAT(tmp,a); DUPRAT(tmp,a);
@ -91,9 +91,9 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
mulrat(&tmp, *pn, precision); mulrat(&tmp, *pn, precision);
addrat(&a, tmp, precision); addrat(&a, tmp, precision);
addrat(&a, rat_one, precision); addrat(&a, rat_one, precision);
// Calculate the necessary bump in precision and up the 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)); // precision += ln(exp(a)*pow(a,n+1.5))-ln(radix));
DUPRAT(tmp,*pn); DUPRAT(tmp,*pn);
one_pt_five=longtorat( 3L ); one_pt_five=longtorat( 3L );
@ -110,7 +110,7 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
lograt( &tmp, precision); lograt( &tmp, precision);
subrat( &term, tmp, precision); subrat( &term, tmp, precision);
precision += rattolong( term, radix, precision); precision += rattolong( term, radix, precision);
// Set up initial terms for series, refer to series in above comment block. // Set up initial terms for series, refer to series in above comment block.
DUPRAT(factorial,rat_one); // Start factorial out with one DUPRAT(factorial,rat_one); // Start factorial out with one
count = longtonum( 0L, BASEX ); count = longtonum( 0L, BASEX );
@ -120,7 +120,7 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
// a2=a^2 // a2=a^2
DUPRAT(a2,a); DUPRAT(a2,a);
mulrat(&a2, a, precision); mulrat(&a2, a, precision);
// sum=(1/n)-(a/(n+1)) // sum=(1/n)-(a/(n+1))
DUPRAT(sum,rat_one); DUPRAT(sum,rat_one);
divrat(&sum, *pn, precision); divrat(&sum, *pn, precision);
@ -136,14 +136,14 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
divrat(&err, ratRadix, precision); divrat(&err, ratRadix, precision);
// Just get something not tiny in term // Just get something not tiny in term
DUPRAT(term, rat_two ); DUPRAT(term, rat_two );
// Loop until precision is reached, or asked to halt. // Loop until precision is reached, or asked to halt.
while ( !zerrat( term ) && rat_gt( term, err, precision) ) while ( !zerrat( term ) && rat_gt( term, err, precision) )
{ {
addrat(pn, rat_two, precision); addrat(pn, rat_two, precision);
// WARNING: mixing numbers and rationals here. // WARNING: mixing numbers and rationals here.
// for speed and efficiency. // for speed and efficiency.
INC(count); INC(count);
mulnumx(&(factorial->pp),count); mulnumx(&(factorial->pp),count);
@ -166,15 +166,15 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
DUPRAT(term,rat_one); DUPRAT(term,rat_one);
divrat( &term, *pn, precision); divrat( &term, *pn, precision);
subrat( &term, tmp, precision); subrat( &term, tmp, precision);
divrat (&term, factorial, precision); divrat (&term, factorial, precision);
addrat( &sum, term, precision); addrat( &sum, term, precision);
ABSRAT(term); ABSRAT(term);
} }
// Multiply by factor. // Multiply by factor.
mulrat( &sum, mpy, precision); mulrat( &sum, mpy, precision);
// And cleanup // And cleanup
precision = oldprec; precision = oldprec;
destroyrat(ratprec); destroyrat(ratprec);
@ -199,13 +199,13 @@ void factrat( PRAT *px, uint32_t radix, int32_t precision)
PRAT fact = nullptr; PRAT fact = nullptr;
PRAT frac = nullptr; PRAT frac = nullptr;
PRAT neg_rat_one = nullptr; PRAT neg_rat_one = nullptr;
if ( rat_gt( *px, rat_max_fact, precision) || rat_lt( *px, rat_min_fact, precision) ) 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. // Don't attempt factorial of anything too large or small.
throw CALC_E_OVERFLOW; throw CALC_E_OVERFLOW;
} }
DUPRAT(fact,rat_one); DUPRAT(fact,rat_one);
DUPRAT(neg_rat_one,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); mulrat( &fact, *px, precision);
subrat( px, rat_one, precision); subrat( px, rat_one, precision);
} }
// Added to make numbers 'close enough' to integers use integer factorial. // Added to make numbers 'close enough' to integers use integer factorial.
if ( LOGRATRADIX(*px) <= -precision) if ( LOGRATRADIX(*px) <= -precision)
{ {

View File

@ -69,13 +69,13 @@ void _asinrat( PRAT *px, int32_t precision)
{ {
CREATETAYLOR(); CREATETAYLOR();
DUPRAT(pret,*px); DUPRAT(pret,*px);
DUPRAT(thisterm,*px); DUPRAT(thisterm,*px);
DUPNUM(n2,num_one); DUPNUM(n2,num_one);
do do
{ {
NEXTTERM(xx,MULNUM(n2) MULNUM(n2) NEXTTERM(xx,MULNUM(n2) MULNUM(n2)
INC(n2) DIVNUM(n2) INC(n2) DIVNUM(n2), precision); INC(n2) DIVNUM(n2) INC(n2) DIVNUM(n2), precision);
} }
while ( !SMALL_ENOUGH_RAT( thisterm, 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)->pp->sign = 1;
(*px)->pq->sign = 1; (*px)->pq->sign = 1;
// Avoid the really bad part of the asin curve near +/-1. // Avoid the really bad part of the asin curve near +/-1.
DUPRAT(phack,*px); DUPRAT(phack,*px);
subrat(&phack, rat_one, precision); subrat(&phack, rat_one, precision);
@ -185,15 +185,15 @@ void _acosrat( PRAT *px, int32_t precision)
{ {
CREATETAYLOR(); CREATETAYLOR();
createrat(thisterm); createrat(thisterm);
thisterm->pp=longtonum( 1L, BASEX ); thisterm->pp=longtonum( 1L, BASEX );
thisterm->pq=longtonum( 1L, BASEX ); thisterm->pq=longtonum( 1L, BASEX );
DUPNUM(n2,num_one); DUPNUM(n2,num_one);
do do
{ {
NEXTTERM(xx,MULNUM(n2) MULNUM(n2) NEXTTERM(xx,MULNUM(n2) MULNUM(n2)
INC(n2) DIVNUM(n2) INC(n2) DIVNUM(n2), precision); INC(n2) DIVNUM(n2) INC(n2) DIVNUM(n2), precision);
} }
while ( !SMALL_ENOUGH_RAT( thisterm, 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)->pp->sign = 1;
(*px)->pq->sign = 1; (*px)->pq->sign = 1;
if ( rat_equ( *px, rat_one, precision) ) if ( rat_equ( *px, rat_one, precision) )
{ {
if ( sgn == -1 ) if ( sgn == -1 )
@ -274,7 +274,7 @@ void _atanrat( PRAT *px, int32_t precision)
{ {
CREATETAYLOR(); CREATETAYLOR();
DUPRAT(pret,*px); DUPRAT(pret,*px);
DUPRAT(thisterm,*px); DUPRAT(thisterm,*px);
DUPNUM(n2,num_one); DUPNUM(n2,num_one);
@ -298,7 +298,7 @@ void atanrat( PRAT *px, uint32_t radix, int32_t precision)
(*px)->pp->sign = 1; (*px)->pp->sign = 1;
(*px)->pq->sign = 1; (*px)->pq->sign = 1;
if ( rat_gt( (*px), pt_eight_five, precision) ) if ( rat_gt( (*px), pt_eight_five, precision) )
{ {
if ( rat_gt( (*px), rat_two, 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); subrat(px, tmpx, precision);
destroyrat( tmpx ); destroyrat( tmpx );
} }
else else
{ {
(*px)->pp->sign = sgn; (*px)->pp->sign = sgn;
DUPRAT(tmpx,*px); DUPRAT(tmpx,*px);

View File

@ -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) ) if ( rat_gt( *px, pt_eight_five, precision) || rat_lt( *px, neg_pt_eight_five, precision) )
{ {
PRAT ptmp = nullptr; PRAT ptmp = nullptr;
DUPRAT(ptmp,(*px)); DUPRAT(ptmp,(*px));
mulrat(&ptmp, *px, precision); mulrat(&ptmp, *px, precision);
addrat(&ptmp, rat_one, precision); addrat(&ptmp, rat_one, precision);
rootrat(&ptmp, rat_two, radix, precision); rootrat(&ptmp, rat_two, radix, precision);
@ -73,14 +73,14 @@ void asinhrat( PRAT *px, uint32_t radix, int32_t precision)
CREATETAYLOR(); CREATETAYLOR();
xx->pp->sign *= -1; xx->pp->sign *= -1;
DUPRAT(pret,(*px)); DUPRAT(pret,(*px));
DUPRAT(thisterm,(*px)); DUPRAT(thisterm,(*px));
DUPNUM(n2,num_one); DUPNUM(n2,num_one);
do do
{ {
NEXTTERM(xx,MULNUM(n2) MULNUM(n2) NEXTTERM(xx,MULNUM(n2) MULNUM(n2)
INC(n2) DIVNUM(n2) INC(n2) DIVNUM(n2), precision); INC(n2) DIVNUM(n2) INC(n2) DIVNUM(n2), precision);
} }
while ( !SMALL_ENOUGH_RAT( thisterm, precision) ); while ( !SMALL_ENOUGH_RAT( thisterm, precision) );
@ -99,7 +99,7 @@ void asinhrat( PRAT *px, uint32_t radix, int32_t precision)
// hyperbolic cose of // hyperbolic cose of
// RETURN: acosh of x in PRAT form. // RETURN: acosh of x in PRAT form.
// //
// EXPLANATION: This uses // EXPLANATION: This uses
// //
// acosh(x)=ln(x+sqrt(x^2-1)) // acosh(x)=ln(x+sqrt(x^2-1))
// //
@ -117,7 +117,7 @@ void acoshrat( PRAT *px, uint32_t radix, int32_t precision)
else else
{ {
PRAT ptmp = nullptr; PRAT ptmp = nullptr;
DUPRAT(ptmp,(*px)); DUPRAT(ptmp,(*px));
mulrat(&ptmp, *px, precision); mulrat(&ptmp, *px, precision);
subrat(&ptmp, rat_one, precision); subrat(&ptmp, rat_one, precision);
rootrat(&ptmp,rat_two, radix, precision); rootrat(&ptmp,rat_two, radix, precision);
@ -148,7 +148,7 @@ void atanhrat( PRAT *px, int32_t precision)
{ {
PRAT ptmp = nullptr; PRAT ptmp = nullptr;
DUPRAT(ptmp,(*px)); DUPRAT(ptmp,(*px));
subrat(&ptmp, rat_one, precision); subrat(&ptmp, rat_one, precision);
addrat(px, rat_one, precision); addrat(px, rat_one, precision);
divrat(px, ptmp, precision); divrat(px, ptmp, precision);

View File

@ -49,7 +49,7 @@ void rshrat( PRAT *pa, PRAT b, uint32_t radix, int32_t precision)
intrat(pa, radix, precision); intrat(pa, radix, precision);
if ( !zernum( (*pa)->pp ) ) if ( !zernum( (*pa)->pp ) )
{ {
// If input is zero we're done. // If input is zero we're done.
if ( rat_lt( b, rat_min_exp, precision) ) if ( rat_lt( b, rat_min_exp, precision) )
{ {
@ -155,11 +155,11 @@ void boolnum( PNUMBER *pa, PNUMBER b, int func )
pchc = c->mant; pchc = c->mant;
for ( ;cdigits > 0; cdigits--, mexp++ ) for ( ;cdigits > 0; cdigits--, mexp++ )
{ {
da = ( ( ( mexp >= a->exp ) && ( cdigits + a->exp - c->exp > da = ( ( ( mexp >= a->exp ) && ( cdigits + a->exp - c->exp >
(c->cdigit - a->cdigit) ) ) ? (c->cdigit - a->cdigit) ) ) ?
*pcha++ : 0 ); *pcha++ : 0 );
db = ( ( ( mexp >= b->exp ) && ( cdigits + b->exp - c->exp > db = ( ( ( mexp >= b->exp ) && ( cdigits + b->exp - c->exp >
(c->cdigit - b->cdigit) ) ) ? (c->cdigit - b->cdigit) ) ) ?
*pchb++ : 0 ); *pchb++ : 0 );
switch ( func ) switch ( func )
{ {
@ -205,15 +205,14 @@ void modrat( PRAT *pa, PRAT b )
throw CALC_E_INDEFINITE; throw CALC_E_INDEFINITE;
} }
DUPRAT(tmp,b); DUPRAT(tmp,b);
mulnumx( &((*pa)->pp), tmp->pq ); mulnumx( &((*pa)->pp), tmp->pq );
mulnumx( &(tmp->pp), (*pa)->pq ); mulnumx( &(tmp->pp), (*pa)->pq );
remnum( &((*pa)->pp), tmp->pp, BASEX ); remnum( &((*pa)->pp), tmp->pp, BASEX );
mulnumx( &((*pa)->pq), tmp->pq ); 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); RENORMALIZE(*pa);
destroyrat( tmp ); destroyrat( tmp );
} }

View File

@ -2,20 +2,20 @@
// Licensed under the MIT License. // Licensed under the MIT License.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Package Title ratpak // Package Title ratpak
// File num.c // File num.c
// Copyright (C) 1995-97 Microsoft // Copyright (C) 1995-97 Microsoft
// Date 01-16-95 // Date 01-16-95
// //
// //
// Description // Description
// //
// Contains number routines for add, mul, div, rem and other support // Contains number routines for add, mul, div, rem and other support
// and longs. // and longs.
// //
// Special Information // Special Information
// //
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "pch.h" #include "pch.h"
#include "ratpak.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. long fcomplb = 0; // fcomplb is a flag to signal b is negative.
a=*pa; a=*pa;
// Calculate the overlap of the numbers after alignment, this includes // Calculate the overlap of the numbers after alignment, this includes
// necessary padding 0's // necessary padding 0's
cdigits = max( a->cdigit+a->exp, b->cdigit+b->exp ) - 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; pcha = a->mant;
pchb = b->mant; pchb = b->mant;
pchc = c->mant; pchc = c->mant;
// Figure out the sign of the numbers // Figure out the sign of the numbers
if ( a->sign != b->sign ) if ( a->sign != b->sign )
{ {
@ -98,21 +98,21 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
fcompla = ( a->sign == -1 ); fcompla = ( a->sign == -1 );
fcomplb = ( b->sign == -1 ); fcomplb = ( b->sign == -1 );
} }
// Loop over all the digits, real and 0 padded. Here we know a and b are // Loop over all the digits, real and 0 padded. Here we know a and b are
// aligned // aligned
for ( ;cdigits > 0; cdigits--, mexp++ ) for ( ;cdigits > 0; cdigits--, mexp++ )
{ {
// Get digit from a, taking padding into account. // Get digit from a, taking padding into account.
da = ( ( ( mexp >= a->exp ) && ( cdigits + a->exp - c->exp > da = ( ( ( mexp >= a->exp ) && ( cdigits + a->exp - c->exp >
(c->cdigit - a->cdigit) ) ) ? (c->cdigit - a->cdigit) ) ) ?
*pcha++ : 0 ); *pcha++ : 0 );
// Get digit from b, taking padding into account. // Get digit from b, taking padding into account.
db = ( ( ( mexp >= b->exp ) && ( cdigits + b->exp - c->exp > db = ( ( ( mexp >= b->exp ) && ( cdigits + b->exp - c->exp >
(c->cdigit - b->cdigit) ) ) ? (c->cdigit - b->cdigit) ) ) ?
*pchb++ : 0 ); *pchb++ : 0 );
// Handle complementing for a and b digit. Might be a better way, but // Handle complementing for a and b digit. Might be a better way, but
// haven't found it yet. // haven't found it yet.
if ( fcompla ) if ( fcompla )
@ -123,20 +123,20 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
{ {
db = (MANTTYPE)(radix) - 1 - db; db = (MANTTYPE)(radix) - 1 - db;
} }
// Update carry as necessary // Update carry as necessary
cy = da + db + cy; cy = da + db + cy;
*pchc++ = (MANTTYPE)(cy % (MANTTYPE)radix); *pchc++ = (MANTTYPE)(cy % (MANTTYPE)radix);
cy /= (MANTTYPE)radix; cy /= (MANTTYPE)radix;
} }
// Handle carry from last sum as extra digit // Handle carry from last sum as extra digit
if ( cy && !(fcompla || fcomplb) ) if ( cy && !(fcompla || fcomplb) )
{ {
*pchc++ = cy; *pchc++ = cy;
c->cdigit++; c->cdigit++;
} }
// Compute sign of result // Compute sign of result
if ( !(fcompla || fcomplb) ) if ( !(fcompla || fcomplb) )
{ {
@ -150,14 +150,14 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
} }
else else
{ {
// In this particular case an overflow or underflow has occurred // In this particular case an overflow or underflow has occurred
// and all the digits need to be complemented, at one time an // 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 // attempt to handle this above was made, it turned out to be much
// slower on average. // slower on average.
c->sign = -1; c->sign = -1;
cy = 1; cy = 1;
for ( ( cdigits = c->cdigit ), (pchc = c->mant); for ( ( cdigits = c->cdigit ), (pchc = c->mant);
cdigits > 0; cdigits > 0;
cdigits-- ) cdigits-- )
{ {
cy = (MANTTYPE)radix - (MANTTYPE)1 - *pchc + cy; 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 // Remove leading zeros, remember digits are in order of
// increasing significance. i.e. 100 would be 0,0,1 // increasing significance. i.e. 100 would be 0,0,1
while ( c->cdigit > 1 && *(--pchc) == 0 ) 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. MANTTYPE da = 0; // da is the digit from the fist number.
TWO_MANTTYPE cy = 0; // cy is the carry resulting from the addition of TWO_MANTTYPE cy = 0; // cy is the carry resulting from the addition of
// a multiplied row into the result. // 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. // multiply, AND the carry of that multiply.
long icdigit = 0; // Index of digit being calculated in final result. 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++; da = *pcha++;
pchb = b->mant; pchb = b->mant;
// Shift pchc, and pchcoffset, one for each digit // Shift pchc, and pchcoffset, one for each digit
pchc = pchcoffset++; pchc = pchcoffset++;
for ( ibdigit = b->cdigit; ibdigit > 0; ibdigit-- ) 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... // If result is nonzero, or while result of carry is nonzero...
while ( mcy || cy ) while ( mcy || cy )
{ {
// update carry from addition(s) and multiply. // update carry from addition(s) and multiply.
cy += (TWO_MANTTYPE)pchc[icdigit]+(mcy%(TWO_MANTTYPE)radix); cy += (TWO_MANTTYPE)pchc[icdigit]+(mcy%(TWO_MANTTYPE)radix);
// update result digit from // update result digit from
pchc[icdigit++]=(MANTTYPE)(cy%(TWO_MANTTYPE)radix); pchc[icdigit++]=(MANTTYPE)(cy%(TWO_MANTTYPE)radix);
// update carries from // update carries from
mcy /= (TWO_MANTTYPE)radix; mcy /= (TWO_MANTTYPE)radix;
cy /= (TWO_MANTTYPE)radix; cy /= (TWO_MANTTYPE)radix;
} }
pchb++; pchb++;
pchc++; pchc++;
} }
} }
// prevent different kinds of zeros, by stripping leading duplicate zeros. // prevent different kinds of zeros, by stripping leading duplicate zeros.
// digits are in order of increasing significance. // digits are in order of increasing significance.
while ( c->cdigit > 1 && c->mant[c->cdigit-1] == 0 ) 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 tmp = nullptr; // tmp is the working remainder.
PNUMBER lasttmp = nullptr; // lasttmp is the last remainder which worked. PNUMBER lasttmp = nullptr; // lasttmp is the last remainder which worked.
// Once *pa is less than b, *pa is the remainder. // Once *pa is less than b, *pa is the remainder.
while ( !lessnum( *pa, b ) ) while ( !lessnum( *pa, b ) )
{ {
@ -336,20 +336,20 @@ void remnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
destroynum( lasttmp ); destroynum( lasttmp );
lasttmp=longtonum( 0, radix); lasttmp=longtonum( 0, radix);
while ( lessnum( tmp, *pa ) ) while ( lessnum( tmp, *pa ) )
{ {
DUPNUM( lasttmp, tmp ); DUPNUM( lasttmp, tmp );
addnum( &tmp, tmp, radix); addnum( &tmp, tmp, radix);
} }
if ( lessnum( *pa, tmp ) ) if ( lessnum( *pa, tmp ) )
{ {
// too far, back up... // too far, back up...
destroynum( tmp ); destroynum( tmp );
tmp=lasttmp; tmp=lasttmp;
lasttmp= nullptr; lasttmp= nullptr;
} }
// Subtract the working remainder from the remainder holder. // Subtract the working remainder from the remainder holder.
tmp->sign = -1*(*pa)->sign; tmp->sign = -1*(*pa)->sign;
addnum( pa, tmp, radix); addnum( pa, tmp, radix);
@ -357,7 +357,7 @@ void remnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
destroynum( tmp ); destroynum( tmp );
destroynum( lasttmp ); 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 ) if ( b->cdigit > 1 || b->mant[0] != 1 || b->exp != 0 )
{ {
// b is not one // b is not one
_divnum( pa, b, radix, precision); _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; tmp->sign = a->sign;
rem->exp = b->cdigit + b->exp - rem->cdigit; 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' // more than radix 'digits'
list<PNUMBER> numberList{ longtonum(0L, radix) }; list<PNUMBER> numberList{ longtonum(0L, radix) };
for (unsigned long i = 1; i < radix; i++) for (unsigned long i = 1; i < radix; i++)
@ -535,21 +535,21 @@ bool equnum( PNUMBER a, PNUMBER b )
pb += b->cdigit - 1; pb += b->cdigit - 1;
cdigits = max( a->cdigit, b->cdigit ); cdigits = max( a->cdigit, b->cdigit );
ccdigits = cdigits; ccdigits = cdigits;
// Loop over all digits until we run out of digits or there is a // Loop over all digits until we run out of digits or there is a
// difference in the digits. // difference in the digits.
for ( ;cdigits > 0; cdigits-- ) for ( ;cdigits > 0; cdigits-- )
{ {
da = ( (cdigits > (ccdigits - a->cdigit) ) ? da = ( (cdigits > (ccdigits - a->cdigit) ) ?
*pa-- : 0 ); *pa-- : 0 );
db = ( (cdigits > (ccdigits - b->cdigit) ) ? db = ( (cdigits > (ccdigits - b->cdigit) ) ?
*pb-- : 0 ); *pb-- : 0 );
if ( da != db ) if ( da != db )
{ {
return false; return false;
} }
} }
// In this case, they are equal. // In this case, they are equal.
return true; return true;
} }
@ -604,9 +604,9 @@ bool lessnum( PNUMBER a, PNUMBER b )
ccdigits = cdigits; ccdigits = cdigits;
for ( ;cdigits > 0; cdigits-- ) for ( ;cdigits > 0; cdigits-- )
{ {
da = ( (cdigits > (ccdigits - a->cdigit) ) ? da = ( (cdigits > (ccdigits - a->cdigit) ) ?
*pa-- : 0 ); *pa-- : 0 );
db = ( (cdigits > (ccdigits - b->cdigit) ) ? db = ( (cdigits > (ccdigits - b->cdigit) ) ?
*pb-- : 0 ); *pb-- : 0 );
diff = da-db; diff = da-db;
if ( diff ) if ( diff )
@ -639,8 +639,8 @@ bool zernum( PNUMBER a )
MANTTYPE *pcha; MANTTYPE *pcha;
length = a->cdigit; length = a->cdigit;
pcha = a->mant; 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 // out of digits
while ( length-- > 0 ) while ( length-- > 0 )
{ {

View File

@ -56,7 +56,7 @@ void gcdrat( PRAT *pa, int32_t precision)
destroynum( pgcd ); destroynum( pgcd );
*pa=a; *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 ); 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); 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) void mulrat( PRAT *pa, PRAT b, int32_t precision)
{ {
// Only do the multiply if it isn't zero. // Only do the multiply if it isn't zero.
if ( !zernum( (*pa)->pp ) ) if ( !zernum( (*pa)->pp ) )
@ -170,7 +170,7 @@ void divrat( PRAT *pa, PRAT b, int32_t precision)
#ifdef DIVGCD #ifdef DIVGCD
gcdrat( pa ); gcdrat( pa );
#endif #endif
} }
@ -215,13 +215,13 @@ void addrat( PRAT *pa, PRAT b, int32_t precision)
if ( equnum( (*pa)->pq, b->pq ) ) 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 // 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. // working with the top half of the rationals.
(*pa)->pp->sign *= (*pa)->pq->sign; (*pa)->pp->sign *= (*pa)->pq->sign;
(*pa)->pq->sign = 1; (*pa)->pq->sign = 1;
b->pp->sign *= b->pq->sign; b->pp->sign *= b->pq->sign;
b->pq->sign = 1; b->pq->sign = 1;
addnum( &((*pa)->pp), b->pp, BASEX ); addnum( &((*pa)->pp), b->pp, BASEX );
} }
@ -236,15 +236,15 @@ void addrat( PRAT *pa, PRAT b, int32_t precision)
destroynum( (*pa)->pq ); destroynum( (*pa)->pq );
(*pa)->pq = bot; (*pa)->pq = bot;
trimit(pa, precision); trimit(pa, precision);
// Get rid of negative zeros here. // Get rid of negative zeros here.
(*pa)->pp->sign *= (*pa)->pq->sign; (*pa)->pp->sign *= (*pa)->pq->sign;
(*pa)->pq->sign = 1; (*pa)->pq->sign = 1;
} }
#ifdef ADDGCD #ifdef ADDGCD
gcdrat( pa ); 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) void rootrat( PRAT *py, PRAT n, uint32_t radix, int32_t precision)
{ {
// Initialize 1/n // Initialize 1/n
PRAT oneovern= nullptr; PRAT oneovern= nullptr;
DUPRAT(oneovern,rat_one); DUPRAT(oneovern,rat_one);

View File

@ -58,7 +58,7 @@ static int cbitsofprecision = RATIO_FOR_DECIMAL * DECIMAL * CALC_DECIMAL_DIGITS_
#endif #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 // chopping internally
// precision used internally // precision used internally
@ -119,8 +119,8 @@ PRAT rat_max_long= nullptr; // max signed long
void ChangeConstants(uint32_t radix, int32_t precision) void ChangeConstants(uint32_t radix, int32_t precision)
{ {
// ratio is set to the number of digits in the current radix, you can get // 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 the internal BASEX radix, this is important for length calculations
// in translating from radix to BASEX and back. // in translating from radix to BASEX and back.
uint64_t limit = static_cast<uint64_t>(BASEX) / static_cast<uint64_t>(radix); uint64_t limit = static_cast<uint64_t>(BASEX) / static_cast<uint64_t>(radix);
@ -213,7 +213,7 @@ void ChangeConstants(uint32_t radix, int32_t precision)
cbitsofprecision = g_ratio * radix * 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. // precision is needed.
long extraPrecision = precision + g_ratio; long extraPrecision = precision + g_ratio;
DUPRAT(pi, rat_half); DUPRAT(pi, rat_half);
@ -348,7 +348,7 @@ bool rat_ge( PRAT a, PRAT b, int32_t precision)
b->pp->sign *= -1; b->pp->sign *= -1;
addrat( &rattmp, b, precision); addrat( &rattmp, b, precision);
b->pp->sign *= -1; b->pp->sign *= -1;
bool bret = ( zernum( rattmp->pp ) || bool bret = ( zernum( rattmp->pp ) ||
rattmp->pp->sign * rattmp->pq->sign == 1 ); rattmp->pp->sign * rattmp->pq->sign == 1 );
destroyrat( rattmp ); destroyrat( rattmp );
return( bret ); return( bret );
@ -472,10 +472,10 @@ void scale( PRAT *px, PRAT scalefact, uint32_t radix, int32_t precision )
{ {
PRAT pret = nullptr; PRAT pret = nullptr;
DUPRAT(pret,*px); 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. // 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) ); (pret->pq->cdigit+pret->pq->exp) );
if ( logscale > 0 ) if ( logscale > 0 )
{ {
@ -508,9 +508,9 @@ void scale2pi( PRAT *px, uint32_t radix, int32_t precision )
PRAT my_two_pi = nullptr; PRAT my_two_pi = nullptr;
DUPRAT(pret,*px); 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. // 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) ); (pret->pq->cdigit+pret->pq->exp) );
if ( logscale > 0 ) if ( logscale > 0 )
{ {
@ -663,16 +663,16 @@ void _readconstants( void )
// ARGUMENTS: PRAT *px, long precision // ARGUMENTS: PRAT *px, long precision
// //
// //
// DESCRIPTION: Chops off digits from rational numbers to avoid time // DESCRIPTION: Chops off digits from rational numbers to avoid time
// explosions in calculations of functions using series. // explosions in calculations of functions using series.
// It can be shown that it is enough to only keep the first n digits // 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 // 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 // scale the smaller by the same number of digits. This will give you
// n-1 digits of accuracy. This dramatically speeds up calculations // n-1 digits of accuracy. This dramatically speeds up calculations
// involving hundreds of digits or more. // involving hundreds of digits or more.
// The last part of this trim dealing with exponents never affects accuracy // 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 ) if ( !g_ftrueinfinite )
{ {
long trim; long trim;
PNUMBER pp=(*px)->pp; PNUMBER pp=(*px)->pp;
PNUMBER pq=(*px)->pq; PNUMBER pq=(*px)->pq;

View File

@ -47,8 +47,8 @@ void scalerat( _Inout_ PRAT *pa, ANGLE_TYPE angletype, uint32_t radix, int32_t p
// EXPLANATION: This uses Taylor series // EXPLANATION: This uses Taylor series
// //
// n // n
// ___ 2j+1 // ___ 2j+1
// \ ] j X // \ ] j X
// \ -1 * --------- // \ -1 * ---------
// / (2j+1)! // / (2j+1)!
// /__] // /__]
@ -73,7 +73,7 @@ void _sinrat( PRAT *px, int32_t precision)
{ {
CREATETAYLOR(); CREATETAYLOR();
DUPRAT(pret,*px); DUPRAT(pret,*px);
DUPRAT(thisterm,*px); DUPRAT(thisterm,*px);
DUPNUM(n2,num_one); DUPNUM(n2,num_one);
@ -84,11 +84,11 @@ void _sinrat( PRAT *px, int32_t precision)
} while ( !SMALL_ENOUGH_RAT( thisterm, precision) ); } while ( !SMALL_ENOUGH_RAT( thisterm, precision) );
DESTROYTAYLOR(); 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. // this trick here.
inbetween(px, rat_one, precision); inbetween(px, rat_one, precision);
// Since *px might be epsilon near zero we must set it to zero. // 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) ) 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(); CREATETAYLOR();
destroynum(pret->pp); destroynum(pret->pp);
destroynum(pret->pq); destroynum(pret->pq);
pret->pp=longtonum( 1L, radix); pret->pp=longtonum( 1L, radix);
pret->pq=longtonum( 1L, radix); pret->pq=longtonum( 1L, radix);
DUPRAT(thisterm,pret) DUPRAT(thisterm,pret)
n2=longtonum(0L, radix); n2=longtonum(0L, radix);
xx->pp->sign *= -1; xx->pp->sign *= -1;
@ -181,7 +181,7 @@ void _cosrat( PRAT *px, uint32_t radix, int32_t precision)
} while ( !SMALL_ENOUGH_RAT( thisterm, precision) ); } while ( !SMALL_ENOUGH_RAT( thisterm, precision) );
DESTROYTAYLOR(); 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. // this trick here.
inbetween(px, rat_one, precision); inbetween(px, rat_one, precision);
// Since *px might be epsilon near zero we must set it to zero. // Since *px might be epsilon near zero we must set it to zero.

View File

@ -80,7 +80,7 @@ void _sinhrat( PRAT *px, int32_t precision)
CREATETAYLOR(); CREATETAYLOR();
DUPRAT(pret,*px); DUPRAT(pret,*px);
DUPRAT(thisterm,pret); DUPRAT(thisterm,pret);
DUPNUM(n2,num_one); DUPNUM(n2,num_one);
@ -194,7 +194,7 @@ void coshrat( PRAT *px, uint32_t radix, int32_t precision)
{ {
_coshrat( px, radix, 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. // we need this trick here.
if ( rat_lt(*px, rat_one, precision) ) if ( rat_lt(*px, rat_one, precision) )
{ {

View File

@ -46,7 +46,7 @@ UnitConverter::UnitConverter(_In_ const shared_ptr<IConverterDataLoader>& dataLo
{ {
m_dataLoader = dataLoader; m_dataLoader = dataLoader;
m_currencyDataLoader = currencyDataLoader; m_currencyDataLoader = currencyDataLoader;
//declaring the delimiter character conversion map // declaring the delimiter character conversion map
quoteConversions[L'|'] = L"{p}"; quoteConversions[L'|'] = L"{p}";
quoteConversions[L'['] = L"{lc}"; quoteConversions[L'['] = L"{lc}";
quoteConversions[L']'] = L"{rc}"; quoteConversions[L']'] = L"{rc}";
@ -90,7 +90,7 @@ vector<Category> UnitConverter::GetCategories()
} }
/// <summary> /// <summary>
/// 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. /// and returns a list of unit types that exist under the given category.
/// </summary> /// </summary>
/// <param name="input">Category struct which we are setting</param> /// <param name="input">Category struct which we are setting</param>
@ -170,7 +170,7 @@ void UnitConverter::SetCurrentUnitTypes(const Unit& fromType, const Unit& toType
/// <summary> /// <summary>
/// Switches the active field, indicating that we are now entering data into /// Switches the active field, indicating that we are now entering data into
/// what was originally the return field, and storing results into what was /// 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. /// but do not callback, as values have not changed.
/// </summary> /// </summary>
/// <param name="newValue"> /// <param name="newValue">
@ -420,7 +420,7 @@ void UnitConverter::RestoreUserPreferences(const wstring& userPreferences)
/// <summary> /// <summary>
/// Serializes the Category and Associated Units in the converter and returns it as a string /// Serializes the Category and Associated Units in the converter and returns it as a string
/// </summary> /// </summary>
wstring UnitConverter::SaveUserPreferences() wstring UnitConverter::SaveUserPreferences()
{ {
wstringstream out(wstringstream::out); wstringstream out(wstringstream::out);
@ -441,7 +441,7 @@ wstring UnitConverter::Quote(const wstring& s)
{ {
wstringstream quotedString(wstringstream::out); 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(); wstring::const_iterator cursor = s.begin();
while(cursor != s.end()) while(cursor != s.end())
{ {
@ -479,7 +479,7 @@ wstring UnitConverter::Unquote(const wstring& s)
} }
if (cursor == s.end()) if (cursor == s.end())
{ {
//badly formatted // Badly formatted
break; break;
} }
else else
@ -505,7 +505,7 @@ void UnitConverter::SendCommand(Command command)
{ {
if (CheckLoad()) if (CheckLoad())
{ {
//TODO: Localization of characters // TODO: Localization of characters
bool clearFront = false; bool clearFront = false;
if (m_currentDisplay == L"0") if (m_currentDisplay == L"0")
{ {
@ -625,7 +625,7 @@ void UnitConverter::SendCommand(Command command)
default: default:
break; break;
} }
if (clearFront) if (clearFront)
{ {
@ -728,7 +728,7 @@ vector<tuple<wstring, Unit>> UnitConverter::CalculateSuggested()
vector<SuggestedValueIntermediate> intermediateVector; vector<SuggestedValueIntermediate> intermediateVector;
vector<SuggestedValueIntermediate> intermediateWhimsicalVector; vector<SuggestedValueIntermediate> intermediateWhimsicalVector;
unordered_map<Unit, ConversionData, UnitHash> ratios = m_ratioMap[m_fromType]; unordered_map<Unit, ConversionData, UnitHash> 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) for (const auto& cur : ratios)
{ {
if (cur.first != m_fromType && cur.first != m_toType) if (cur.first != m_fromType && cur.first != m_toType)
@ -745,21 +745,21 @@ vector<tuple<wstring, Unit>> 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(), [] sort(intermediateVector.begin(), intermediateVector.end(), []
(SuggestedValueIntermediate first, SuggestedValueIntermediate second) (SuggestedValueIntermediate first, SuggestedValueIntermediate second)
{ {
if (abs(first.magnitude) == abs(second.magnitude)) if (abs(first.magnitude) == abs(second.magnitude))
{ {
return first.magnitude > second.magnitude; return first.magnitude > second.magnitude;
} }
else else
{ {
return abs(first.magnitude) < abs(second.magnitude); 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) for (const auto& entry : intermediateVector)
{ {
wstring roundedString; wstring roundedString;
@ -783,7 +783,7 @@ vector<tuple<wstring, Unit>> UnitConverter::CalculateSuggested()
} }
// The Whimsicals are determined differently // 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(), [] sort(intermediateWhimsicalVector.begin(), intermediateWhimsicalVector.end(), []
(SuggestedValueIntermediate first, SuggestedValueIntermediate second) (SuggestedValueIntermediate first, SuggestedValueIntermediate second)
{ {
@ -797,7 +797,7 @@ vector<tuple<wstring, Unit>> 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<tuple<wstring, Unit>> whimsicalReturnVector; vector<tuple<wstring, Unit>> whimsicalReturnVector;
for (const auto& entry : intermediateWhimsicalVector) for (const auto& entry : intermediateWhimsicalVector)

View File

@ -3,9 +3,9 @@
#pragma once #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::DependencyObject,
public Windows::UI::Xaml::Data::ICollectionView public Windows::UI::Xaml::Data::ICollectionView
{ {
@ -14,11 +14,11 @@ namespace CalculatorApp { namespace Common
m_currentPosition(-1) m_currentPosition(-1)
{ {
m_source = source; m_source = source;
Windows::UI::Xaml::Interop::IBindableObservableVector^ observable = dynamic_cast<Windows::UI::Xaml::Interop::IBindableObservableVector^>(source); Windows::UI::Xaml::Interop::IBindableObservableVector^ observable = dynamic_cast<Windows::UI::Xaml::Interop::IBindableObservableVector^>(source);
if (observable) if (observable)
{ {
observable->VectorChanged += observable->VectorChanged +=
ref new Windows::UI::Xaml::Interop::BindableVectorChangedEventHandler(this, &AlwaysSelectedCollectionView::OnSourceBindableVectorChanged); ref new Windows::UI::Xaml::Interop::BindableVectorChangedEventHandler(this, &AlwaysSelectedCollectionView::OnSourceBindableVectorChanged);
} }
} }
@ -53,7 +53,7 @@ namespace CalculatorApp { namespace Common
return ref new Platform::Collections::Vector<Platform::Object^>(); return ref new Platform::Collections::Vector<Platform::Object^>();
} }
} }
property bool HasMoreItems property bool HasMoreItems
{ {
virtual bool get() = Windows::UI::Xaml::Data::ICollectionView::HasMoreItems::get 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 // 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 // restore the selection to the way we wanted it to begin with
if (m_currentPosition >= 0 && m_currentPosition < static_cast<int>(m_source->Size)) if (m_currentPosition >= 0 && m_currentPosition < static_cast<int>(m_source->Size))
{ {
@ -161,7 +161,7 @@ namespace CalculatorApp { namespace Common
m_currentChanging -= token; m_currentChanging -= token;
} }
} }
// IVector<Object^> // IVector<Object^>
// Not implemented methods // Not implemented methods
virtual void Append(Platform::Object^ /*item*/) = Windows::Foundation::Collections::IVector<Platform::Object^>::Append virtual void Append(Platform::Object^ /*item*/) = Windows::Foundation::Collections::IVector<Platform::Object^>::Append
@ -219,7 +219,7 @@ namespace CalculatorApp { namespace Common
return m_source->Size; return m_source->Size;
} }
} }
// IObservableVector<Object^> // IObservableVector<Object^>
event Windows::Foundation::Collections::VectorChangedEventHandler<Platform::Object^>^ VectorChanged event Windows::Foundation::Collections::VectorChangedEventHandler<Platform::Object^>^ VectorChanged
{ {
@ -262,9 +262,9 @@ namespace CalculatorApp { namespace Common
private: private:
virtual Platform::Object^ Convert( virtual Platform::Object^ Convert(
Platform::Object^ value, Platform::Object^ value,
Windows::UI::Xaml::Interop::TypeName /*targetType*/, Windows::UI::Xaml::Interop::TypeName /*targetType*/,
Platform::Object^ /*parameter*/, Platform::Object^ /*parameter*/,
Platform::String^ /*language*/) = Windows::UI::Xaml::Data::IValueConverter::Convert Platform::String^ /*language*/) = Windows::UI::Xaml::Data::IValueConverter::Convert
{ {
auto result = dynamic_cast<Windows::UI::Xaml::Interop::IBindableVector^>(value); auto result = dynamic_cast<Windows::UI::Xaml::Interop::IBindableVector^>(value);
@ -276,9 +276,9 @@ namespace CalculatorApp { namespace Common
} }
virtual Platform::Object^ ConvertBack( virtual Platform::Object^ ConvertBack(
Platform::Object^ /*value*/, Platform::Object^ /*value*/,
Windows::UI::Xaml::Interop::TypeName /*targetType*/, Windows::UI::Xaml::Interop::TypeName /*targetType*/,
Platform::Object^ /*parameter*/, Platform::Object^ /*parameter*/,
Platform::String^ /*language*/) = Windows::UI::Xaml::Data::IValueConverter::ConvertBack Platform::String^ /*language*/) = Windows::UI::Xaml::Data::IValueConverter::ConvertBack
{ {
return Windows::UI::Xaml::DependencyProperty::UnsetValue; return Windows::UI::Xaml::DependencyProperty::UnsetValue;

View File

@ -88,7 +88,7 @@ namespace CalculatorApp::Common::Automation
static NarratorAnnouncement^ GetCategoryNameChangedAnnouncement(Platform::String^ announcement); static NarratorAnnouncement^ GetCategoryNameChangedAnnouncement(Platform::String^ announcement);
static NarratorAnnouncement^ GetUpdateCurrencyRatesAnnouncement(Platform::String^ announcement); static NarratorAnnouncement^ GetUpdateCurrencyRatesAnnouncement(Platform::String^ announcement);
static NarratorAnnouncement^ GetDisplayCopiedAnnouncement(Platform::String^ announcement); static NarratorAnnouncement^ GetDisplayCopiedAnnouncement(Platform::String^ announcement);
static NarratorAnnouncement^ GetOpenParenthesisCountChangedAnnouncement(Platform::String^ announcement); static NarratorAnnouncement^ GetOpenParenthesisCountChangedAnnouncement(Platform::String^ announcement);

View File

@ -18,17 +18,17 @@ void BindableBase::OnPropertyChanged(String^ propertyName)
PropertyChanged(this, ref new PropertyChangedEventArgs(propertyName)); PropertyChanged(this, ref new PropertyChangedEventArgs(propertyName));
} }
Windows::UI::Xaml::Data::ICustomProperty^ BindableBase::GetCustomProperty(Platform::String^ name) Windows::UI::Xaml::Data::ICustomProperty^ BindableBase::GetCustomProperty(Platform::String^ name)
{ {
return nullptr; return nullptr;
} }
Windows::UI::Xaml::Data::ICustomProperty^ BindableBase::GetIndexedProperty(Platform::String^ name, Windows::UI::Xaml::Interop::TypeName type) Windows::UI::Xaml::Data::ICustomProperty^ BindableBase::GetIndexedProperty(Platform::String^ name, Windows::UI::Xaml::Interop::TypeName type)
{ {
return nullptr; return nullptr;
} }
Platform::String^ BindableBase::GetStringRepresentation() Platform::String^ BindableBase::GetStringRepresentation()
{ {
return this->ToString(); return this->ToString();
} }

View File

@ -80,7 +80,7 @@ namespace CalculatorApp
D = (int) CM::Command::CommandD, D = (int) CM::Command::CommandD,
E = (int) CM::Command::CommandE, E = (int) CM::Command::CommandE,
F = (int) CM::Command::CommandF, F = (int) CM::Command::CommandF,
Memory, // This is the memory button. Doesn't have a direct mapping to the CalcEngine. Memory, // This is the memory button. Doesn't have a direct mapping to the CalcEngine.
Sinh = (int) CM::Command::CommandSINH, Sinh = (int) CM::Command::CommandSINH,
Cosh = (int) CM::Command::CommandCOSH, Cosh = (int) CM::Command::CommandCOSH,
Tanh = (int) CM::Command::CommandTANH, Tanh = (int) CM::Command::CommandTANH,

View File

@ -2,7 +2,7 @@
// Licensed under the MIT License. // Licensed under the MIT License.
// This class provides the concrete implementation for the ICalcDisplay interface // This class provides the concrete implementation for the ICalcDisplay interface
// that is declared in the Calculation Manager Library. // that is declared in the Calculation Manager Library.
#include "pch.h" #include "pch.h"
#include "CalculatorDisplay.h" #include "CalculatorDisplay.h"
#include "StandardCalculatorViewModel.h" #include "StandardCalculatorViewModel.h"

View File

@ -12,7 +12,7 @@ namespace CalculatorApp
public: public:
ConversionResultTaskHelper(unsigned int delay, const std::function<void()> functionToRun); ConversionResultTaskHelper(unsigned int delay, const std::function<void()> functionToRun);
~ConversionResultTaskHelper(); ~ConversionResultTaskHelper();
private: private:
concurrency::task<void> CompleteAfter(unsigned int timeout); concurrency::task<void> CompleteAfter(unsigned int timeout);

View File

@ -135,7 +135,7 @@ String^ CopyPasteManager::ValidatePasteExpression(String^ pastedText, ViewMode m
wstring pasteExpression = pastedText->Data(); wstring pasteExpression = pastedText->Data();
// Get english translated expression // Get english translated expression
String^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(pasteExpression); String^ englishString = LocalizationSettings::GetInstance().GetEnglishValueFromLocalizedDigits(pasteExpression);
// Removing the spaces, comma separator from the pasteExpression to allow pasting of expressions like 1 + 2+1,333 // Removing the spaces, comma separator from the pasteExpression to allow pasting of expressions like 1 + 2+1,333

View File

@ -15,7 +15,7 @@ DateCalculationEngine::DateCalculationEngine(_In_ String^ calendarIdentifier)
m_calendar->ChangeCalendarSystem(calendarIdentifier); m_calendar->ChangeCalendarSystem(calendarIdentifier);
} }
// Adding Duration to a Date // Adding Duration to a Date
// Returns: True if function succeeds to calculate the date else returns False // Returns: True if function succeeds to calculate the date else returns False
bool DateCalculationEngine::AddDuration(_In_ DateTime startDate, _In_ const DateDifference& duration, _Out_ DateTime *endDate) bool DateCalculationEngine::AddDuration(_In_ DateTime startDate, _In_ const DateDifference& duration, _Out_ DateTime *endDate)
{ {
@ -52,7 +52,7 @@ bool DateCalculationEngine::AddDuration(_In_ DateTime startDate, _In_ const Date
bool DateCalculationEngine::SubtractDuration(_In_ DateTime startDate, _In_ const DateDifference& duration, _Out_ DateTime *endDate) bool DateCalculationEngine::SubtractDuration(_In_ DateTime startDate, _In_ const DateDifference& duration, _Out_ DateTime *endDate)
{ {
// For Subtract the Algorithm is different than Add. Here the smaller units are subtracted first // For Subtract the Algorithm is different than Add. Here the smaller units are subtracted first
// and then the larger units. // and then the larger units.
try try
{ {
m_calendar->SetDateTime(startDate); m_calendar->SetDateTime(startDate);

View File

@ -21,10 +21,10 @@ namespace CalculatorApp
private: private:
// Explicit, and private, implementation of ICommand, this way of programming makes it so // Explicit, and private, implementation of ICommand, this way of programming makes it so
// the ICommand methods will only be available if the ICommand interface is requested via a dynamic_cast // the ICommand methods will only be available if the ICommand interface is requested via a dynamic_cast
// The ICommand interface is meant to be consumed by Xaml and not by the app, this is a defensive measure against // The ICommand interface is meant to be consumed by Xaml and not by the app, this is a defensive measure against
// code in the app calling Execute. // code in the app calling Execute.
virtual void ExecuteImpl(Platform::Object^ parameter) sealed = Windows::UI::Xaml::Input::ICommand::Execute virtual void ExecuteImpl(Platform::Object^ parameter) sealed = Windows::UI::Xaml::Input::ICommand::Execute
{ {
TTarget^ target = m_weakTarget.Resolve<TTarget>(); TTarget^ target = m_weakTarget.Resolve<TTarget>();

View File

@ -56,7 +56,7 @@ namespace CalculatorApp
{ {
// Lights up all of the buttons in the given range // Lights up all of the buttons in the given range
// The range is defined by a pair of iterators // The range is defined by a pair of iterators
template <typename T> template <typename T>
void LightUpButtons(const T& buttons) void LightUpButtons(const T& buttons)
{ {
auto iterator = buttons.first; auto iterator = buttons.first;
@ -72,14 +72,14 @@ namespace CalculatorApp
void LightUpButton(ButtonBase^ button) void LightUpButton(ButtonBase^ button)
{ {
// If the button is a toggle button then we don't need // If the button is a toggle button then we don't need
// to change the UI of the button // to change the UI of the button
if (dynamic_cast<ToggleButton^>(button)) if (dynamic_cast<ToggleButton^>(button))
{ {
return; return;
} }
// The button will go into the visual Pressed state with this call // The button will go into the visual Pressed state with this call
VisualStateManager::GoToState(button, "Pressed", true); VisualStateManager::GoToState(button, "Pressed", true);
// This timer will fire after lightUpTime and make the button // This timer will fire after lightUpTime and make the button
@ -89,7 +89,7 @@ namespace CalculatorApp
TimeSpan lightUpTime{}; TimeSpan lightUpTime{};
lightUpTime.Duration = 500000L; // Half second (in 100-ns units) lightUpTime.Duration = 500000L; // Half second (in 100-ns units)
timer->Interval = lightUpTime; timer->Interval = lightUpTime;
WeakReference timerWeakReference(timer); WeakReference timerWeakReference(timer);
WeakReference buttonWeakReference(button); WeakReference buttonWeakReference(button);
timer->Tick += ref new EventHandler<Object^>( timer->Tick += ref new EventHandler<Object^>(
@ -206,7 +206,7 @@ void KeyboardShortcutManager::HonorEscape()
} }
void KeyboardShortcutManager::OnCharacterPropertyChanged( void KeyboardShortcutManager::OnCharacterPropertyChanged(
DependencyObject^ target, DependencyObject^ target,
String^ oldValue, String^ oldValue,
String^ newValue) String^ newValue)
{ {
@ -263,10 +263,10 @@ void KeyboardShortcutManager::OnVirtualKeyPropertyChanged(
reader_writer_lock::scoped_lock lock(s_keyboardShortcutMapLock); reader_writer_lock::scoped_lock lock(s_keyboardShortcutMapLock);
auto button = static_cast<ButtonBase^>(target); auto button = static_cast<ButtonBase^>(target);
int viewId = Utils::GetWindowId(); int viewId = Utils::GetWindowId();
auto iterViewMap = s_VirtualKeysForButtons.find(viewId); auto iterViewMap = s_VirtualKeysForButtons.find(viewId);
// Check if the View Id has already been registered // Check if the View Id has already been registered
if (iterViewMap != s_VirtualKeysForButtons.end()) if (iterViewMap != s_VirtualKeysForButtons.end())
{ {
@ -281,7 +281,7 @@ void KeyboardShortcutManager::OnVirtualKeyPropertyChanged(
} }
void KeyboardShortcutManager::OnVirtualKeyControlChordPropertyChanged( void KeyboardShortcutManager::OnVirtualKeyControlChordPropertyChanged(
DependencyObject^ target, DependencyObject^ target,
MyVirtualKey /*oldValue*/, MyVirtualKey /*oldValue*/,
MyVirtualKey newValue) MyVirtualKey newValue)
{ {
@ -537,7 +537,7 @@ void KeyboardShortcutManager::OnKeyDownHandler(CoreWindow^ sender, KeyEventArgs^
// Handle Ctrl + E for DateCalculator // Handle Ctrl + E for DateCalculator
if ((key == VirtualKey::E) && if ((key == VirtualKey::E) &&
isControlKeyPressed && isControlKeyPressed &&
!isShiftKeyPressed) !isShiftKeyPressed)
{ {
const auto& lookupMap = GetCurrentKeyDictionary(static_cast<MyVirtualKey>(key)); const auto& lookupMap = GetCurrentKeyDictionary(static_cast<MyVirtualKey>(key));
@ -710,7 +710,7 @@ void KeyboardShortcutManager::OnAcceleratorKeyActivated(CoreDispatcher^, Acceler
{ {
int viewId = Utils::GetWindowId(); int viewId = Utils::GetWindowId();
auto iterViewMap = s_AboutFlyout.find(viewId); auto iterViewMap = s_AboutFlyout.find(viewId);
if ((iterViewMap != s_AboutFlyout.end()) && (iterViewMap->second != nullptr)) if ((iterViewMap != s_AboutFlyout.end()) && (iterViewMap->second != nullptr))
{ {
iterViewMap->second->Hide(); iterViewMap->second->Hide();
@ -721,9 +721,9 @@ void KeyboardShortcutManager::OnAcceleratorKeyActivated(CoreDispatcher^, Acceler
void KeyboardShortcutManager::Initialize() void KeyboardShortcutManager::Initialize()
{ {
auto coreWindow = Window::Current->CoreWindow; auto coreWindow = Window::Current->CoreWindow;
coreWindow->CharacterReceived += coreWindow->CharacterReceived +=
ref new TypedEventHandler<CoreWindow^, CharacterReceivedEventArgs^>(&KeyboardShortcutManager::OnCharacterReceivedHandler); ref new TypedEventHandler<CoreWindow^, CharacterReceivedEventArgs^>(&KeyboardShortcutManager::OnCharacterReceivedHandler);
coreWindow->KeyDown += coreWindow->KeyDown +=
ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(&KeyboardShortcutManager::OnKeyDownHandler); ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(&KeyboardShortcutManager::OnKeyDownHandler);
coreWindow->KeyUp += coreWindow->KeyUp +=
ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(&KeyboardShortcutManager::OnKeyUpHandler); ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(&KeyboardShortcutManager::OnKeyUpHandler);
@ -758,7 +758,7 @@ void KeyboardShortcutManager::UpdateDropDownState(bool isOpen)
void KeyboardShortcutManager::UpdateDropDownState(Flyout^ aboutPageFlyout) void KeyboardShortcutManager::UpdateDropDownState(Flyout^ aboutPageFlyout)
{ {
int viewId = Utils::GetWindowId(); int viewId = Utils::GetWindowId();
if (s_AboutFlyout.find(viewId) != s_AboutFlyout.end()) if (s_AboutFlyout.find(viewId) != s_AboutFlyout.end())
{ {
s_AboutFlyout.erase(viewId); s_AboutFlyout.erase(viewId);
@ -803,7 +803,7 @@ void KeyboardShortcutManager::RegisterNewAppViewId()
{ {
s_CharacterForButtons.insert(std::make_pair(appViewId, std::multimap<wchar_t, WeakReference>())); s_CharacterForButtons.insert(std::make_pair(appViewId, std::multimap<wchar_t, WeakReference>()));
} }
if (s_VirtualKeysForButtons.find(appViewId) == s_VirtualKeysForButtons.end()) if (s_VirtualKeysForButtons.find(appViewId) == s_VirtualKeysForButtons.end())
{ {
s_VirtualKeysForButtons.insert(std::make_pair(appViewId, std::multimap<MyVirtualKey, WeakReference>())); s_VirtualKeysForButtons.insert(std::make_pair(appViewId, std::multimap<MyVirtualKey, WeakReference>()));
@ -823,17 +823,17 @@ void KeyboardShortcutManager::RegisterNewAppViewId()
{ {
s_VirtualKeyAltChordsForButtons.insert(std::make_pair(appViewId, std::multimap<MyVirtualKey, WeakReference>())); s_VirtualKeyAltChordsForButtons.insert(std::make_pair(appViewId, std::multimap<MyVirtualKey, WeakReference>()));
} }
if (s_VirtualKeyControlShiftChordsForButtons.find(appViewId) == s_VirtualKeyControlShiftChordsForButtons.end()) if (s_VirtualKeyControlShiftChordsForButtons.find(appViewId) == s_VirtualKeyControlShiftChordsForButtons.end())
{ {
s_VirtualKeyControlShiftChordsForButtons.insert(std::make_pair(appViewId, std::multimap<MyVirtualKey, WeakReference>())); s_VirtualKeyControlShiftChordsForButtons.insert(std::make_pair(appViewId, std::multimap<MyVirtualKey, WeakReference>()));
} }
if (s_VirtualKeyInverseChordsForButtons.find(appViewId) == s_VirtualKeyInverseChordsForButtons.end()) if (s_VirtualKeyInverseChordsForButtons.find(appViewId) == s_VirtualKeyInverseChordsForButtons.end())
{ {
s_VirtualKeyInverseChordsForButtons.insert(std::make_pair(appViewId, std::multimap<MyVirtualKey, WeakReference>())); s_VirtualKeyInverseChordsForButtons.insert(std::make_pair(appViewId, std::multimap<MyVirtualKey, WeakReference>()));
} }
if (s_VirtualKeyControlInverseChordsForButtons.find(appViewId) == s_VirtualKeyControlInverseChordsForButtons.end()) if (s_VirtualKeyControlInverseChordsForButtons.find(appViewId) == s_VirtualKeyControlInverseChordsForButtons.end())
{ {
s_VirtualKeyControlInverseChordsForButtons.insert(std::make_pair(appViewId, std::multimap<MyVirtualKey, WeakReference>())); s_VirtualKeyControlInverseChordsForButtons.insert(std::make_pair(appViewId, std::multimap<MyVirtualKey, WeakReference>()));

View File

@ -206,7 +206,7 @@ FontWeight LocalizationService::GetFontWeightOverride()
double LocalizationService::GetFontScaleFactorOverride(LanguageFontType fontType) double LocalizationService::GetFontScaleFactorOverride(LanguageFontType fontType)
{ {
assert(m_overrideFontApiValues); assert(m_overrideFontApiValues);
switch (fontType) switch (fontType)
{ {
case LanguageFontType::UIText: case LanguageFontType::UIText:
@ -271,12 +271,12 @@ void LocalizationService::UpdateFontFamilyAndSize(DependencyObject^ target)
{ {
control->FontSize = sizeToUse; control->FontSize = sizeToUse;
} }
else else
{ {
control->ClearValue(Control::FontSizeProperty); control->ClearValue(Control::FontSizeProperty);
} }
} }
else else
{ {
auto textBlock = dynamic_cast<TextBlock^>(target); auto textBlock = dynamic_cast<TextBlock^>(target);
if (textBlock) if (textBlock)
@ -290,7 +290,7 @@ void LocalizationService::UpdateFontFamilyAndSize(DependencyObject^ target)
{ {
textBlock->FontSize = sizeToUse; textBlock->FontSize = sizeToUse;
} }
else else
{ {
textBlock->ClearValue(TextBlock::FontSizeProperty); textBlock->ClearValue(TextBlock::FontSizeProperty);
} }
@ -309,7 +309,7 @@ void LocalizationService::UpdateFontFamilyAndSize(DependencyObject^ target)
{ {
richTextBlock->FontSize = sizeToUse; richTextBlock->FontSize = sizeToUse;
} }
else else
{ {
richTextBlock->ClearValue(RichTextBlock::FontSizeProperty); richTextBlock->ClearValue(RichTextBlock::FontSizeProperty);
} }
@ -328,7 +328,7 @@ void LocalizationService::UpdateFontFamilyAndSize(DependencyObject^ target)
{ {
textElement->FontSize = sizeToUse; textElement->FontSize = sizeToUse;
} }
else else
{ {
textElement->ClearValue(TextElement::FontSizeProperty); textElement->ClearValue(TextElement::FontSizeProperty);
} }
@ -416,7 +416,7 @@ IIterable<String^>^ LocalizationService::GetLanguageIdentifiers()
int result = GetUserDefaultLocaleName(currentLocale, LOCALE_NAME_MAX_LENGTH); int result = GetUserDefaultLocaleName(currentLocale, LOCALE_NAME_MAX_LENGTH);
if (result != 0) if (result != 0)
{ {
// GetUserDefaultLocaleName may return an invalid bcp47 language tag with trailing non-BCP47 friendly characters, // GetUserDefaultLocaleName may return an invalid bcp47 language tag with trailing non-BCP47 friendly characters,
// which if present would start with an underscore, for example sort order // which if present would start with an underscore, for example sort order
// (see https://msdn.microsoft.com/en-us/library/windows/desktop/dd373814(v=vs.85).aspx). // (see https://msdn.microsoft.com/en-us/library/windows/desktop/dd373814(v=vs.85).aspx).
// Therefore, if there is an underscore in the locale name, trim all characters from the underscore onwards. // Therefore, if there is an underscore in the locale name, trim all characters from the underscore onwards.

View File

@ -20,11 +20,11 @@ namespace CalculatorApp
va_list args = NULL; va_list args = NULL;
va_start(args, pMessage); va_start(args, pMessage);
DWORD fmtReturnVal = FormatMessage(FORMAT_MESSAGE_FROM_STRING, DWORD fmtReturnVal = FormatMessage(FORMAT_MESSAGE_FROM_STRING,
pMessage, pMessage,
0, 0,
0, 0,
spBuffer.get(), spBuffer.get(),
length, length,
&args); &args);
va_end(args); va_end(args);

View File

@ -141,7 +141,7 @@ namespace CalculatorApp
property Platform::String^ AccessKey property Platform::String^ AccessKey
{ {
Platform::String^ get() Platform::String^ get()
{ {
return m_accessKey; return m_accessKey;
} }
@ -220,11 +220,11 @@ namespace CalculatorApp
static Windows::Foundation::Collections::IObservableVector<NavCategoryGroup^>^ CreateMenuOptions(); static Windows::Foundation::Collections::IObservableVector<NavCategoryGroup^>^ CreateMenuOptions();
static Platform::String^ GetHeaderResourceKey(CategoryGroupType type); static Platform::String^ GetHeaderResourceKey(CategoryGroupType type);
internal: internal:
static NavCategoryGroup^ CreateCalculatorCategory(); static NavCategoryGroup^ CreateCalculatorCategory();
static NavCategoryGroup^ CreateConverterCategory(); static NavCategoryGroup^ CreateConverterCategory();
private: private:
NavCategoryGroup(const NavCategoryGroupInitializer& groupInitializer); NavCategoryGroup(const NavCategoryGroupInitializer& groupInitializer);

View File

@ -103,7 +103,7 @@ namespace CalculatorApp
g_calculatorProvider( g_calculatorProvider(
L"MicrosoftCalculator", L"MicrosoftCalculator",
LoggingChannelOptions(GUID{ 0x4f50731a, 0x89cf, 0x4782, 0xb3, 0xe0, 0xdc, 0xe8, 0xc9, 0x4, 0x76, 0xba }), // Microsoft Telemetry group LoggingChannelOptions(GUID{ 0x4f50731a, 0x89cf, 0x4782, 0xb3, 0xe0, 0xdc, 0xe8, 0xc9, 0x4, 0x76, 0xba }), // Microsoft Telemetry group
GUID{ 0x905ca09, 0x610e, 0x401e, 0xb6, 0x50, 0x2f, 0x21, 0x29, 0x80, 0xb9, 0xe0 }), //Unique providerID {0905CA09-610E-401E-B650-2F212980B9E0} GUID{ 0x905ca09, 0x610e, 0x401e, 0xb6, 0x50, 0x2f, 0x21, 0x29, 0x80, 0xb9, 0xe0 }), // Unique providerID {0905CA09-610E-401E-B650-2F212980B9E0}
m_appLaunchActivity{ nullptr } m_appLaunchActivity{ nullptr }
{ {
// initialize the function array // initialize the function array
@ -248,7 +248,7 @@ namespace CalculatorApp
{ {
windowIdLog.insert(pair<int, bool>(windowId, false)); windowIdLog.insert(pair<int, bool>(windowId, false));
} }
// if the event is not logged already for the present mode // if the event is not logged already for the present mode
if (currentMode != mode) if (currentMode != mode)
{ {
currentMode = mode; currentMode = mode;
@ -271,7 +271,7 @@ namespace CalculatorApp
{ {
windowIdLog.insert(pair<int, bool>(windowId, false)); windowIdLog.insert(pair<int, bool>(windowId, false));
} }
// if the event is not logged already for the present mode // if the event is not logged already for the present mode
if (currentMode != mode) if (currentMode != mode)
{ {
currentMode = mode; currentMode = mode;
@ -293,7 +293,7 @@ namespace CalculatorApp
{ {
windowIdLog.insert(pair<int, bool>(windowId, false)); windowIdLog.insert(pair<int, bool>(windowId, false));
} }
// if the event is not logged already for the present mode // if the event is not logged already for the present mode
if (currentMode != mode) if (currentMode != mode)
{ {
currentMode = mode; currentMode = mode;
@ -482,9 +482,9 @@ namespace CalculatorApp
LogTelemetryEvent(EVENT_NAME_MEMORY_BODY_OPENED, fields); LogTelemetryEvent(EVENT_NAME_MEMORY_BODY_OPENED, fields);
} }
//If calculator is launched in any mode other than standard then this call will come which is not intended. But there is no way to avoid it. // If calculator is launched in any mode other than standard then this call will come which is not intended. But there is no way to avoid it.
//So don't use this function to analyze the count of mode change in session instead use CalculatorViewedInSession and ConverterViewedInSession to do that. // So don't use this function to analyze the count of mode change in session instead use CalculatorViewedInSession and ConverterViewedInSession to do that.
//Use of this function is to analyze perf of mode change. // Use of this function is to analyze perf of mode change.
void TraceLogger::LogModeChangeBegin(ViewMode fromMode, ViewMode toMode, int windowId) void TraceLogger::LogModeChangeBegin(ViewMode fromMode, ViewMode toMode, int windowId)
{ {
if (!GetTraceLoggingProviderEnabled()) return; if (!GetTraceLoggingProviderEnabled()) return;
@ -499,7 +499,7 @@ namespace CalculatorApp
} }
} }
//comment: same as LogModeChangeBegin // comment: same as LogModeChangeBegin
void TraceLogger::LogModeChangeEnd(ViewMode toMode, int windowId) const void TraceLogger::LogModeChangeEnd(ViewMode toMode, int windowId) const
{ {
if (!GetTraceLoggingProviderEnabled()) return; if (!GetTraceLoggingProviderEnabled()) return;
@ -578,7 +578,7 @@ namespace CalculatorApp
// Writer lock for the static resources // Writer lock for the static resources
reader_writer_lock::scoped_lock lock(s_traceLoggerLock); reader_writer_lock::scoped_lock lock(s_traceLoggerLock);
auto iterMap = s_memoryMap.find(windowId); auto iterMap = s_memoryMap.find(windowId);
LoggingFields fields{}; LoggingFields fields{};
LogTelemetryEvent(EVENT_NAME_MEMORY_CLEAR_ALL, fields); LogTelemetryEvent(EVENT_NAME_MEMORY_CLEAR_ALL, fields);

View File

@ -9,8 +9,8 @@
static const int maxFunctionSize = (int)CalculationManager::Command::CommandBINEDITEND; static const int maxFunctionSize = (int)CalculationManager::Command::CommandBINEDITEND;
// A trace logging provider can only be instantiated and registered once per module. // A trace logging provider can only be instantiated and registered once per module.
// This class implements a singleton model ensure that only one instance is created. // This class implements a singleton model ensure that only one instance is created.
namespace CalculatorApp namespace CalculatorApp
{ {
struct FuncLog struct FuncLog
@ -105,7 +105,7 @@ namespace CalculatorApp
// Any new Log method should // Any new Log method should
// a) decide the level of logging. This will help us in limiting recording of events only up to a certain level. See this link for guidance https://msdn.microsoft.com/en-us/library/windows/desktop/aa363742(v=vs.85).aspx // a) decide the level of logging. This will help us in limiting recording of events only up to a certain level. See this link for guidance https://msdn.microsoft.com/en-us/library/windows/desktop/aa363742(v=vs.85).aspx
// We're using Verbose level for events that are called frequently and needed only for debugging or capturing perf for specific scenarios // We're using Verbose level for events that are called frequently and needed only for debugging or capturing perf for specific scenarios
// b) should decide whether or not to log to telemetry and pass TraceLoggingKeyword(MICROSOFT_KEYWORD_TELEMETRY) accordingly // b) should decide whether or not to log to telemetry and pass TraceLoggingKeyword(MICROSOFT_KEYWORD_TELEMETRY) accordingly
// c) Should accept a variable number of additional data arguments if needed // c) Should accept a variable number of additional data arguments if needed
void LogTelemetryEvent(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const; void LogTelemetryEvent(std::wstring_view eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields fields) const;

View File

@ -54,7 +54,7 @@ double Utils::GetDoubleFromWstring(wstring input)
return ::atof(inputString.c_str()); return ::atof(inputString.c_str());
} }
//returns windowId for the current view // Returns windowId for the current view
int Utils::GetWindowId() int Utils::GetWindowId()
{ {
int windowId = -1; int windowId = -1;
@ -80,20 +80,20 @@ void Utils::RunOnUIThreadNonblocking(std::function<void()>&& function, _In_ Core
} }
} }
// returns if the last character of a wstring is the target wchar_t // Returns if the last character of a wstring is the target wchar_t
bool Utils::IsLastCharacterTarget(_In_ wstring const &input, _In_ wchar_t target) bool Utils::IsLastCharacterTarget(_In_ wstring const &input, _In_ wchar_t target)
{ {
return !input.empty() && input.back() == target; return !input.empty() && input.back() == target;
} }
//return wstring after removing characters like space, comma, and double quotes // Returns wstring after removing characters like space, comma, and double quotes
wstring Utils::RemoveUnwantedCharsFromWstring(wstring input) wstring Utils::RemoveUnwantedCharsFromWstring(wstring input)
{ {
wchar_t unWantedChars[] = { L' ', L',', L'"', 8234, 8235, 8236, 8237 }; wchar_t unWantedChars[] = { L' ', L',', L'"', 8234, 8235, 8236, 8237 };
return RemoveUnwantedCharsFromWstring(input, unWantedChars, 6); return RemoveUnwantedCharsFromWstring(input, unWantedChars, 6);
} }
//return wstring after removing characters specified by unwantedChars array // Returns wstring after removing characters specified by unwantedChars array
wstring Utils::RemoveUnwantedCharsFromWstring(wstring input, wchar_t* unwantedChars, unsigned int size) wstring Utils::RemoveUnwantedCharsFromWstring(wstring input, wchar_t* unwantedChars, unsigned int size)
{ {
for (unsigned int i = 0; i < size; ++i) for (unsigned int i = 0; i < size; ++i)
@ -110,7 +110,7 @@ void Utils::SerializeCommandsAndTokens(_In_ shared_ptr<CalculatorVector <pair<ws
unsigned int commandsSize; unsigned int commandsSize;
IFTPlatformException(commands->GetSize(&commandsSize)); IFTPlatformException(commands->GetSize(&commandsSize));
// save the size of the commands vector // Save the size of the commands vector
writer->WriteUInt32(commandsSize); writer->WriteUInt32(commandsSize);
SerializeCommandVisitor cmdVisitor(writer); SerializeCommandVisitor cmdVisitor(writer);

View File

@ -54,11 +54,11 @@
#ifndef UNIT_TESTS #ifndef UNIT_TESTS
#define OBSERVABLE_OBJECT() virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged;\ #define OBSERVABLE_OBJECT() virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged;\
internal: void RaisePropertyChanged(Platform::String^ p) {\ internal: void RaisePropertyChanged(Platform::String^ p) {\
PropertyChanged(this, ref new Windows::UI::Xaml::Data::PropertyChangedEventArgs(p)); } public: PropertyChanged(this, ref new Windows::UI::Xaml::Data::PropertyChangedEventArgs(p)); } public:
#else #else
#define OBSERVABLE_OBJECT() virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged;\ #define OBSERVABLE_OBJECT() virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged;\
internal: void RaisePropertyChanged(Platform::String^ p) {\ internal: void RaisePropertyChanged(Platform::String^ p) {\
} public: } public:
#endif #endif
// The callback specified in the macro is a method in the class that will be called every time the object changes // The callback specified in the macro is a method in the class that will be called every time the object changes
@ -68,21 +68,21 @@
internal: void RaisePropertyChanged(Platform::String^ p) {\ internal: void RaisePropertyChanged(Platform::String^ p) {\
PropertyChanged(this, ref new Windows::UI::Xaml::Data::PropertyChangedEventArgs(p));\ PropertyChanged(this, ref new Windows::UI::Xaml::Data::PropertyChangedEventArgs(p));\
c(p);\ c(p);\
} public: } public:
#else #else
#define OBSERVABLE_OBJECT_CALLBACK(c) virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged;\ #define OBSERVABLE_OBJECT_CALLBACK(c) virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged;\
internal: void RaisePropertyChanged(Platform::String^ p) {\ internal: void RaisePropertyChanged(Platform::String^ p) {\
c(p);\ c(p);\
} public: } public:
#endif #endif
// The variable member generated by this macro should not be used in the class code, use the // The variable member generated by this macro should not be used in the class code, use the
// property getter instead. // property getter instead.
#define COMMAND_FOR_METHOD(p, m) property Windows::UI::Xaml::Input::ICommand^ p {\ #define COMMAND_FOR_METHOD(p, m) property Windows::UI::Xaml::Input::ICommand^ p {\
Windows::UI::Xaml::Input::ICommand^ get() {\ Windows::UI::Xaml::Input::ICommand^ get() {\
if (!donotuse_##p) {\ if (!donotuse_##p) {\
donotuse_##p = CalculatorApp::Common::MakeDelegate(this, &m);\ donotuse_##p = CalculatorApp::Common::MakeDelegate(this, &m);\
} return donotuse_##p; }} private: Windows::UI::Xaml::Input::ICommand^ donotuse_##p; public: } return donotuse_##p; }} private: Windows::UI::Xaml::Input::ICommand^ donotuse_##p; public:
#define DEPENDENCY_PROPERTY_DECLARATION(t, n)\ #define DEPENDENCY_PROPERTY_DECLARATION(t, n)\
property t n {\ property t n {\
@ -141,7 +141,7 @@ namespace Utils
const wchar_t PDF = 0x202c; // Pop Directional Formatting const wchar_t PDF = 0x202c; // Pop Directional Formatting
const wchar_t LRO = 0x202d; // Left-to-Right Override const wchar_t LRO = 0x202d; // Left-to-Right Override
// Regular DependencyProperty // Regular DependencyProperty
template <typename TOwner, typename TType> template <typename TOwner, typename TType>
Windows::UI::Xaml::DependencyProperty^ RegisterDependencyProperty( Windows::UI::Xaml::DependencyProperty^ RegisterDependencyProperty(
_In_ const wchar_t* const name, _In_ const wchar_t* const name,
@ -205,7 +205,7 @@ namespace Utils
ref new Windows::UI::Xaml::PropertyChangedCallback(callback))); ref new Windows::UI::Xaml::PropertyChangedCallback(callback)));
} }
// Attached DependencyProperty // Attached DependencyProperty
template <typename TOwner, typename TType> template <typename TOwner, typename TType>
Windows::UI::Xaml::DependencyProperty^ RegisterDependencyPropertyAttached( Windows::UI::Xaml::DependencyProperty^ RegisterDependencyPropertyAttached(
_In_ const wchar_t* const name, _In_ const wchar_t* const name,

View File

@ -14,9 +14,9 @@ namespace CalculatorApp { namespace Common
private: private:
virtual Platform::Object^ Convert( virtual Platform::Object^ Convert(
Platform::Object^ value, Platform::Object^ value,
Windows::UI::Xaml::Interop::TypeName /*targetType*/, Windows::UI::Xaml::Interop::TypeName /*targetType*/,
Platform::Object^ /*parameter*/, Platform::Object^ /*parameter*/,
Platform::String^ /*language*/) = Windows::UI::Xaml::Data::IValueConverter::Convert Platform::String^ /*language*/) = Windows::UI::Xaml::Data::IValueConverter::Convert
{ {
// Pass through as we don't want to change the value from the source // Pass through as we don't want to change the value from the source
@ -24,9 +24,9 @@ namespace CalculatorApp { namespace Common
} }
virtual Platform::Object^ ConvertBack( virtual Platform::Object^ ConvertBack(
Platform::Object^ value, Platform::Object^ value,
Windows::UI::Xaml::Interop::TypeName /*targetType*/, Windows::UI::Xaml::Interop::TypeName /*targetType*/,
Platform::Object^ /*parameter*/, Platform::Object^ /*parameter*/,
Platform::String^ /*language*/) = Windows::UI::Xaml::Data::IValueConverter::ConvertBack Platform::String^ /*language*/) = Windows::UI::Xaml::Data::IValueConverter::ConvertBack
{ {
if (value) if (value)
@ -47,9 +47,9 @@ namespace CalculatorApp { namespace Common
private: private:
virtual Platform::Object^ Convert( virtual Platform::Object^ Convert(
Platform::Object^ value, Platform::Object^ value,
Windows::UI::Xaml::Interop::TypeName /*targetType*/, Windows::UI::Xaml::Interop::TypeName /*targetType*/,
Platform::Object^ /*parameter*/, Platform::Object^ /*parameter*/,
Platform::String^ /*language*/) = Windows::UI::Xaml::Data::IValueConverter::Convert Platform::String^ /*language*/) = Windows::UI::Xaml::Data::IValueConverter::Convert
{ {
// Pass through as we don't want to change the value from the source // Pass through as we don't want to change the value from the source
@ -57,9 +57,9 @@ namespace CalculatorApp { namespace Common
} }
virtual Platform::Object^ ConvertBack( virtual Platform::Object^ ConvertBack(
Platform::Object^ value, Platform::Object^ value,
Windows::UI::Xaml::Interop::TypeName /*targetType*/, Windows::UI::Xaml::Interop::TypeName /*targetType*/,
Platform::Object^ /*parameter*/, Platform::Object^ /*parameter*/,
Platform::String^ /*language*/) = Windows::UI::Xaml::Data::IValueConverter::ConvertBack Platform::String^ /*language*/) = Windows::UI::Xaml::Data::IValueConverter::ConvertBack
{ {
// The value to be valid has to be a boxed int32 value // The value to be valid has to be a boxed int32 value

View File

@ -203,7 +203,7 @@ void CurrencyDataLoader::LoadData()
} }
} }
co_return didLoad; co_return didLoad;
}).then([this](bool didLoad) }).then([this](bool didLoad)
{ {
UpdateDisplayedTimestamp(); UpdateDisplayedTimestamp();
@ -329,7 +329,7 @@ task<bool> CurrencyDataLoader::TryLoadDataFromCacheAsync()
{ {
loadComplete = co_await TryLoadDataFromWebAsync(); loadComplete = co_await TryLoadDataFromWebAsync();
} }
if (!loadComplete) if (!loadComplete)
{ {
loadComplete = co_await TryFinishLoadFromCacheAsync(); loadComplete = co_await TryFinishLoadFromCacheAsync();

View File

@ -87,7 +87,7 @@ namespace CalculatorApp
bool TryParseWebResponses( bool TryParseWebResponses(
_In_ Platform::String^ staticDataJson, _In_ Platform::String^ staticDataJson,
_In_ Platform::String^ allRatiosJson, _In_ Platform::String^ allRatiosJson,
_Inout_ std::vector<UCM::CurrencyStaticData>& staticData, _Inout_ std::vector<UCM::CurrencyStaticData>& staticData,
_Inout_ CurrencyRatioMap& allRatiosData); _Inout_ CurrencyRatioMap& allRatiosData);
bool TryParseStaticData(_In_ Platform::String^ rawJson, _Inout_ std::vector<UCM::CurrencyStaticData>& staticData); bool TryParseStaticData(_In_ Platform::String^ rawJson, _Inout_ std::vector<UCM::CurrencyStaticData>& staticData);

View File

@ -200,7 +200,7 @@ void UnitConverterDataLoader::GetUnits(_In_ unordered_map<ViewMode, vector<Order
dataUnits.push_back(OrderedUnit{ UnitConverterUnits::Data_Exbibits, GetLocalizedStringName(L"UnitName_Exbibits"), GetLocalizedStringName(L"UnitAbbreviation_Exbibits"), 24 }); dataUnits.push_back(OrderedUnit{ UnitConverterUnits::Data_Exbibits, GetLocalizedStringName(L"UnitName_Exbibits"), GetLocalizedStringName(L"UnitAbbreviation_Exbibits"), 24 });
dataUnits.push_back(OrderedUnit{ UnitConverterUnits::Data_Exbibytes, GetLocalizedStringName(L"UnitName_Exbibytes"), GetLocalizedStringName(L"UnitAbbreviation_Exbibytes"), 26 }); dataUnits.push_back(OrderedUnit{ UnitConverterUnits::Data_Exbibytes, GetLocalizedStringName(L"UnitName_Exbibytes"), GetLocalizedStringName(L"UnitAbbreviation_Exbibytes"), 26 });
dataUnits.push_back(OrderedUnit{ UnitConverterUnits::Data_Gibibits, GetLocalizedStringName(L"UnitName_Gibibits"), GetLocalizedStringName(L"UnitAbbreviation_Gibibits"), 12 }); dataUnits.push_back(OrderedUnit{ UnitConverterUnits::Data_Gibibits, GetLocalizedStringName(L"UnitName_Gibibits"), GetLocalizedStringName(L"UnitAbbreviation_Gibibits"), 12 });
dataUnits.push_back(OrderedUnit{ UnitConverterUnits::Data_Gibibytes, GetLocalizedStringName(L"UnitName_Gibibytes"), GetLocalizedStringName(L"UnitAbbreviation_Gibibytes"), 14 }); dataUnits.push_back(OrderedUnit{ UnitConverterUnits::Data_Gibibytes, GetLocalizedStringName(L"UnitName_Gibibytes"), GetLocalizedStringName(L"UnitAbbreviation_Gibibytes"), 14 });
dataUnits.push_back(OrderedUnit{ UnitConverterUnits::Data_Gigabit, GetLocalizedStringName(L"UnitName_Gigabit"), GetLocalizedStringName(L"UnitAbbreviation_Gigabit"), 11 }); dataUnits.push_back(OrderedUnit{ UnitConverterUnits::Data_Gigabit, GetLocalizedStringName(L"UnitName_Gigabit"), GetLocalizedStringName(L"UnitAbbreviation_Gigabit"), 11 });
dataUnits.push_back(OrderedUnit{ UnitConverterUnits::Data_Gigabyte, GetLocalizedStringName(L"UnitName_Gigabyte"), GetLocalizedStringName(L"UnitAbbreviation_Gigabyte"),13, true, false, false}); dataUnits.push_back(OrderedUnit{ UnitConverterUnits::Data_Gigabyte, GetLocalizedStringName(L"UnitName_Gigabyte"), GetLocalizedStringName(L"UnitAbbreviation_Gigabyte"),13, true, false, false});
dataUnits.push_back(OrderedUnit{ UnitConverterUnits::Data_Kibibits, GetLocalizedStringName(L"UnitName_Kibibits"), GetLocalizedStringName(L"UnitAbbreviation_Kibibits"), 4 }); dataUnits.push_back(OrderedUnit{ UnitConverterUnits::Data_Kibibits, GetLocalizedStringName(L"UnitName_Kibibits"), GetLocalizedStringName(L"UnitAbbreviation_Kibibits"), 4 });

View File

@ -180,8 +180,8 @@ void DateCalculatorViewModel::UpdateDisplayResult()
StrDateDiffResultInDays = L""; StrDateDiffResultInDays = L"";
StrDateDiffResult = AppResourceProvider::GetInstance().GetResourceString(L"Date_SameDates"); StrDateDiffResult = AppResourceProvider::GetInstance().GetResourceString(L"Date_SameDates");
} }
else if ((m_dateDiffResult.year == 0) && else if ((m_dateDiffResult.year == 0) &&
(m_dateDiffResult.month == 0) && (m_dateDiffResult.month == 0) &&
(m_dateDiffResult.week == 0)) (m_dateDiffResult.week == 0))
{ {
IsDiffInDays = true; IsDiffInDays = true;

View File

@ -17,18 +17,18 @@ namespace CalculatorApp
internal: internal:
HistoryItemViewModel(Platform::String^ expression, HistoryItemViewModel(Platform::String^ expression,
Platform::String^ result, Platform::String^ result,
_In_ std::shared_ptr<CalculatorVector <std::pair<std::wstring, int>>> const &spTokens, _In_ std::shared_ptr<CalculatorVector <std::pair<std::wstring, int>>> const &spTokens,
_In_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const &spCommands); _In_ std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const &spCommands);
std::shared_ptr<CalculatorVector <std::pair<std::wstring, int>>> const& GetTokens() std::shared_ptr<CalculatorVector <std::pair<std::wstring, int>>> const& GetTokens()
{ {
return m_spTokens; return m_spTokens;
} }
std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& GetCommands() std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> const& GetCommands()
{ {
return m_spCommands; return m_spCommands;
} }
public: public:

View File

@ -64,7 +64,7 @@ void HistoryViewModel::ReloadHistory(_In_ ViewMode currentMode)
if (historyListModel.size() > 0) if (historyListModel.size() > 0)
{ {
for (auto ritr = historyListModel.rbegin(); ritr != historyListModel.rend(); ++ritr) for (auto ritr = historyListModel.rbegin(); ritr != historyListModel.rend(); ++ritr)
{ {
wstring expression = (*ritr)->historyItemVector.expression; wstring expression = (*ritr)->historyItemVector.expression;
wstring result = (*ritr)->historyItemVector.result; wstring result = (*ritr)->historyItemVector.result;
localizer.LocalizeDisplayValue(&expression); localizer.LocalizeDisplayValue(&expression);

View File

@ -43,7 +43,7 @@ namespace CalculatorApp::ViewModel
StringReference BinaryDisplayValue(L"BinaryDisplayValue"); StringReference BinaryDisplayValue(L"BinaryDisplayValue");
StringReference OpenParenthesisCount(L"OpenParenthesisCount"); StringReference OpenParenthesisCount(L"OpenParenthesisCount");
} }
namespace CalculatorResourceKeys namespace CalculatorResourceKeys
{ {
StringReference CalculatorExpression(L"Format_CalculatorExpression"); StringReference CalculatorExpression(L"Format_CalculatorExpression");
@ -516,7 +516,7 @@ void StandardCalculatorViewModel::HandleUpdatedOperandData(Command cmdenum)
if (IsOperandTextCompletelySelected) if (IsOperandTextCompletelySelected)
{ {
//Clear older text; // Clear older text;
m_selectedExpressionLastData = L""; m_selectedExpressionLastData = L"";
if (ch == L'x') if (ch == L'x')
{ {
@ -606,7 +606,7 @@ void StandardCalculatorViewModel::OnButtonPressed(Object^ parameter)
if (IsInError) if (IsInError)
{ {
m_standardCalculatorManager.SendCommand(Command::CommandCLEAR); m_standardCalculatorManager.SendCommand(Command::CommandCLEAR);
if (!IsRecoverableCommand((int)numOpEnum)) if (!IsRecoverableCommand((int)numOpEnum))
{ {
return; return;
@ -869,8 +869,8 @@ void StandardCalculatorViewModel::OnPaste(String^ pastedString, ViewMode mode)
Command cmdenum = ConvertToOperatorsEnum(mappedNumOp); Command cmdenum = ConvertToOperatorsEnum(mappedNumOp);
m_standardCalculatorManager.SendCommand(cmdenum); m_standardCalculatorManager.SendCommand(cmdenum);
// The CalcEngine state machine won't allow the negate command to be sent before any // The CalcEngine state machine won't allow the negate command to be sent before any
// other digits, so instead a flag is set and the command is sent after the first appropriate // other digits, so instead a flag is set and the command is sent after the first appropriate
// command. // command.
if (sendNegate) if (sendNegate)
{ {
@ -1196,10 +1196,10 @@ Array<unsigned char>^ StandardCalculatorViewModel::Serialize()
writer->WriteInt32(data); writer->WriteInt32(data);
} }
//For ProgrammerMode // For ProgrammerMode
writer->WriteUInt32(static_cast<UINT32>(CurrentRadixType)); writer->WriteUInt32(static_cast<UINT32>(CurrentRadixType));
//Serialize commands of calculator manager // Serialize commands of calculator manager
vector<unsigned char> serializedCommand = m_standardCalculatorManager.SerializeCommands(); vector<unsigned char> serializedCommand = m_standardCalculatorManager.SerializeCommands();
writer->WriteUInt32(static_cast<UINT32>(serializedCommand.size())); writer->WriteUInt32(static_cast<UINT32>(serializedCommand.size()));
writer->WriteBytes(ref new Array<unsigned char>(serializedCommand.data(), static_cast<unsigned int>(serializedCommand.size()))); writer->WriteBytes(ref new Array<unsigned char>(serializedCommand.data(), static_cast<unsigned int>(serializedCommand.size())));
@ -1209,7 +1209,7 @@ Array<unsigned char>^ StandardCalculatorViewModel::Serialize()
Utils::SerializeCommandsAndTokens(m_tokens, m_commands, writer); Utils::SerializeCommandsAndTokens(m_tokens, m_commands, writer);
} }
//Convert viewmodel data in writer to bytes // Convert viewmodel data in writer to bytes
IBuffer^ buffer = writer->DetachBuffer(); IBuffer^ buffer = writer->DetachBuffer();
DataReader^ reader = DataReader::FromBuffer(buffer); DataReader^ reader = DataReader::FromBuffer(buffer);
Platform::Array<unsigned char>^ viewModelDataAsBytes = ref new Array<unsigned char>(buffer->Length); Platform::Array<unsigned char>^ viewModelDataAsBytes = ref new Array<unsigned char>(buffer->Length);
@ -1257,7 +1257,7 @@ void StandardCalculatorViewModel::Deserialize(Array<unsigned char>^ state)
m_standardCalculatorManager.DeSerializePrimaryDisplay(serializedPrimaryDisplay); m_standardCalculatorManager.DeSerializePrimaryDisplay(serializedPrimaryDisplay);
CurrentRadixType = reader->ReadUInt32(); CurrentRadixType = reader->ReadUInt32();
//Read command data and Deserialize // Read command data and Deserialize
UINT32 modeldatalength = reader->ReadUInt32(); UINT32 modeldatalength = reader->ReadUInt32();
Array<unsigned char>^ modelDataAsBytes = ref new Array<unsigned char>(modeldatalength); Array<unsigned char>^ modelDataAsBytes = ref new Array<unsigned char>(modeldatalength);
reader->ReadBytes(modelDataAsBytes); reader->ReadBytes(modelDataAsBytes);
@ -1604,7 +1604,7 @@ void StandardCalculatorViewModel::Recalculate(bool fromHistory)
m_standardCalculatorManager.SendCommand(static_cast<CalculationManager::Command>(currentCommands[i])); m_standardCalculatorManager.SendCommand(static_cast<CalculationManager::Command>(currentCommands[i]));
} }
if (fromHistory) // This is for the cases where the expression is loaded from history if (fromHistory) // This is for the cases where the expression is loaded from history
{ {
// To maintain F-E state of the engine, as the last operand hasn't reached engine by now // To maintain F-E state of the engine, as the last operand hasn't reached engine by now
m_standardCalculatorManager.SendCommand(Command::CommandFE); m_standardCalculatorManager.SendCommand(Command::CommandFE);
@ -1981,7 +1981,7 @@ void StandardCalculatorViewModel::UpdatecommandsInRecordingMode()
} }
else else
{ {
//reset all vars // Reset all vars
isDecimal = false; isDecimal = false;
isNegative = false; isNegative = false;
isExpMode = false; isExpMode = false;

View File

@ -277,7 +277,7 @@ namespace CalculatorApp
NumbersAndOperatorsEnum MapCharacterToButtonId(const wchar_t ch, bool& canSendNegate); NumbersAndOperatorsEnum MapCharacterToButtonId(const wchar_t ch, bool& canSendNegate);
//Memory feature related methods. They are internal because they need to called from the MainPage code-behind // Memory feature related methods. They are internal because they need to called from the MainPage code-behind
void OnMemoryButtonPressed(); void OnMemoryButtonPressed();
void OnMemoryItemPressed(Platform::Object^ memoryItemPosition); void OnMemoryItemPressed(Platform::Object^ memoryItemPosition);
void OnMemoryAdd(Platform::Object^ memoryItemPosition); void OnMemoryAdd(Platform::Object^ memoryItemPosition);

View File

@ -142,7 +142,7 @@ UnitConverterViewModel::UnitConverterViewModel(const shared_ptr<UCM::IUnitConver
m_currencyFormatter->Mode = CurrencyFormatterMode::UseCurrencyCode; m_currencyFormatter->Mode = CurrencyFormatterMode::UseCurrencyCode;
m_currencyFormatter->ApplyRoundingForCurrency(RoundingAlgorithm::RoundHalfDown); m_currencyFormatter->ApplyRoundingForCurrency(RoundingAlgorithm::RoundHalfDown);
m_currencyMaxFractionDigits = m_currencyFormatter->FractionDigits; m_currencyMaxFractionDigits = m_currencyFormatter->FractionDigits;
auto resourceLoader = AppResourceProvider::GetInstance(); auto resourceLoader = AppResourceProvider::GetInstance();
m_localizedValueFromFormat = resourceLoader.GetResourceString(UnitConverterResourceKeys::ValueFromFormat); m_localizedValueFromFormat = resourceLoader.GetResourceString(UnitConverterResourceKeys::ValueFromFormat);
m_localizedValueToFormat = resourceLoader.GetResourceString(UnitConverterResourceKeys::ValueToFormat); m_localizedValueToFormat = resourceLoader.GetResourceString(UnitConverterResourceKeys::ValueToFormat);
@ -257,7 +257,7 @@ void UnitConverterViewModel::OnUnitChanged(Object^ parameter)
void UnitConverterViewModel::OnSwitchActive(Platform::Object^ unused) void UnitConverterViewModel::OnSwitchActive(Platform::Object^ unused)
{ {
// this can be false if this switch occurs without the user having explicitly updated any strings // this can be false if this switch occurs without the user having explicitly updated any strings
// (for example, during deserialization). We only want to try this cleanup if there's actually // (for example, during deserialization). We only want to try this cleanup if there's actually
// something to clean up. // something to clean up.
if (m_relocalizeStringOnSwitch) if (m_relocalizeStringOnSwitch)
@ -279,7 +279,7 @@ void UnitConverterViewModel::OnSwitchActive(Platform::Object^ unused)
m_valueFromUnlocalized.swap(m_valueToUnlocalized); m_valueFromUnlocalized.swap(m_valueToUnlocalized);
Utils::Swap(&m_localizedValueFromFormat, &m_localizedValueToFormat); Utils::Swap(&m_localizedValueFromFormat, &m_localizedValueToFormat);
Utils::Swap(&m_Unit1AutomationName, &m_Unit2AutomationName); Utils::Swap(&m_Unit1AutomationName, &m_Unit2AutomationName);
RaisePropertyChanged(UnitConverterViewModelProperties::Unit1AutomationName); RaisePropertyChanged(UnitConverterViewModelProperties::Unit1AutomationName);
RaisePropertyChanged(UnitConverterViewModelProperties::Unit2AutomationName); RaisePropertyChanged(UnitConverterViewModelProperties::Unit2AutomationName);
@ -324,7 +324,7 @@ String^ UnitConverterViewModel::ConvertToLocalizedString(const std::wstring& str
if (allowPartialStrings) if (allowPartialStrings)
{ {
// allow "in progress" strings, like "3." that occur during the composition of // allow "in progress" strings, like "3." that occur during the composition of
// a final number. Without this, when typing the three characters in "3.2" // a final number. Without this, when typing the three characters in "3.2"
// you don't see the decimal point when typing it, you only see it once you've finally // you don't see the decimal point when typing it, you only see it once you've finally
// typed a post-decimal digit. // typed a post-decimal digit.
@ -341,7 +341,7 @@ String^ UnitConverterViewModel::ConvertToLocalizedString(const std::wstring& str
{ {
wstring currencyResult = m_currencyFormatter->Format(stod(stringToLocalize))->Data(); wstring currencyResult = m_currencyFormatter->Format(stod(stringToLocalize))->Data();
wstring currencyCode = m_currencyFormatter->Currency->Data(); wstring currencyCode = m_currencyFormatter->Currency->Data();
// CurrencyFormatter always includes LangCode or Symbol. Make it include LangCode // CurrencyFormatter always includes LangCode or Symbol. Make it include LangCode
// because this includes a non-breaking space. Remove the LangCode. // because this includes a non-breaking space. Remove the LangCode.
auto pos = currencyResult.find(currencyCode); auto pos = currencyResult.find(currencyCode);
@ -367,7 +367,7 @@ String^ UnitConverterViewModel::ConvertToLocalizedString(const std::wstring& str
if (hasDecimal) if (hasDecimal)
{ {
// Since the output from GetLocaleInfoEx() and DecimalFormatter are differing for decimal string // Since the output from GetLocaleInfoEx() and DecimalFormatter are differing for decimal string
// we are adding the below work-around of editing the string returned by DecimalFormatter // we are adding the below work-around of editing the string returned by DecimalFormatter
// and replacing the decimal separator with the one returned by GetLocaleInfoEx() // and replacing the decimal separator with the one returned by GetLocaleInfoEx()
String^ formattedSampleString = m_decimalFormatter->Format(stod("1.1")); String^ formattedSampleString = m_decimalFormatter->Format(stod("1.1"));
wstring formattedSampleWString = wstring(formattedSampleString->Data()); wstring formattedSampleWString = wstring(formattedSampleString->Data());
@ -378,7 +378,7 @@ String^ UnitConverterViewModel::ConvertToLocalizedString(const std::wstring& str
{ {
resultWithDecimal.replace(pos, 1, &m_decimalSeparator); resultWithDecimal.replace(pos, 1, &m_decimalSeparator);
} }
// Copy back the edited string to the result // Copy back the edited string to the result
result = ref new String(resultWithDecimal.c_str()); result = ref new String(resultWithDecimal.c_str());
} }
@ -479,7 +479,7 @@ void UnitConverterViewModel::OnButtonPressed(Platform::Object^ parameter)
NumbersAndOperatorsEnum numOpEnum = CalculatorButtonPressedEventArgs::GetOperationFromCommandParameter(parameter); NumbersAndOperatorsEnum numOpEnum = CalculatorButtonPressedEventArgs::GetOperationFromCommandParameter(parameter);
UCM::Command command = CommandFromButtonId(numOpEnum); UCM::Command command = CommandFromButtonId(numOpEnum);
//Don't clear the display if combo box is open and escape is pressed // Don't clear the display if combo box is open and escape is pressed
if (command == UCM::Command::Clear && IsDropDownOpen) if (command == UCM::Command::Clear && IsDropDownOpen)
{ {
return; return;
@ -674,7 +674,7 @@ void UnitConverterViewModel::Deserialize(Platform::String^ state)
RaisePropertyChanged(nullptr); // Update since all props have been updated. RaisePropertyChanged(nullptr); // Update since all props have been updated.
} }
//Saving User Preferences of Category and Associated-Units across Sessions. // Saving User Preferences of Category and Associated-Units across Sessions.
void UnitConverterViewModel::SaveUserPreferences() void UnitConverterViewModel::SaveUserPreferences()
{ {
if (UnitsAreValid()) if (UnitsAreValid())
@ -695,7 +695,7 @@ void UnitConverterViewModel::SaveUserPreferences()
} }
} }
//Restoring User Preferences of Category and Associated-Units. // Restoring User Preferences of Category and Associated-Units.
void UnitConverterViewModel::RestoreUserPreferences() void UnitConverterViewModel::RestoreUserPreferences()
{ {
if (!IsCurrencyCurrentCategory) if (!IsCurrencyCurrentCategory)
@ -973,7 +973,7 @@ void UnitConverterViewModel::OnPaste(String^ stringToPaste, ViewMode mode)
{ {
if (isFirstLegalChar) if (isFirstLegalChar)
{ {
// Send Clear before sending something that will actually apply // Send Clear before sending something that will actually apply
// to the field. // to the field.
m_model->SendCommand(UCM::Command::Clear); m_model->SendCommand(UCM::Command::Clear);
isFirstLegalChar = false; isFirstLegalChar = false;

View File

@ -19,7 +19,7 @@ namespace CalculatorApp
public ref class Category sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged public ref class Category sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged
{ {
internal: internal:
Category(const UnitConversionManager::Category& category) : Category(const UnitConversionManager::Category& category) :
m_original(category) m_original(category)
{ } { }
@ -52,7 +52,7 @@ namespace CalculatorApp
public ref class Unit sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged public ref class Unit sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged
{ {
internal: internal:
Unit(const UnitConversionManager::Unit& unit) : Unit(const UnitConversionManager::Unit& unit) :
m_original(unit) m_original(unit)
{ } { }
@ -163,7 +163,7 @@ namespace CalculatorApp
internal: internal:
UnitConverterViewModel(const std::shared_ptr<UnitConversionManager::IUnitConverter>& model); UnitConverterViewModel(const std::shared_ptr<UnitConversionManager::IUnitConverter>& model);
public: public:
OBSERVABLE_OBJECT_CALLBACK(OnPropertyChanged); OBSERVABLE_OBJECT_CALLBACK(OnPropertyChanged);
OBSERVABLE_PROPERTY_R(Windows::Foundation::Collections::IObservableVector<Category^>^, Categories); OBSERVABLE_PROPERTY_R(Windows::Foundation::Collections::IObservableVector<Category^>^, Categories);
@ -224,7 +224,7 @@ namespace CalculatorApp
COMMAND_FOR_METHOD(PasteCommand, UnitConverterViewModel::OnPasteCommand); COMMAND_FOR_METHOD(PasteCommand, UnitConverterViewModel::OnPasteCommand);
void AnnounceConversionResult(); void AnnounceConversionResult();
internal: internal:
void ResetView(); void ResetView();
void PopulateData(); void PopulateData();
@ -242,8 +242,8 @@ namespace CalculatorApp
void UpdateValue2AutomationName(); void UpdateValue2AutomationName();
Platform::String^ Serialize(); Platform::String^ Serialize();
void Deserialize(Platform::String^ state); void Deserialize(Platform::String^ state);
//Saving And Restoring User Preferences of Category and Associated-Units across Sessions. // Saving And Restoring User Preferences of Category and Associated-Units across Sessions.
void SaveUserPreferences(); void SaveUserPreferences();
void RestoreUserPreferences(); void RestoreUserPreferences();
@ -360,9 +360,9 @@ namespace CalculatorApp
UnitConverterVMCallback(UnitConverterViewModel^ viewModel) : m_viewModel(viewModel) UnitConverterVMCallback(UnitConverterViewModel^ viewModel) : m_viewModel(viewModel)
{} {}
void DisplayCallback(const std::wstring& from, const std::wstring& to) override void DisplayCallback(const std::wstring& from, const std::wstring& to) override
{ {
m_viewModel->UpdateDisplay(from, to); m_viewModel->UpdateDisplay(from, to);
} }
void SuggestedValueCallback( void SuggestedValueCallback(

View File

@ -3,9 +3,9 @@
#pragma once #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::DependencyObject,
public Windows::UI::Xaml::Data::ICollectionView public Windows::UI::Xaml::Data::ICollectionView
{ {
@ -14,11 +14,11 @@ namespace CalculatorApp { namespace Common
m_currentPosition(-1) m_currentPosition(-1)
{ {
m_source = source; m_source = source;
Windows::UI::Xaml::Interop::IBindableObservableVector^ observable = dynamic_cast<Windows::UI::Xaml::Interop::IBindableObservableVector^>(source); Windows::UI::Xaml::Interop::IBindableObservableVector^ observable = dynamic_cast<Windows::UI::Xaml::Interop::IBindableObservableVector^>(source);
if (observable) if (observable)
{ {
observable->VectorChanged += observable->VectorChanged +=
ref new Windows::UI::Xaml::Interop::BindableVectorChangedEventHandler(this, &AlwaysSelectedCollectionView::OnSourceBindableVectorChanged); ref new Windows::UI::Xaml::Interop::BindableVectorChangedEventHandler(this, &AlwaysSelectedCollectionView::OnSourceBindableVectorChanged);
} }
} }
@ -53,7 +53,7 @@ namespace CalculatorApp { namespace Common
return ref new Platform::Collections::Vector<Platform::Object^>(); return ref new Platform::Collections::Vector<Platform::Object^>();
} }
} }
property bool HasMoreItems property bool HasMoreItems
{ {
virtual bool get() = Windows::UI::Xaml::Data::ICollectionView::HasMoreItems::get virtual bool get() = Windows::UI::Xaml::Data::ICollectionView::HasMoreItems::get
{ {
@ -77,11 +77,11 @@ namespace CalculatorApp { namespace Common
} }
// The item is not in the collection // 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 // restore the selection to the way we wanted it to begin with
if (m_currentPosition >= 0 && m_currentPosition < static_cast<int>(m_source->Size)) if (m_currentPosition >= 0 && m_currentPosition < static_cast<int>(m_source->Size))
{ {
this->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, this->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal,
ref new Windows::UI::Core::DispatchedHandler( ref new Windows::UI::Core::DispatchedHandler(
[this]() [this]()
{ {
@ -161,7 +161,7 @@ namespace CalculatorApp { namespace Common
m_currentChanging -= token; m_currentChanging -= token;
} }
} }
// IVector<Object^> // IVector<Object^>
// Not implemented methods // Not implemented methods
virtual void Append(Platform::Object^ /*item*/) = Windows::Foundation::Collections::IVector<Platform::Object^>::Append virtual void Append(Platform::Object^ /*item*/) = Windows::Foundation::Collections::IVector<Platform::Object^>::Append
@ -219,7 +219,7 @@ namespace CalculatorApp { namespace Common
return m_source->Size; return m_source->Size;
} }
} }
// IObservableVector<Object^> // IObservableVector<Object^>
event Windows::Foundation::Collections::VectorChangedEventHandler<Platform::Object^>^ VectorChanged event Windows::Foundation::Collections::VectorChangedEventHandler<Platform::Object^>^ VectorChanged
{ {
@ -262,9 +262,9 @@ namespace CalculatorApp { namespace Common
private: private:
virtual Platform::Object^ Convert( virtual Platform::Object^ Convert(
Platform::Object^ value, Platform::Object^ value,
Windows::UI::Xaml::Interop::TypeName /*targetType*/, Windows::UI::Xaml::Interop::TypeName /*targetType*/,
Platform::Object^ /*parameter*/, Platform::Object^ /*parameter*/,
Platform::String^ /*language*/) = Windows::UI::Xaml::Data::IValueConverter::Convert Platform::String^ /*language*/) = Windows::UI::Xaml::Data::IValueConverter::Convert
{ {
auto result = dynamic_cast<Windows::UI::Xaml::Interop::IBindableVector^>(value); auto result = dynamic_cast<Windows::UI::Xaml::Interop::IBindableVector^>(value);
@ -276,9 +276,9 @@ namespace CalculatorApp { namespace Common
} }
virtual Platform::Object^ ConvertBack( virtual Platform::Object^ ConvertBack(
Platform::Object^ /*value*/, Platform::Object^ /*value*/,
Windows::UI::Xaml::Interop::TypeName /*targetType*/, Windows::UI::Xaml::Interop::TypeName /*targetType*/,
Platform::Object^ /*parameter*/, Platform::Object^ /*parameter*/,
Platform::String^ /*language*/) = Windows::UI::Xaml::Data::IValueConverter::ConvertBack Platform::String^ /*language*/) = Windows::UI::Xaml::Data::IValueConverter::ConvertBack
{ {
return Windows::UI::Xaml::DependencyProperty::UnsetValue; return Windows::UI::Xaml::DependencyProperty::UnsetValue;

View File

@ -37,7 +37,7 @@ namespace CalculatorApp
m_appLifecycleProvider( m_appLifecycleProvider(
L"Microsoft.Windows.AppLifeCycle", L"Microsoft.Windows.AppLifeCycle",
LoggingChannelOptions(GUID{ 0x4f50731a, 0x89cf, 0x4782, 0xb3, 0xe0, 0xdc, 0xe8, 0xc9, 0x4, 0x76, 0xba }), // Microsoft Telemetry group LoggingChannelOptions(GUID{ 0x4f50731a, 0x89cf, 0x4782, 0xb3, 0xe0, 0xdc, 0xe8, 0xc9, 0x4, 0x76, 0xba }), // Microsoft Telemetry group
GUID{ 0xef00584a, 0x2655, 0x462c, 0xbc, 0x24, 0xe7, 0xde, 0x63, 0xe, 0x7f, 0xbf }) //Unique provider ID {EF00584A-2655-462C-BC24-E7DE630E7FBF} GUID{ 0xef00584a, 0x2655, 0x462c, 0xbc, 0x24, 0xe7, 0xde, 0x63, 0xe, 0x7f, 0xbf }) // Unique provider ID {EF00584A-2655-462C-BC24-E7DE630E7FBF}
{ {
} }

View File

@ -29,9 +29,9 @@ namespace CalculatorApp
AppLifecycleLogger(); AppLifecycleLogger();
// Any new Log method should // Any new Log method should
// a) decide the level of logging. This will help us in limiting recording of events only up to a certain level. See this link for guidance https://msdn.microsoft.com/en-us/library/windows/desktop/aa363742(v=vs.85).aspx // a) Decide the level of logging. This will help us in limiting recording of events only up to a certain level. See this link for guidance https://msdn.microsoft.com/en-us/library/windows/desktop/aa363742(v=vs.85).aspx
// We're using Verbose level for events that are called frequently and needed only for debugging or capturing perf for specific scenarios // We're using Verbose level for events that are called frequently and needed only for debugging or capturing perf for specific scenarios
// b) should decide whether or not to log to telemetry and pass TraceLoggingKeyword(MICROSOFT_KEYWORD_TELEMETRY) accordingly // b) Should decide whether or not to log to telemetry and pass TraceLoggingKeyword(MICROSOFT_KEYWORD_TELEMETRY) accordingly
// c) Should accept a variable number of additional data arguments if needed // c) Should accept a variable number of additional data arguments if needed
void LogAppLifecycleEvent(winrt::hstring const& eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields const& fields) const; void LogAppLifecycleEvent(winrt::hstring const& eventName, winrt::Windows::Foundation::Diagnostics::LoggingFields const& fields) const;
void PopulateAppInfo(winrt::Windows::Foundation::Diagnostics::LoggingFields& fields) const; void PopulateAppInfo(winrt::Windows::Foundation::Diagnostics::LoggingFields& fields) const;

View File

@ -18,17 +18,17 @@ void BindableBase::OnPropertyChanged(String^ propertyName)
PropertyChanged(this, ref new PropertyChangedEventArgs(propertyName)); PropertyChanged(this, ref new PropertyChangedEventArgs(propertyName));
} }
Windows::UI::Xaml::Data::ICustomProperty^ BindableBase::GetCustomProperty(Platform::String^ name) Windows::UI::Xaml::Data::ICustomProperty^ BindableBase::GetCustomProperty(Platform::String^ name)
{ {
return nullptr; return nullptr;
} }
Windows::UI::Xaml::Data::ICustomProperty^ BindableBase::GetIndexedProperty(Platform::String^ name, Windows::UI::Xaml::Interop::TypeName type) Windows::UI::Xaml::Data::ICustomProperty^ BindableBase::GetIndexedProperty(Platform::String^ name, Windows::UI::Xaml::Interop::TypeName type)
{ {
return nullptr; return nullptr;
} }
Platform::String^ BindableBase::GetStringRepresentation() Platform::String^ BindableBase::GetStringRepresentation()
{ {
return this->ToString(); return this->ToString();
} }

View File

@ -76,7 +76,7 @@ void CalculationResult::OnApplyTemplate()
if (m_textContainer) if (m_textContainer)
{ {
m_textContainer->SizeChanged += ref new SizeChangedEventHandler(this, &CalculationResult::TextContainerSizeChanged); m_textContainer->SizeChanged += ref new SizeChangedEventHandler(this, &CalculationResult::TextContainerSizeChanged);
// We want to know when the size of the container changes so // We want to know when the size of the container changes so
// we can rescale the textbox // we can rescale the textbox
m_textContainerLayoutChangedToken = m_textContainer->LayoutUpdated += ref new EventHandler<Object^>(this, &CalculationResult::OnTextContainerLayoutUpdated); m_textContainerLayoutChangedToken = m_textContainer->LayoutUpdated += ref new EventHandler<Object^>(this, &CalculationResult::OnTextContainerLayoutUpdated);
@ -154,15 +154,15 @@ void CalculationResult::OnIsInErrorPropertyChanged(bool /*oldValue*/, bool newVa
if (newValue) if (newValue)
{ {
// If there's an error message we need to override the normal display font // If there's an error message we need to override the normal display font
// with the font appropriate for this language. This is because the error // with the font appropriate for this language. This is because the error
// message is localized and therefore can contain characters that are not // message is localized and therefore can contain characters that are not
// available in the normal font. // available in the normal font.
// We use UIText as the font type because this is the most common font type to use // We use UIText as the font type because this is the most common font type to use
m_textBlock->FontFamily = LocalizationService::GetInstance()->GetLanguageFontFamilyForType(LanguageFontType::UIText); m_textBlock->FontFamily = LocalizationService::GetInstance()->GetLanguageFontFamilyForType(LanguageFontType::UIText);
} }
else else
{ {
// The error result is no longer an error so we will restore the // The error result is no longer an error so we will restore the
// value to FontFamily property to the value provided in the style // value to FontFamily property to the value provided in the style
// for the TextBlock in the template. // for the TextBlock in the template.
m_textBlock->ClearValue(TextBlock::FontFamilyProperty); m_textBlock->ClearValue(TextBlock::FontFamilyProperty);
@ -175,7 +175,7 @@ void CalculationResult::UpdateVisualState()
{ {
VisualStateManager::GoToState(this, "Active", true); VisualStateManager::GoToState(this, "Active", true);
} }
else else
{ {
VisualStateManager::GoToState(this, "Normal", true); VisualStateManager::GoToState(this, "Normal", true);
} }
@ -192,8 +192,8 @@ void CalculationResult::UpdateTextState()
String^ oldText = m_textBlock->Text; String^ oldText = m_textBlock->Text;
String^ newText = Utils::LRO + DisplayValue + Utils::PDF; String^ newText = Utils::LRO + DisplayValue + Utils::PDF;
//Initiate the scaling operation // Initiate the scaling operation
//UpdateLayout will keep calling us until we make it through the below 2 if-statements // UpdateLayout will keep calling us until we make it through the below 2 if-statements
if (!m_isScalingText || oldText != newText) if (!m_isScalingText || oldText != newText)
{ {
m_textBlock->Text = newText; m_textBlock->Text = newText;
@ -329,17 +329,17 @@ void CalculationResult::ShowHideScrollButtons(::Visibility vLeft, ::Visibility v
void CalculationResult::UpdateScrollButtons() void CalculationResult::UpdateScrollButtons()
{ {
// When the width is smaller than the container, don't show any // When the width is smaller than the container, don't show any
if (m_textBlock->ActualWidth < m_textContainer->ActualWidth) if (m_textBlock->ActualWidth < m_textContainer->ActualWidth)
{ {
ShowHideScrollButtons(::Visibility::Collapsed, ::Visibility::Collapsed); ShowHideScrollButtons(::Visibility::Collapsed, ::Visibility::Collapsed);
} }
// We have more number on both side. Show both arrows // We have more number on both side. Show both arrows
else if (m_textContainer->HorizontalOffset > 0 && m_textContainer->HorizontalOffset < (m_textContainer->ExtentWidth - m_textContainer->ViewportWidth)) else if (m_textContainer->HorizontalOffset > 0 && m_textContainer->HorizontalOffset < (m_textContainer->ExtentWidth - m_textContainer->ViewportWidth))
{ {
ShowHideScrollButtons(::Visibility::Visible, ::Visibility::Visible); ShowHideScrollButtons(::Visibility::Visible, ::Visibility::Visible);
} }
// Width is larger than the container and left most part of the number is shown. Should be able to scroll left. // Width is larger than the container and left most part of the number is shown. Should be able to scroll left.
else if (m_textContainer->HorizontalOffset == 0) else if (m_textContainer->HorizontalOffset == 0)
{ {
ShowHideScrollButtons(::Visibility::Collapsed, ::Visibility::Visible); ShowHideScrollButtons(::Visibility::Collapsed, ::Visibility::Visible);
} }

View File

@ -54,7 +54,7 @@ void CalculatorButton::OnKeyUp(KeyRoutedEventArgs^ e)
} }
void CalculatorButton::OnButtonIdPropertyChanged( void CalculatorButton::OnButtonIdPropertyChanged(
NumbersAndOperatorsEnum /*oldValue*/, NumbersAndOperatorsEnum /*oldValue*/,
NumbersAndOperatorsEnum newValue) NumbersAndOperatorsEnum newValue)
{ {
this->CommandParameter = ref new CalculatorButtonPressedEventArgs(AuditoryFeedback, newValue); this->CommandParameter = ref new CalculatorButtonPressedEventArgs(AuditoryFeedback, newValue);

View File

@ -13,7 +13,7 @@ namespace CalculatorApp
public ref class CalculatorButton sealed: Windows::UI::Xaml::Controls::Button public ref class CalculatorButton sealed: Windows::UI::Xaml::Controls::Button
{ {
public: public:
CalculatorButton(); CalculatorButton();
DEPENDENCY_PROPERTY_OWNER(CalculatorButton); DEPENDENCY_PROPERTY_OWNER(CalculatorButton);

View File

@ -43,7 +43,7 @@ void FlipButtons::OnKeyUp(KeyRoutedEventArgs^ e)
} }
void FlipButtons::OnButtonIdPropertyChanged( void FlipButtons::OnButtonIdPropertyChanged(
NumbersAndOperatorsEnum /*oldValue*/, NumbersAndOperatorsEnum /*oldValue*/,
NumbersAndOperatorsEnum newValue) NumbersAndOperatorsEnum newValue)
{ {
this->CommandParameter = newValue; this->CommandParameter = newValue;

View File

@ -29,7 +29,7 @@ namespace CalculatorApp
private: private:
void OnButtonIdPropertyChanged( void OnButtonIdPropertyChanged(
NumbersAndOperatorsEnum oldValue, NumbersAndOperatorsEnum oldValue,
NumbersAndOperatorsEnum newValue); NumbersAndOperatorsEnum newValue);
}; };
} }

View File

@ -23,7 +23,7 @@ using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation; using namespace Windows::UI::Xaml::Navigation;
void OperandTextBox::OnApplyTemplate() void OperandTextBox::OnApplyTemplate()
{ {
this->IsEnabled = false; this->IsEnabled = false;
this->IsHitTestVisible = false; this->IsHitTestVisible = false;
this->IsTapEnabled = false; this->IsTapEnabled = false;

View File

@ -34,22 +34,22 @@ void OverflowTextBlock::OnApplyTemplate()
m_expressionContainer = safe_cast<ScrollViewer^>(GetTemplateChild("expressionContainer")); m_expressionContainer = safe_cast<ScrollViewer^>(GetTemplateChild("expressionContainer"));
m_expressionContainer->ChangeView(m_expressionContainer->ExtentWidth - m_expressionContainer->ViewportWidth, nullptr, nullptr); m_expressionContainer->ChangeView(m_expressionContainer->ExtentWidth - m_expressionContainer->ViewportWidth, nullptr, nullptr);
m_scrollLeft = safe_cast<Button^>(GetTemplateChild("scrollLeft")); m_scrollLeft = safe_cast<Button^>(GetTemplateChild("scrollLeft"));
m_scrollRight = safe_cast<Button^>(GetTemplateChild("scrollRight")); m_scrollRight = safe_cast<Button^>(GetTemplateChild("scrollRight"));
m_scrollLeftClickEventToken = m_scrollLeft->Click += ref new RoutedEventHandler(this, &OverflowTextBlock::OnScrollClick); m_scrollLeftClickEventToken = m_scrollLeft->Click += ref new RoutedEventHandler(this, &OverflowTextBlock::OnScrollClick);
m_scrollRightClickEventToken = m_scrollRight->Click += ref new RoutedEventHandler(this, &OverflowTextBlock::OnScrollClick); m_scrollRightClickEventToken = m_scrollRight->Click += ref new RoutedEventHandler(this, &OverflowTextBlock::OnScrollClick);
m_scrollingLeft = false; m_scrollingLeft = false;
m_scrollingRight = false; m_scrollingRight = false;
auto borderContainer = safe_cast<Border^>(GetTemplateChild("expressionborder")); auto borderContainer = safe_cast<Border^>(GetTemplateChild("expressionborder"));
m_pointerEnteredEventToken = borderContainer->PointerEntered += ref new PointerEventHandler(this, &OverflowTextBlock::OnPointerEntered); m_pointerEnteredEventToken = borderContainer->PointerEntered += ref new PointerEventHandler(this, &OverflowTextBlock::OnPointerEntered);
m_pointerExitedEventToken = borderContainer->PointerExited += ref new PointerEventHandler(this, &OverflowTextBlock::OnPointerExited); m_pointerExitedEventToken = borderContainer->PointerExited += ref new PointerEventHandler(this, &OverflowTextBlock::OnPointerExited);
m_listView = safe_cast<ListView^>(GetTemplateChild("TokenList")); m_listView = safe_cast<ListView^>(GetTemplateChild("TokenList"));
UpdateAllState(); UpdateAllState();
} }

View File

@ -12,7 +12,7 @@ namespace CalculatorApp
public ref class OverflowTextBlock sealed : public Windows::UI::Xaml::Controls::Control public ref class OverflowTextBlock sealed : public Windows::UI::Xaml::Controls::Control
{ {
public: public:
OverflowTextBlock() OverflowTextBlock()
{ {
} }

View File

@ -16,7 +16,7 @@ namespace CalculatorApp
public: public:
static constexpr Windows::UI::Xaml::Visibility Convert(bool visibility) static constexpr Windows::UI::Xaml::Visibility Convert(bool visibility)
{ {
return visibility return visibility
? Windows::UI::Xaml::Visibility::Visible ? Windows::UI::Xaml::Visibility::Visible
: Windows::UI::Xaml::Visibility::Collapsed; : Windows::UI::Xaml::Visibility::Collapsed;
} }

View File

@ -51,7 +51,7 @@ UnitConverter::UnitConverter() :
{ {
InitializeComponent(); InitializeComponent();
//adding ESC key shortcut binding to clear button // adding ESC key shortcut binding to clear button
clearEntryButtonPos0->SetValue(Common::KeyboardShortcutManager::VirtualKeyProperty, Common::MyVirtualKey::Escape); clearEntryButtonPos0->SetValue(Common::KeyboardShortcutManager::VirtualKeyProperty, Common::MyVirtualKey::Escape);
m_layoutDirection = LocalizationService::GetInstance()->GetFlowDirection(); m_layoutDirection = LocalizationService::GetInstance()->GetFlowDirection();
@ -278,7 +278,7 @@ void UnitConverter::AnimateConverter()
void UnitConverter::OnValueSelected(_In_ Platform::Object^ sender) void UnitConverter::OnValueSelected(_In_ Platform::Object^ sender)
{ {
auto value = safe_cast<CalculationResult^>(sender); auto value = safe_cast<CalculationResult^>(sender);
//update the font size since the font is changed to bold // update the font size since the font is changed to bold
value->UpdateTextState(); value->UpdateTextState();
safe_cast<UnitConverterViewModel^>(this->DataContext)->OnValueActivated(AsActivatable(value)); safe_cast<UnitConverterViewModel^>(this->DataContext)->OnValueActivated(AsActivatable(value));
} }

View File

@ -82,7 +82,7 @@ namespace CalculatorApp
assert(frame->BackStackDepth == 0); assert(frame->BackStackDepth == 0);
m_frame = frame; m_frame = frame;
} }
void WindowFrameService::RegisterOnWindowClosingHandler(function<void()> onWindowClosingHandler) void WindowFrameService::RegisterOnWindowClosingHandler(function<void()> onWindowClosingHandler)
{ {
m_onWindowClosingHandlers.push_back(onWindowClosingHandler); m_onWindowClosingHandlers.push_back(onWindowClosingHandler);

View File

@ -6,7 +6,7 @@
namespace CalculatorApp namespace CalculatorApp
{ {
public ref class WindowFrameService sealed public ref class WindowFrameService sealed
{ {
public: public:
@ -16,16 +16,16 @@ namespace CalculatorApp
internal: internal:
// createdByUs means any window that we create. // createdByUs means any window that we create.
// !createdByUs means the main window // !createdByUs means the main window
static WindowFrameService^ CreateNewWindowFrameService(_In_ Windows::UI::Xaml::Controls::Frame^ viewFrame, static WindowFrameService^ CreateNewWindowFrameService(_In_ Windows::UI::Xaml::Controls::Frame^ viewFrame,
bool createdByUs, bool createdByUs,
Platform::WeakReference parent); Platform::WeakReference parent);
Windows::UI::Core::CoreDispatcher^ GetCoreDispatcher(); Windows::UI::Core::CoreDispatcher^ GetCoreDispatcher();
int GetViewId(); int GetViewId();
void RegisterOnWindowClosingHandler(std::function<void()> onWindowClosingHandler); void RegisterOnWindowClosingHandler(std::function<void()> onWindowClosingHandler);
concurrency::task<void> HandleViewRelease(); concurrency::task<void> HandleViewRelease();
// Throws InvalidArgumentException if a service is already registered with the specified id // Throws InvalidArgumentException if a service is already registered with the specified id
void RegisterRuntimeWindowService(Windows::UI::Xaml::Interop::TypeName serviceId, _In_opt_ Platform::Object^ service); void RegisterRuntimeWindowService(Windows::UI::Xaml::Interop::TypeName serviceId, _In_opt_ Platform::Object^ service);
@ -53,7 +53,7 @@ namespace CalculatorApp
Platform::Agile<Windows::UI::Core::CoreWindow^> m_currentWindow; Platform::Agile<Windows::UI::Core::CoreWindow^> m_currentWindow;
Platform::Agile<Windows::UI::Core::CoreDispatcher^> m_coreDispatcher; Platform::Agile<Windows::UI::Core::CoreDispatcher^> m_coreDispatcher;
Windows::UI::Xaml::Controls::Frame^ m_frame; Windows::UI::Xaml::Controls::Frame^ m_frame;
int m_viewId; int m_viewId;
Platform::WeakReference m_parent; Platform::WeakReference m_parent;
std::unordered_map<Platform::String^, Platform::Object^> m_runtimeServicesMap; std::unordered_map<Platform::String^, Platform::Object^> m_runtimeServicesMap;

View File

@ -526,7 +526,7 @@ namespace CalculatorManagerTest
Command commands22[] = { Command::Command0, Command::CommandSQRT, Command::CommandNULL }; Command commands22[] = { Command::Command0, Command::CommandSQRT, Command::CommandNULL };
TestDriver::Test(L"0", L"\x221A(0)", commands22); TestDriver::Test(L"0", L"\x221A(0)", commands22);
Command commands23[] = { Command::Command1, Command::Command0, Command::Command2, Command::Command4, Command commands23[] = { Command::Command1, Command::Command0, Command::Command2, Command::Command4,
Command::CommandSQRT, Command::CommandSUB, Command::Command3, Command::Command2, Command::CommandSQRT, Command::CommandSUB, Command::Command3, Command::Command2,
Command::CommandADD, Command::CommandNULL }; Command::CommandADD, Command::CommandNULL };
@ -593,11 +593,11 @@ namespace CalculatorManagerTest
Command commands17[] = { Command::Command5, Command::CommandPWR, Command::Command0, Command commands17[] = { Command::Command5, Command::CommandPWR, Command::Command0,
Command::CommandADD, Command::CommandNULL }; Command::CommandADD, Command::CommandNULL };
TestDriver::Test(L"1", L"5 ^ 0 + ", commands17); TestDriver::Test(L"1", L"5 ^ 0 + ", commands17);
Command commands18[] = { Command::Command0, Command::CommandPWR, Command::Command0, Command commands18[] = { Command::Command0, Command::CommandPWR, Command::Command0,
Command::CommandADD, Command::CommandNULL }; Command::CommandADD, Command::CommandNULL };
TestDriver::Test(L"1", L"0 ^ 0 + ", commands18); TestDriver::Test(L"1", L"0 ^ 0 + ", commands18);
Command commands19[] = { Command::Command2, Command::Command7, Command::CommandSIGN, Command::CommandROOT, Command commands19[] = { Command::Command2, Command::Command7, Command::CommandSIGN, Command::CommandROOT,
Command::Command3, Command::CommandADD, Command::CommandNULL }; Command::Command3, Command::CommandADD, Command::CommandNULL };
TestDriver::Test(L"-3", L"-27 yroot 3 + ", commands19, true, true); TestDriver::Test(L"-3", L"-27 yroot 3 + ", commands19, true, true);
@ -859,7 +859,7 @@ namespace CalculatorManagerTest
memorizedNumbers = pCalculatorDisplay->GetMemorizedNumbers(); memorizedNumbers = pCalculatorDisplay->GetMemorizedNumbers();
VERIFY_ARE_EQUAL(wstring(L"2"), memorizedNumbers.at(0)); VERIFY_ARE_EQUAL(wstring(L"2"), memorizedNumbers.at(0));
// Test for trying to memorize invalid value // Test for trying to memorize invalid value
m_calculatorManager->SendCommand(Command::Command2); m_calculatorManager->SendCommand(Command::Command2);
m_calculatorManager->SendCommand(Command::CommandSIGN); m_calculatorManager->SendCommand(Command::CommandSIGN);
m_calculatorManager->SendCommand(Command::CommandSQRT); m_calculatorManager->SendCommand(Command::CommandSQRT);

View File

@ -264,7 +264,7 @@ namespace CalculatorUnitTests
VERIFY_IS_FALSE(loader.LoadFinished()); VERIFY_IS_FALSE(loader.LoadFinished());
VERIFY_IS_FALSE(loader.LoadedFromCache()); VERIFY_IS_FALSE(loader.LoadedFromCache());
} }
TEST_METHOD(LoadFromCache_Fail_ResponseLanguageChanged) TEST_METHOD(LoadFromCache_Fail_ResponseLanguageChanged)
{ {
DateTime now = Utils::GetUniversalSystemTime(); DateTime now = Utils::GetUniversalSystemTime();

View File

@ -354,7 +354,7 @@ namespace CalculatorUnitTests
{ NumbersAndOperatorsEnum::HexButton, L"0", L"" }, { NumbersAndOperatorsEnum::HexButton, L"0", L"" },
{ NumbersAndOperatorsEnum::None, L"", L"" } { NumbersAndOperatorsEnum::None, L"", L"" }
}; };
ValidateViewModelByCommands(programmerViewModel1, programmerModeInitializeItems1, false); ValidateViewModelByCommands(programmerViewModel1, programmerModeInitializeItems1, false);
// Bit Length: Word & Radix Type: Oct // Bit Length: Word & Radix Type: Oct
@ -369,7 +369,7 @@ namespace CalculatorUnitTests
TESTITEM programmerModeTestItems1[] = { TESTITEM programmerModeTestItems1[] = {
{ NumbersAndOperatorsEnum::F, L"F", L"" }, { NumbersAndOperatorsEnum::F, L"F", L"" },
{ NumbersAndOperatorsEnum::F, L"FF", L"" }, { NumbersAndOperatorsEnum::F, L"FF", L"" },
// One more F shouldn't have any effect, testing for precision // One more F shouldn't have any effect, testing for precision
{ NumbersAndOperatorsEnum::F, L"FF", L"" }, { NumbersAndOperatorsEnum::F, L"FF", L"" },
{ NumbersAndOperatorsEnum::None, L"", L"" } { NumbersAndOperatorsEnum::None, L"", L"" }
}; };
@ -663,7 +663,7 @@ namespace CalculatorUnitTests
// needs to be updated with correct expected value and viewmodel needs // needs to be updated with correct expected value and viewmodel needs
// to be updated to calculate correct value. // to be updated to calculate correct value.
//DateCalculatorViewModel^ viewModels[4]; // DateCalculatorViewModel^ viewModels[4];
//// Initialize the view models //// Initialize the view models
//for (int i = 0; i < 4; i++) //for (int i = 0; i < 4; i++)
@ -776,7 +776,7 @@ namespace CalculatorUnitTests
VERIFY_IS_TRUE(CAT1 == viewModels[0]->CurrentCategory->GetModelCategory()); VERIFY_IS_TRUE(CAT1 == viewModels[0]->CurrentCategory->GetModelCategory());
VERIFY_IS_TRUE(CAT2 == viewModels[1]->CurrentCategory->GetModelCategory()); VERIFY_IS_TRUE(CAT2 == viewModels[1]->CurrentCategory->GetModelCategory());
VERIFY_IS_TRUE(CAT3 == viewModels[2]->CurrentCategory->GetModelCategory()); VERIFY_IS_TRUE(CAT3 == viewModels[2]->CurrentCategory->GetModelCategory());
VERIFY_IS_TRUE(UNIT1 == viewModels[0]->Unit1->GetModelUnit()); VERIFY_IS_TRUE(UNIT1 == viewModels[0]->Unit1->GetModelUnit());
VERIFY_IS_TRUE(UNIT2 == viewModels[0]->Unit2->GetModelUnit()); VERIFY_IS_TRUE(UNIT2 == viewModels[0]->Unit2->GetModelUnit());
@ -925,7 +925,7 @@ namespace CalculatorUnitTests
VERIFY_ARE_EQUAL(GetStringValue(standardViewModel->DisplayValue), StringReference(L"1")); VERIFY_ARE_EQUAL(GetStringValue(standardViewModel->DisplayValue), StringReference(L"1"));
// Again perform calculations on Standard Calc instance and validate that the Converter remains unaffected // Again perform calculations on Standard Calc instance and validate that the Converter remains unaffected
// Standard Mode: Expression 1+2= // Standard Mode: Expression 1+2=
TESTITEM standardModeTestItems2[] = { TESTITEM standardModeTestItems2[] = {
{ NumbersAndOperatorsEnum::One, L"1", L"" }, { NumbersAndOperatorsEnum::One, L"1", L"" },
@ -978,7 +978,7 @@ namespace CalculatorUnitTests
}; };
ValidateViewModelByCommands(viewModels[0], standardModeTestItems, false /*doReset*/); ValidateViewModelByCommands(viewModels[0], standardModeTestItems, false /*doReset*/);
//Launch a new instance in standard mode // Launch a new instance in standard mode
viewModels[2] = ref new StandardCalculatorViewModel(); viewModels[2] = ref new StandardCalculatorViewModel();
ChangeMode(viewModels[2], 0); ChangeMode(viewModels[2], 0);
@ -994,7 +994,7 @@ namespace CalculatorUnitTests
}; };
ValidateViewModelByCommands(viewModels[2], standardModeTestItemsNew, false /*doReset*/); ValidateViewModelByCommands(viewModels[2], standardModeTestItemsNew, false /*doReset*/);
//Radix in the programmer mode launched should still be hex. // Radix in the programmer mode launched should still be hex.
// A + 1 = B // A + 1 = B
TESTITEM programmerModeTestItemsNew[] = { TESTITEM programmerModeTestItemsNew[] = {
{ NumbersAndOperatorsEnum::A, L"A", L"" }, { NumbersAndOperatorsEnum::A, L"A", L"" },

View File

@ -779,7 +779,7 @@ namespace CalculatorUnitTests
VERIFY_ARE_EQUAL(viewModel->IsOperatorCommand, false); VERIFY_ARE_EQUAL(viewModel->IsOperatorCommand, false);
} }
//When memory button is pressed - verify if display value is being stored in vector // When memory button is pressed - verify if display value is being stored in vector
TEST_METHOD(OnMemoryButtonPressed) TEST_METHOD(OnMemoryButtonPressed)
{ {
StandardCalculatorViewModel^ viewModel = ref new StandardCalculatorViewModel(); StandardCalculatorViewModel^ viewModel = ref new StandardCalculatorViewModel();
@ -790,7 +790,7 @@ namespace CalculatorUnitTests
VERIFY_ARE_EQUAL((int)viewModel->MemorizedNumbers->Size, 2); VERIFY_ARE_EQUAL((int)viewModel->MemorizedNumbers->Size, 2);
} }
//when memory list is empty and M+ is pressed // When memory list is empty and M+ is pressed
TEST_METHOD(OnMemoryAddWhenMemoryEmpty) TEST_METHOD(OnMemoryAddWhenMemoryEmpty)
{ {
m_viewModel->IsStandard = true; m_viewModel->IsStandard = true;
@ -808,7 +808,7 @@ namespace CalculatorUnitTests
} }
//when memory list is empty and M- is pressed // When memory list is empty and M- is pressed
TEST_METHOD(OnMemorySubtractWhenMemoryEmpty) TEST_METHOD(OnMemorySubtractWhenMemoryEmpty)
{ {
m_viewModel->IsStandard = true; m_viewModel->IsStandard = true;
@ -825,7 +825,7 @@ namespace CalculatorUnitTests
VERIFY_ARE_EQUAL(Platform::StringReference(L"-1,001"), m_viewModel->DisplayValue); VERIFY_ARE_EQUAL(Platform::StringReference(L"-1,001"), m_viewModel->DisplayValue);
} }
//when negative number is saved in memory // When negative number is saved in memory
TEST_METHOD(OnNegativeEntryInMemory) TEST_METHOD(OnNegativeEntryInMemory)
{ {
ChangeMode(m_viewModel, 0/*Standard*/); ChangeMode(m_viewModel, 0/*Standard*/);
@ -851,7 +851,7 @@ namespace CalculatorUnitTests
VERIFY_ARE_EQUAL(Platform::StringReference(L"-1,001"), Utils::GetStringValue(memorySlotProgrammer->Value)); VERIFY_ARE_EQUAL(Platform::StringReference(L"-1,001"), Utils::GetStringValue(memorySlotProgrammer->Value));
} }
//when decimal number is saved in memory // When decimal number is saved in memory
TEST_METHOD(OnDecimalEntryInMemory) TEST_METHOD(OnDecimalEntryInMemory)
{ {
ChangeMode(m_viewModel, 0/*Standard*/); ChangeMode(m_viewModel, 0/*Standard*/);
@ -878,7 +878,7 @@ namespace CalculatorUnitTests
VERIFY_ARE_EQUAL(Platform::StringReference(L"1,001"), Utils::GetStringValue(memorySlotProgrammer->Value)); VERIFY_ARE_EQUAL(Platform::StringReference(L"1,001"), Utils::GetStringValue(memorySlotProgrammer->Value));
} }
//when negative decimal number is saved in memory // When negative decimal number is saved in memory
TEST_METHOD(OnNegativeDecimalInMemory) TEST_METHOD(OnNegativeDecimalInMemory)
{ {
m_viewModel->IsStandard = true; m_viewModel->IsStandard = true;
@ -898,7 +898,7 @@ namespace CalculatorUnitTests
VERIFY_ARE_EQUAL(Platform::StringReference(L"-1,001.1"), m_viewModel->DisplayValue); VERIFY_ARE_EQUAL(Platform::StringReference(L"-1,001.1"), m_viewModel->DisplayValue);
} }
//when decimal number is added to the memory // When decimal number is added to the memory
TEST_METHOD(OnDecimalAddedToMemory) TEST_METHOD(OnDecimalAddedToMemory)
{ {
m_viewModel->IsStandard = true; m_viewModel->IsStandard = true;
@ -928,7 +928,7 @@ namespace CalculatorUnitTests
VERIFY_ARE_EQUAL(Platform::StringReference(L"2,002.1"), m_viewModel->DisplayValue); VERIFY_ARE_EQUAL(Platform::StringReference(L"2,002.1"), m_viewModel->DisplayValue);
} }
//when memory is saved in programmer as Hex value and then we switch to standard mode, test to see that memory gets converted to decimal // When memory is saved in programmer as Hex value and then we switch to standard mode, test to see that memory gets converted to decimal
TEST_METHOD(OnMemorySavedInHexRadixAndSwitchedToStandardMode) TEST_METHOD(OnMemorySavedInHexRadixAndSwitchedToStandardMode)
{ {
ChangeMode(m_viewModel, 2/*programmer*/); ChangeMode(m_viewModel, 2/*programmer*/);
@ -971,8 +971,8 @@ namespace CalculatorUnitTests
} }
//When memory button is pressed more than max number of slots allowed, // When memory button is pressed more than max number of slots allowed,
//the MemorizedNumbers vector size should not increase. // the MemorizedNumbers vector size should not increase.
TEST_METHOD(OnMemoryButtonPressedMaxTimes) TEST_METHOD(OnMemoryButtonPressedMaxTimes)
{ {
StandardCalculatorViewModel^ viewModel = ref new StandardCalculatorViewModel(); StandardCalculatorViewModel^ viewModel = ref new StandardCalculatorViewModel();
@ -1014,7 +1014,7 @@ namespace CalculatorUnitTests
VERIFY_ARE_EQUAL(Platform::StringReference(L"1,001"), m_viewModel->DisplayValue); VERIFY_ARE_EQUAL(Platform::StringReference(L"1,001"), m_viewModel->DisplayValue);
} }
// verify nothing happens if there is no memory and the memory slot pressed action is taken // Verify nothing happens if there is no memory and the memory slot pressed action is taken
TEST_METHOD(OnMemoryItemPressedNoMemory) TEST_METHOD(OnMemoryItemPressedNoMemory)
{ {
TESTITEM items[] = { TESTITEM items[] = {

View File

@ -76,7 +76,7 @@ namespace UnitConverterUnitTests
SetConversionDataParams(&conversion4, 0.453592, 0, false); SetConversionDataParams(&conversion4, 0.453592, 0, false);
SetConversionDataParams(&conversion5, 2.20462, 0, false); SetConversionDataParams(&conversion5, 2.20462, 0, false);
//Setting the conversion ratios for testing // Setting the conversion ratios for testing
unit1Map[u1] = conversion1; unit1Map[u1] = conversion1;
unit1Map[u2] = conversion2; unit1Map[u2] = conversion2;
@ -95,7 +95,7 @@ namespace UnitConverterUnitTests
m_ratioMaps[u3] = unit3Map; m_ratioMaps[u3] = unit3Map;
m_ratioMaps[u4] = unit4Map; m_ratioMaps[u4] = unit4Map;
} }
void LoadData() void LoadData()
{ {
m_loadDataCallCount++; m_loadDataCallCount++;
@ -105,12 +105,12 @@ namespace UnitConverterUnitTests
{ {
return m_categories; return m_categories;
} }
vector<Unit> LoadOrderedUnits(const Category& c) vector<Unit> LoadOrderedUnits(const Category& c)
{ {
return m_units[c]; return m_units[c];
} }
unordered_map<Unit, ConversionData, UnitHash> LoadOrderedRatios(const Unit& u) unordered_map<Unit, ConversionData, UnitHash> LoadOrderedRatios(const Unit& u)
{ {
return m_ratioMaps[u]; return m_ratioMaps[u];

View File

@ -286,7 +286,7 @@ namespace CalculatorUnitTests
VM::UnitConverterViewModel^ vm = ref new UnitConverterViewModel(make_shared<UnitConversionManager::UnitConverter>(make_shared<UnitConverterDataLoader>(ref new GeographicRegion()), nullptr)); VM::UnitConverterViewModel^ vm = ref new UnitConverterViewModel(make_shared<UnitConversionManager::UnitConverter>(make_shared<UnitConverterDataLoader>(ref new GeographicRegion()), nullptr));
IObservableVector<Category^>^ categoryList = vm->Categories; IObservableVector<Category^>^ categoryList = vm->Categories;
ResourceLoader^ m_resLoader = ResourceLoader::GetForViewIndependentUse("Test"); ResourceLoader^ m_resLoader = ResourceLoader::GetForViewIndependentUse("Test");
double epsilon = 0.1; //Could be more precise like 0.001 except atm to pascal conversion double epsilon = 0.1; // Could be more precise like 0.001 except atm to pascal conversion
for (unsigned int k = 0; k < categoryList->Size; k++) for (unsigned int k = 0; k < categoryList->Size; k++)
{ {
@ -302,7 +302,7 @@ namespace CalculatorUnitTests
vm->Value1Active = false; vm->Value1Active = false;
vm->Unit2 = unitList->GetAt(j); vm->Unit2 = unitList->GetAt(j);
wstring unit2Name = vm->Unit2->Name->Data(); wstring unit2Name = vm->Unit2->Name->Data();
//change value2 as 1. // Change value2 as 1.
vm->ButtonPressed->Execute(NumbersAndOperatorsEnum::One); vm->ButtonPressed->Execute(NumbersAndOperatorsEnum::One);
String^ expectedResult = m_resLoader->GetString(ref new String((unit1Name + L"-" + unit2Name).c_str())); String^ expectedResult = m_resLoader->GetString(ref new String((unit1Name + L"-" + unit2Name).c_str()));
@ -315,10 +315,10 @@ namespace CalculatorUnitTests
double actualConversion = GetDoubleFromWstring(GetStringValue(vm->Value1)->Data()); double actualConversion = GetDoubleFromWstring(GetStringValue(vm->Value1)->Data());
double diff = abs(expectedConversion - actualConversion); double diff = abs(expectedConversion - actualConversion);
// assert for diff less than epsilonth fraction of expected conversion result // Assert for diff less than epsilonth fraction of expected conversion result
VERIFY_IS_LESS_THAN_OR_EQUAL(diff, epsilon*expectedConversion); VERIFY_IS_LESS_THAN_OR_EQUAL(diff, epsilon*expectedConversion);
} }
//clearing the value1 // Clearing the value1
vm->ButtonPressed->Execute(NumbersAndOperatorsEnum::Clear); vm->ButtonPressed->Execute(NumbersAndOperatorsEnum::Clear);
} }
} }
@ -356,7 +356,7 @@ namespace CalculatorUnitTests
VERIFY_ARE_EQUAL((UINT)1, mock->m_setVMCallbackCallCount); VERIFY_ARE_EQUAL((UINT)1, mock->m_setVMCallbackCallCount);
} }
// Test that we've set up all categories on load and that the first // Test that we've set up all categories on load and that the first
// category is selected. // category is selected.
TEST_METHOD(TestUnitConverterLoadSetsUpCategories) TEST_METHOD(TestUnitConverterLoadSetsUpCategories)
{ {
@ -393,7 +393,7 @@ namespace CalculatorUnitTests
shared_ptr<UnitConverterMock> mock = make_shared<UnitConverterMock>(); shared_ptr<UnitConverterMock> mock = make_shared<UnitConverterMock>();
VM::UnitConverterViewModel vm(mock); VM::UnitConverterViewModel vm(mock);
vm.Unit1 = vm.Units->GetAt(1); // Change from u4 to u5 vm.Unit1 = vm.Units->GetAt(1); // Change from u4 to u5
// count will be 2 here since it was already called once at init // Count will be 2 here since it was already called once at init
VERIFY_ARE_EQUAL((UINT)2, mock->m_setCurUnitTypesCallCount); VERIFY_ARE_EQUAL((UINT)2, mock->m_setCurUnitTypesCallCount);
VERIFY_IS_TRUE(UNIT5 == mock->m_curFrom); VERIFY_IS_TRUE(UNIT5 == mock->m_curFrom);
VERIFY_IS_TRUE(UNIT6 == mock->m_curTo); VERIFY_IS_TRUE(UNIT6 == mock->m_curTo);
@ -409,7 +409,7 @@ namespace CalculatorUnitTests
shared_ptr<UnitConverterMock> mock = make_shared<UnitConverterMock>(); shared_ptr<UnitConverterMock> mock = make_shared<UnitConverterMock>();
VM::UnitConverterViewModel vm(mock); VM::UnitConverterViewModel vm(mock);
vm.CurrentCategory = vm.Categories->GetAt(2); // Change from cat1 to cat3 vm.CurrentCategory = vm.Categories->GetAt(2); // Change from cat1 to cat3
// counts will be 2 here since the first call should have happened during init // Counts will be 2 here since the first call should have happened during init
VERIFY_IS_GREATER_THAN_OR_EQUAL(2u, mock->m_setCurrentCategoryCallCount); VERIFY_IS_GREATER_THAN_OR_EQUAL(2u, mock->m_setCurrentCategoryCallCount);
VERIFY_ARE_EQUAL((UINT)3, vm.Units->Size); VERIFY_ARE_EQUAL((UINT)3, vm.Units->Size);
VERIFY_IS_TRUE(UNIT7 == vm.Units->GetAt(0)->GetModelUnit()); VERIFY_IS_TRUE(UNIT7 == vm.Units->GetAt(0)->GetModelUnit());
@ -424,7 +424,7 @@ namespace CalculatorUnitTests
shared_ptr<UnitConverterMock> mock = make_shared<UnitConverterMock>(); shared_ptr<UnitConverterMock> mock = make_shared<UnitConverterMock>();
VM::UnitConverterViewModel vm(mock); VM::UnitConverterViewModel vm(mock);
vm.CurrentCategory = vm.Categories->GetAt(2); // Change from cat1 to cat3 vm.CurrentCategory = vm.Categories->GetAt(2); // Change from cat1 to cat3
// counts will be 2 here since the first call should have happened during init // Counts will be 2 here since the first call should have happened during init
VERIFY_IS_GREATER_THAN_OR_EQUAL(2u, mock->m_setCurrentCategoryCallCount); VERIFY_IS_GREATER_THAN_OR_EQUAL(2u, mock->m_setCurrentCategoryCallCount);
VERIFY_IS_TRUE(UNIT9 == vm.Unit1->GetModelUnit()); VERIFY_IS_TRUE(UNIT9 == vm.Unit1->GetModelUnit());
VERIFY_IS_TRUE(UNIT7 == vm.Unit2->GetModelUnit()); VERIFY_IS_TRUE(UNIT7 == vm.Unit2->GetModelUnit());
@ -451,7 +451,7 @@ namespace CalculatorUnitTests
shared_ptr<UnitConverterMock> mock = make_shared<UnitConverterMock>(); shared_ptr<UnitConverterMock> mock = make_shared<UnitConverterMock>();
VM::UnitConverterViewModel vm(mock); VM::UnitConverterViewModel vm(mock);
// Call count is being set to 1 because we send 'CE' command as the first call // Call count is being set to 1 because we send 'CE' command as the first call
UINT callCount = 1; UINT callCount = 1;
vm.ButtonPressed->Execute(CalculatorApp::NumbersAndOperatorsEnum::Zero); vm.ButtonPressed->Execute(CalculatorApp::NumbersAndOperatorsEnum::Zero);
@ -1045,7 +1045,7 @@ namespace CalculatorUnitTests
VERIFY_ARE_EQUAL((UCM::EMPTY_UNIT).id, (vm.Units->GetAt(0)->GetModelUnit()).id); VERIFY_ARE_EQUAL((UCM::EMPTY_UNIT).id, (vm.Units->GetAt(0)->GetModelUnit()).id);
} }
// Test that a valid model unit list vuilds // Test that a valid model unit list vuilds
TEST_METHOD(TestUnitsListBuildsFromValidModelUnitList) TEST_METHOD(TestUnitsListBuildsFromValidModelUnitList)
{ {
shared_ptr<UnitConverterMock> mock = make_shared<UnitConverterMock>(); shared_ptr<UnitConverterMock> mock = make_shared<UnitConverterMock>();

View File

@ -76,7 +76,7 @@ void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEvent
// Place the frame in the current Window // Place the frame in the current Window
Window::Current->Content = rootFrame; Window::Current->Content = rootFrame;
} }
Microsoft::VisualStudio::TestPlatform::TestExecutor::WinRTCore::UnitTestClient::CreateDefaultUI(); Microsoft::VisualStudio::TestPlatform::TestExecutor::WinRTCore::UnitTestClient::CreateDefaultUI();
Window::Current->Activate(); Window::Current->Activate();
@ -96,7 +96,7 @@ void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e)
(void) sender; // Unused parameter (void) sender; // Unused parameter
(void) e; // Unused parameter (void) e; // Unused parameter
//TODO: Save application state and stop any background activity // TODO: Save application state and stop any background activity
} }
/// <summary> /// <summary>

View File

@ -73,7 +73,7 @@ namespace StandardPeers = Windows::UI::Xaml::Automation::Peers;
namespace CalculatorApp::Common::Automation {} namespace CalculatorApp::Common::Automation {}
namespace CustomPeers = CalculatorApp::Common::Automation; namespace CustomPeers = CalculatorApp::Common::Automation;
//CalcManager Headers // CalcManager Headers
#include "CalcManager/CalculatorVector.h" #include "CalcManager/CalculatorVector.h"
#include "CalcManager/ExpressionCommand.h" #include "CalcManager/ExpressionCommand.h"
#include "CalcManager/CalculatorResource.h" #include "CalcManager/CalculatorResource.h"

View File

@ -3,7 +3,7 @@
// Used by CalculatorUnitTests_VS.rc // Used by CalculatorUnitTests_VS.rc
// Next default values for new objects // Next default values for new objects
// //
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101 #define _APS_NEXT_RESOURCE_VALUE 101