Update Calc Engine for new functions needed for keyboard refresh (#662)
* Update Calc Engine to Support New Functionality * Address PR comments * Address PR comments
This commit is contained in:
@@ -81,6 +81,7 @@
|
||||
#define IDC_ROL 99
|
||||
#define IDC_ROR 100
|
||||
#define IDC_COM 101
|
||||
|
||||
#define IDC_SIN 102
|
||||
#define IDC_COS 103
|
||||
#define IDC_TAN 104
|
||||
@@ -136,7 +137,44 @@
|
||||
#define IDC_INV 146
|
||||
#define IDC_SET_RESULT 147
|
||||
|
||||
#define IDC_LASTCONTROL IDC_SET_RESULT
|
||||
#define IDC_STRING_MAPPED_VALUES 400
|
||||
#define IDC_UNARYEXTENDEDFIRST IDC_STRING_MAPPED_VALUES
|
||||
#define IDC_SEC 400 // Secant
|
||||
// 401 reserved for inverse
|
||||
#define IDC_CSC 402 // Cosecant
|
||||
// 403 reserved for inverse
|
||||
#define IDC_COT 404 // Cotangent
|
||||
// 405 reserved for inverse
|
||||
|
||||
#define IDC_SECH 406 //Hyperbolic Secant
|
||||
// 407 reserved for inverse
|
||||
#define IDC_CSCH 408 //Hyperbolic Cosecant
|
||||
// 409 reserved for inverse
|
||||
#define IDC_COTH 410 //Hyperbolic Cotangent
|
||||
// 411 reserved for inverse
|
||||
|
||||
#define IDC_POW2 412 // 2 ^ x
|
||||
#define IDC_ABS 413 // Absolute Value
|
||||
#define IDC_FLOOR 414 // Floor
|
||||
#define IDC_CEIL 415 // Ceiling
|
||||
|
||||
#define IDC_ROLC 416 // Rotate Left Circular
|
||||
#define IDC_RORC 417 // Rotate Right Circular
|
||||
|
||||
#define IDC_UNARYEXTENDEDLAST IDC_RORC
|
||||
|
||||
#define IDC_LASTCONTROL IDC_CEIL
|
||||
|
||||
#define IDC_BINARYEXTENDEDFIRST 500
|
||||
#define IDC_LOGBASEX 500 // logx(y)
|
||||
#define IDC_NAND 501 // Nand
|
||||
#define IDC_NOR 502 // Nor
|
||||
|
||||
#define IDC_RSHFL 505 //Right Shift Logical
|
||||
#define IDC_BINARYEXTENDEDLAST IDC_RSHFL
|
||||
|
||||
#define IDC_RAND 600 // Random
|
||||
#define IDC_EULER 601 // e Constant
|
||||
|
||||
#define IDC_BINEDITSTART 700
|
||||
#define IDC_BINPOS0 700
|
||||
|
@@ -14,6 +14,7 @@
|
||||
*
|
||||
\****************************************************************************/
|
||||
|
||||
#include <random>
|
||||
#include "CCommand.h"
|
||||
#include "EngineStrings.h"
|
||||
#include "../Command.h"
|
||||
@@ -68,6 +69,10 @@ public:
|
||||
{
|
||||
return m_bError;
|
||||
}
|
||||
bool IsInputEmpty()
|
||||
{
|
||||
return m_input.IsEmpty() && (m_numberString.empty() || m_numberString == L"0");
|
||||
}
|
||||
bool FInRecordingState()
|
||||
{
|
||||
return m_bRecord;
|
||||
@@ -103,6 +108,7 @@ public:
|
||||
return GetString(IdStrFromCmdId(nOpCode));
|
||||
}
|
||||
static std::wstring_view OpCodeToUnaryString(int nOpCode, bool fInv, ANGLE_TYPE angletype);
|
||||
static std::wstring_view OpCodeToBinaryString(int nOpCode, bool isIntegerMode);
|
||||
|
||||
private:
|
||||
bool m_fPrecedence;
|
||||
@@ -147,6 +153,11 @@ private:
|
||||
NUM_WIDTH m_numwidth; // one of qword, dword, word or byte mode.
|
||||
int32_t m_dwWordBitWidth; // # of bits in currently selected word size
|
||||
|
||||
std::unique_ptr<std::mt19937> m_randomGeneratorEngine;
|
||||
std::unique_ptr<std::uniform_real_distribution<>> m_distr;
|
||||
|
||||
uint64_t m_carryBit;
|
||||
|
||||
CHistoryCollector m_HistoryCollector; // Accumulator of each line of history as various commands are processed
|
||||
|
||||
std::array<CalcEngine::Rational, NUM_WIDTH_LENGTH> m_chopNumbers; // word size enforcement
|
||||
@@ -171,6 +182,7 @@ private:
|
||||
void SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwidth);
|
||||
int32_t DwWordBitWidthFromeNumWidth(NUM_WIDTH numwidth);
|
||||
uint32_t NRadixFromRadixType(RADIX_TYPE radixtype);
|
||||
double GenerateRandomNumber();
|
||||
|
||||
bool TryToggleBit(CalcEngine::Rational& rat, uint32_t wbitno);
|
||||
void CheckAndAddLastBinOpToHistory(bool addToHistory = true);
|
||||
|
@@ -66,6 +66,7 @@ namespace CalcEngine
|
||||
bool TryBeginExponent();
|
||||
void Backspace();
|
||||
void SetDecimalSymbol(wchar_t decSymbol);
|
||||
bool IsEmpty();
|
||||
std::wstring ToString(uint32_t radix);
|
||||
Rational ToRational(uint32_t radix, int32_t precision);
|
||||
|
||||
|
@@ -87,7 +87,6 @@ inline constexpr auto SIDS_XPOW3 = L"32";
|
||||
inline constexpr auto SIDS_NFACTORIAL = L"33";
|
||||
inline constexpr auto SIDS_RECIPROCAL = L"34";
|
||||
inline constexpr auto SIDS_DMS = L"35";
|
||||
inline constexpr auto SIDS_CUBEROOT = L"36";
|
||||
inline constexpr auto SIDS_POWTEN = L"37";
|
||||
inline constexpr auto SIDS_PERCENT = L"38";
|
||||
inline constexpr auto SIDS_SCIENTIFIC_NOTATION = L"39";
|
||||
@@ -172,125 +171,193 @@ inline constexpr auto SIDS_ERR_UNEX_END = L"117";
|
||||
inline constexpr auto SIDS_ERR_SG_INV_ERROR = L"118";
|
||||
inline constexpr auto SIDS_ERR_INPUT_OVERFLOW = L"119";
|
||||
inline constexpr auto SIDS_ERR_OUTPUT_OVERFLOW = L"120";
|
||||
inline constexpr auto SIDS_SECD = L"SecDeg";
|
||||
inline constexpr auto SIDS_SECR = L"SecRad";
|
||||
inline constexpr auto SIDS_SECG = L"SecGrad";
|
||||
inline constexpr auto SIDS_ASECD = L"InverseSecDeg";
|
||||
inline constexpr auto SIDS_ASECR = L"InverseSecRad";
|
||||
inline constexpr auto SIDS_ASECG = L"InverseSecGrad";
|
||||
inline constexpr auto SIDS_CSCD = L"CscDeg";
|
||||
inline constexpr auto SIDS_CSCR = L"CscRad";
|
||||
inline constexpr auto SIDS_CSCG = L"CscGrad";
|
||||
inline constexpr auto SIDS_ACSCD = L"InverseCscDeg";
|
||||
inline constexpr auto SIDS_ACSCR = L"InverseCscRad";
|
||||
inline constexpr auto SIDS_ACSCG = L"InverseCscGrad";
|
||||
inline constexpr auto SIDS_COTD = L"CotDeg";
|
||||
inline constexpr auto SIDS_COTR = L"CotRad";
|
||||
inline constexpr auto SIDS_COTG = L"CotGrad";
|
||||
inline constexpr auto SIDS_ACOTD = L"InverseCotDeg";
|
||||
inline constexpr auto SIDS_ACOTR = L"InverseCotRad";
|
||||
inline constexpr auto SIDS_ACOTG = L"InverseCotGrad";
|
||||
inline constexpr auto SIDS_SECH = L"Sech";
|
||||
inline constexpr auto SIDS_ASECH = L"InverseSech";
|
||||
inline constexpr auto SIDS_CSCH = L"Csch";
|
||||
inline constexpr auto SIDS_ACSCH = L"InverseCsch";
|
||||
inline constexpr auto SIDS_COTH = L"Coth";
|
||||
inline constexpr auto SIDS_ACOTH = L"InverseCoth";
|
||||
inline constexpr auto SIDS_TWOPOWX = L"TwoPowX";
|
||||
inline constexpr auto SIDS_LOGBASEX = L"LogBaseX";
|
||||
inline constexpr auto SIDS_ABS = L"Abs";
|
||||
inline constexpr auto SIDS_FLOOR = L"Floor";
|
||||
inline constexpr auto SIDS_CEIL = L"Ceil";
|
||||
inline constexpr auto SIDS_NAND = L"Nand";
|
||||
inline constexpr auto SIDS_NOR = L"Nor";
|
||||
inline constexpr auto SIDS_CUBEROOT = L"CubeRoot";
|
||||
inline constexpr auto SIDS_PROGRAMMER_MOD = L"ProgrammerMod";
|
||||
|
||||
// Include the resource key ID from above into this vector to load it into memory for the engine to use
|
||||
inline constexpr std::array<std::wstring_view, 120> g_sids = { SIDS_PLUS_MINUS,
|
||||
SIDS_C,
|
||||
SIDS_CE,
|
||||
SIDS_BACKSPACE,
|
||||
SIDS_DECIMAL_SEPARATOR,
|
||||
SIDS_EMPTY_STRING,
|
||||
SIDS_AND,
|
||||
SIDS_OR,
|
||||
SIDS_XOR,
|
||||
SIDS_LSH,
|
||||
SIDS_RSH,
|
||||
SIDS_DIVIDE,
|
||||
SIDS_MULTIPLY,
|
||||
SIDS_PLUS,
|
||||
SIDS_MINUS,
|
||||
SIDS_MOD,
|
||||
SIDS_YROOT,
|
||||
SIDS_POW_HAT,
|
||||
SIDS_INT,
|
||||
SIDS_ROL,
|
||||
SIDS_ROR,
|
||||
SIDS_NOT,
|
||||
SIDS_SIN,
|
||||
SIDS_COS,
|
||||
SIDS_TAN,
|
||||
SIDS_SINH,
|
||||
SIDS_COSH,
|
||||
SIDS_TANH,
|
||||
SIDS_LN,
|
||||
SIDS_LOG,
|
||||
SIDS_SQRT,
|
||||
SIDS_XPOW2,
|
||||
SIDS_XPOW3,
|
||||
SIDS_NFACTORIAL,
|
||||
SIDS_RECIPROCAL,
|
||||
SIDS_DMS,
|
||||
SIDS_CUBEROOT,
|
||||
SIDS_POWTEN,
|
||||
SIDS_PERCENT,
|
||||
SIDS_SCIENTIFIC_NOTATION,
|
||||
SIDS_PI,
|
||||
SIDS_EQUAL,
|
||||
SIDS_MC,
|
||||
SIDS_MR,
|
||||
SIDS_MS,
|
||||
SIDS_MPLUS,
|
||||
SIDS_MMINUS,
|
||||
SIDS_EXP,
|
||||
SIDS_OPEN_PAREN,
|
||||
SIDS_CLOSE_PAREN,
|
||||
SIDS_0,
|
||||
SIDS_1,
|
||||
SIDS_2,
|
||||
SIDS_3,
|
||||
SIDS_4,
|
||||
SIDS_5,
|
||||
SIDS_6,
|
||||
SIDS_7,
|
||||
SIDS_8,
|
||||
SIDS_9,
|
||||
SIDS_A,
|
||||
SIDS_B,
|
||||
SIDS_C,
|
||||
SIDS_D,
|
||||
SIDS_E,
|
||||
SIDS_F,
|
||||
SIDS_FRAC,
|
||||
SIDS_SIND,
|
||||
SIDS_COSD,
|
||||
SIDS_TAND,
|
||||
SIDS_ASIND,
|
||||
SIDS_ACOSD,
|
||||
SIDS_ATAND,
|
||||
SIDS_SINR,
|
||||
SIDS_COSR,
|
||||
SIDS_TANR,
|
||||
SIDS_ASINR,
|
||||
SIDS_ACOSR,
|
||||
SIDS_ATANR,
|
||||
SIDS_SING,
|
||||
SIDS_COSG,
|
||||
SIDS_TANG,
|
||||
SIDS_ASING,
|
||||
SIDS_ACOSG,
|
||||
SIDS_ATANG,
|
||||
SIDS_ASINH,
|
||||
SIDS_ACOSH,
|
||||
SIDS_ATANH,
|
||||
SIDS_POWE,
|
||||
SIDS_POWTEN2,
|
||||
SIDS_SQRT2,
|
||||
SIDS_SQR,
|
||||
SIDS_CUBE,
|
||||
SIDS_CUBERT,
|
||||
SIDS_FACT,
|
||||
SIDS_RECIPROC,
|
||||
SIDS_DEGREES,
|
||||
SIDS_NEGATE,
|
||||
SIDS_RSH,
|
||||
SIDS_DIVIDEBYZERO,
|
||||
SIDS_DOMAIN,
|
||||
SIDS_UNDEFINED,
|
||||
SIDS_POS_INFINITY,
|
||||
SIDS_NEG_INFINITY,
|
||||
SIDS_ABORTED,
|
||||
SIDS_NOMEM,
|
||||
SIDS_TOOMANY,
|
||||
SIDS_OVERFLOW,
|
||||
SIDS_NORESULT,
|
||||
SIDS_INSUFFICIENT_DATA,
|
||||
SIDS_ERR_UNK_CH,
|
||||
SIDS_ERR_UNK_FN,
|
||||
SIDS_ERR_UNEX_NUM,
|
||||
SIDS_ERR_UNEX_CH,
|
||||
SIDS_ERR_UNEX_SZ,
|
||||
SIDS_ERR_MISMATCH_CLOSE,
|
||||
SIDS_ERR_UNEX_END,
|
||||
SIDS_ERR_SG_INV_ERROR,
|
||||
SIDS_ERR_INPUT_OVERFLOW,
|
||||
SIDS_ERR_OUTPUT_OVERFLOW };
|
||||
inline constexpr std::array<std::wstring_view, 152> g_sids =
|
||||
{
|
||||
SIDS_PLUS_MINUS,
|
||||
SIDS_C,
|
||||
SIDS_CE,
|
||||
SIDS_BACKSPACE,
|
||||
SIDS_DECIMAL_SEPARATOR,
|
||||
SIDS_EMPTY_STRING,
|
||||
SIDS_AND,
|
||||
SIDS_OR,
|
||||
SIDS_XOR,
|
||||
SIDS_LSH,
|
||||
SIDS_RSH,
|
||||
SIDS_DIVIDE,
|
||||
SIDS_MULTIPLY,
|
||||
SIDS_PLUS,
|
||||
SIDS_MINUS,
|
||||
SIDS_MOD,
|
||||
SIDS_YROOT,
|
||||
SIDS_POW_HAT,
|
||||
SIDS_INT,
|
||||
SIDS_ROL,
|
||||
SIDS_ROR,
|
||||
SIDS_NOT,
|
||||
SIDS_SIN,
|
||||
SIDS_COS,
|
||||
SIDS_TAN,
|
||||
SIDS_SINH,
|
||||
SIDS_COSH,
|
||||
SIDS_TANH,
|
||||
SIDS_LN,
|
||||
SIDS_LOG,
|
||||
SIDS_SQRT,
|
||||
SIDS_XPOW2,
|
||||
SIDS_XPOW3,
|
||||
SIDS_NFACTORIAL,
|
||||
SIDS_RECIPROCAL,
|
||||
SIDS_DMS,
|
||||
SIDS_POWTEN,
|
||||
SIDS_PERCENT,
|
||||
SIDS_SCIENTIFIC_NOTATION,
|
||||
SIDS_PI,
|
||||
SIDS_EQUAL,
|
||||
SIDS_MC,
|
||||
SIDS_MR,
|
||||
SIDS_MS,
|
||||
SIDS_MPLUS,
|
||||
SIDS_MMINUS,
|
||||
SIDS_EXP,
|
||||
SIDS_OPEN_PAREN,
|
||||
SIDS_CLOSE_PAREN,
|
||||
SIDS_0,
|
||||
SIDS_1,
|
||||
SIDS_2,
|
||||
SIDS_3,
|
||||
SIDS_4,
|
||||
SIDS_5,
|
||||
SIDS_6,
|
||||
SIDS_7,
|
||||
SIDS_8,
|
||||
SIDS_9,
|
||||
SIDS_A,
|
||||
SIDS_B,
|
||||
SIDS_C,
|
||||
SIDS_D,
|
||||
SIDS_E,
|
||||
SIDS_F,
|
||||
SIDS_FRAC,
|
||||
SIDS_SIND,
|
||||
SIDS_COSD,
|
||||
SIDS_TAND,
|
||||
SIDS_ASIND,
|
||||
SIDS_ACOSD,
|
||||
SIDS_ATAND,
|
||||
SIDS_SINR,
|
||||
SIDS_COSR,
|
||||
SIDS_TANR,
|
||||
SIDS_ASINR,
|
||||
SIDS_ACOSR,
|
||||
SIDS_ATANR,
|
||||
SIDS_SING,
|
||||
SIDS_COSG,
|
||||
SIDS_TANG,
|
||||
SIDS_ASING,
|
||||
SIDS_ACOSG,
|
||||
SIDS_ATANG,
|
||||
SIDS_ASINH,
|
||||
SIDS_ACOSH,
|
||||
SIDS_ATANH,
|
||||
SIDS_POWE,
|
||||
SIDS_POWTEN2,
|
||||
SIDS_SQRT2,
|
||||
SIDS_SQR,
|
||||
SIDS_CUBE,
|
||||
SIDS_CUBERT,
|
||||
SIDS_FACT,
|
||||
SIDS_RECIPROC,
|
||||
SIDS_DEGREES,
|
||||
SIDS_NEGATE,
|
||||
SIDS_RSH,
|
||||
SIDS_DIVIDEBYZERO,
|
||||
SIDS_DOMAIN,
|
||||
SIDS_UNDEFINED,
|
||||
SIDS_POS_INFINITY,
|
||||
SIDS_NEG_INFINITY,
|
||||
SIDS_ABORTED,
|
||||
SIDS_NOMEM,
|
||||
SIDS_TOOMANY,
|
||||
SIDS_OVERFLOW,
|
||||
SIDS_NORESULT,
|
||||
SIDS_INSUFFICIENT_DATA,
|
||||
SIDS_ERR_UNK_CH,
|
||||
SIDS_ERR_UNK_FN,
|
||||
SIDS_ERR_UNEX_NUM,
|
||||
SIDS_ERR_UNEX_CH,
|
||||
SIDS_ERR_UNEX_SZ,
|
||||
SIDS_ERR_MISMATCH_CLOSE,
|
||||
SIDS_ERR_UNEX_END,
|
||||
SIDS_ERR_SG_INV_ERROR,
|
||||
SIDS_ERR_INPUT_OVERFLOW,
|
||||
SIDS_ERR_OUTPUT_OVERFLOW,
|
||||
SIDS_SECD,
|
||||
SIDS_SECG,
|
||||
SIDS_SECR,
|
||||
SIDS_ASECD,
|
||||
SIDS_ASECR,
|
||||
SIDS_ASECG,
|
||||
SIDS_CSCD,
|
||||
SIDS_CSCR,
|
||||
SIDS_CSCG,
|
||||
SIDS_ACSCD,
|
||||
SIDS_ACSCR,
|
||||
SIDS_ACSCG,
|
||||
SIDS_COTD,
|
||||
SIDS_COTR,
|
||||
SIDS_COTG,
|
||||
SIDS_ACOTD,
|
||||
SIDS_ACOTR,
|
||||
SIDS_ACOTG,
|
||||
SIDS_SECH,
|
||||
SIDS_ASECH,
|
||||
SIDS_CSCH,
|
||||
SIDS_ACSCH,
|
||||
SIDS_COTH,
|
||||
SIDS_ACOTH,
|
||||
SIDS_TWOPOWX,
|
||||
SIDS_LOGBASEX,
|
||||
SIDS_ABS,
|
||||
SIDS_FLOOR,
|
||||
SIDS_CEIL,
|
||||
SIDS_NAND,
|
||||
SIDS_NOR,
|
||||
SIDS_CUBEROOT,
|
||||
SIDS_PROGRAMMER_MOD,
|
||||
};
|
||||
|
@@ -21,8 +21,8 @@ public:
|
||||
~CHistoryCollector();
|
||||
void AddOpndToHistory(std::wstring_view numStr, CalcEngine::Rational const& rat, bool fRepetition = false);
|
||||
void RemoveLastOpndFromHistory();
|
||||
void AddBinOpToHistory(int nOpCode, bool fNoRepetition = true);
|
||||
void ChangeLastBinOp(int nOpCode, bool fPrecInvToHigher);
|
||||
void AddBinOpToHistory(int nOpCode, bool isIntgerMode, bool fNoRepetition = true);
|
||||
void ChangeLastBinOp(int nOpCode, bool fPrecInvToHigher, bool isIntgerMode);
|
||||
void AddUnaryOpToHistory(int nOpCode, bool fInv, ANGLE_TYPE angletype);
|
||||
void AddOpenBraceToHistory();
|
||||
void AddCloseBraceToHistory();
|
||||
|
@@ -22,4 +22,5 @@ public:
|
||||
virtual void OnHistoryItemAdded(_In_ unsigned int addedItemIndex) = 0;
|
||||
virtual void SetMemorizedNumbers(const std::vector<std::wstring>& memorizedNumbers) = 0;
|
||||
virtual void MemoryItemChanged(unsigned int indexOfMemory) = 0;
|
||||
virtual void InputChanged() = 0;
|
||||
};
|
||||
|
Reference in New Issue
Block a user