Add Auto-E switch and fix standard mode

This commit is contained in:
uhliksk 2019-03-07 12:48:26 +01:00
commit 92e735d757
23 changed files with 112 additions and 21 deletions

View file

@ -44,6 +44,7 @@ bool IsGuiSettingOpCode(WPARAM opCode)
{ {
case IDC_INV: case IDC_INV:
case IDC_FE: case IDC_FE:
case IDC_AE:
case IDC_MCLEAR: case IDC_MCLEAR:
case IDC_BACK: case IDC_BACK:
case IDC_EXP: case IDC_EXP:

View file

@ -444,14 +444,14 @@ namespace CalcEngine
return !(lhs < rhs); return !(lhs < rhs);
} }
wstring Rational::ToString(uint32_t radix, NUMOBJ_FMT fmt, int32_t precision) const wstring Rational::ToString(uint32_t radix, NUMOBJ_FMT fmt, NUMOBJ_AUTOFMT afmt, int32_t precision) const
{ {
PRAT rat = this->ToPRAT(); PRAT rat = this->ToPRAT();
wstring result{}; wstring result{};
try try
{ {
result = RatToString(rat, fmt, radix, precision); result = RatToString(rat, fmt, afmt, radix, precision);
} }
catch (DWORD error) catch (DWORD error)
{ {

View file

@ -75,6 +75,7 @@ CCalcEngine::CCalcEngine(bool fPrecedence, bool fIntegerMode, CalculationManager
m_bError(false), m_bError(false),
m_bInv(false), m_bInv(false),
m_nFE(FMT_FLOAT), m_nFE(FMT_FLOAT),
m_nAE(AUTOFMT_DISABLED),
m_bNoPrevEqu(true), m_bNoPrevEqu(true),
m_numwidth(QWORD_WIDTH), m_numwidth(QWORD_WIDTH),
m_angletype(ANGLE_DEG), m_angletype(ANGLE_DEG),
@ -120,7 +121,7 @@ void CCalcEngine::InitChopNumbers()
auto maxVal = m_chopNumbers[i] / 2; auto maxVal = m_chopNumbers[i] / 2;
maxVal = RationalMath::Integer(maxVal); maxVal = RationalMath::Integer(maxVal);
m_maxDecimalValueStrings[i] = maxVal.ToString(10, FMT_FLOAT, m_precision); m_maxDecimalValueStrings[i] = maxVal.ToString(10, FMT_FLOAT, AUTOFMT_ENABLED, m_precision);
} }
} }

View file

@ -757,6 +757,12 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
DisplayNum(); DisplayNum();
break; break;
case IDC_AE:
// Toggle automatic exponential notation display.
m_nAE = NUMOBJ_AUTOFMT(!(int)m_nAE);
DisplayNum();
break;
case IDC_EXP: case IDC_EXP:
if (m_bRecord && !m_fIntegerMode && m_input.TryBeginExponent()) if (m_bRecord && !m_fIntegerMode && m_input.TryBeginExponent())
{ {
@ -1033,7 +1039,7 @@ wstring CCalcEngine::GetStringForDisplay(Rational const& rat, uint32_t radix)
// Check for standard\scientific mode // Check for standard\scientific mode
if (!m_fIntegerMode) if (!m_fIntegerMode)
{ {
result = rat.ToString(radix, m_nFE, m_precision); result = rat.ToString(radix, m_nFE, m_nAE, m_precision);
} }
else else
{ {
@ -1051,7 +1057,7 @@ wstring CCalcEngine::GetStringForDisplay(Rational const& rat, uint32_t radix)
tempRat = -((tempRat ^ m_chopNumbers[m_numwidth]) + 1); tempRat = -((tempRat ^ m_chopNumbers[m_numwidth]) + 1);
} }
result = tempRat.ToString(radix, m_nFE, m_precision); result = tempRat.ToString(radix, m_nFE, m_nAE, m_precision);
} }
catch (DWORD) catch (DWORD)
{ {

View file

@ -40,13 +40,14 @@ typedef struct {
int32_t precision; int32_t precision;
uint32_t radix; uint32_t radix;
INT nFE; INT nFE;
INT nAE;
NUM_WIDTH numwidth; NUM_WIDTH numwidth;
bool fIntMath; bool fIntMath;
bool bRecord; bool bRecord;
bool bUseSep; bool bUseSep;
} LASTDISP; } LASTDISP;
LASTDISP gldPrevious = { 0, -1, 0, -1, (NUM_WIDTH)-1, false, false, false }; LASTDISP gldPrevious = { 0, -1, 0, -1, -1, (NUM_WIDTH)-1, false, false, false };
// Truncates if too big, makes it a non negative - the number in rat. Doesn't do anything if not in INT mode // Truncates if too big, makes it a non negative - the number in rat. Doesn't do anything if not in INT mode
CalcEngine::Rational CCalcEngine::TruncateNumForIntMath(CalcEngine::Rational const& rat) CalcEngine::Rational CCalcEngine::TruncateNumForIntMath(CalcEngine::Rational const& rat)
@ -87,6 +88,7 @@ void CCalcEngine::DisplayNum(void)
gldPrevious.precision != m_precision || gldPrevious.precision != m_precision ||
gldPrevious.radix != m_radix || gldPrevious.radix != m_radix ||
gldPrevious.nFE != (int)m_nFE || gldPrevious.nFE != (int)m_nFE ||
gldPrevious.nAE != (int)m_nAE ||
gldPrevious.bUseSep != true || gldPrevious.bUseSep != true ||
gldPrevious.numwidth != m_numwidth || gldPrevious.numwidth != m_numwidth ||
gldPrevious.fIntMath != m_fIntegerMode || gldPrevious.fIntMath != m_fIntegerMode ||
@ -95,6 +97,7 @@ void CCalcEngine::DisplayNum(void)
gldPrevious.precision = m_precision; gldPrevious.precision = m_precision;
gldPrevious.radix = m_radix; gldPrevious.radix = m_radix;
gldPrevious.nFE = (int)m_nFE; gldPrevious.nFE = (int)m_nFE;
gldPrevious.nAE = (int)m_nAE;
gldPrevious.numwidth = m_numwidth; gldPrevious.numwidth = m_numwidth;
gldPrevious.fIntMath = m_fIntegerMode; gldPrevious.fIntMath = m_fIntegerMode;

View file

@ -28,6 +28,7 @@ namespace CalculationManager
m_currentDegreeMode(Command::CommandNULL), m_currentDegreeMode(Command::CommandNULL),
m_savedDegreeMode(Command::CommandDEG), m_savedDegreeMode(Command::CommandDEG),
m_isExponentialFormat(false), m_isExponentialFormat(false),
m_isAutoExponentialFormat(true),
m_persistedPrimaryValue(), m_persistedPrimaryValue(),
m_currentCalculatorEngine(nullptr), m_currentCalculatorEngine(nullptr),
m_pStdHistory(new CalculatorHistory(CM_STD, MAX_HISTORY_ITEMS)), m_pStdHistory(new CalculatorHistory(CM_STD, MAX_HISTORY_ITEMS)),
@ -139,6 +140,11 @@ namespace CalculationManager
m_isExponentialFormat = false; m_isExponentialFormat = false;
m_scientificCalculatorEngine->ProcessCommand(IDC_FE); m_scientificCalculatorEngine->ProcessCommand(IDC_FE);
} }
if (!m_isAutoExponentialFormat)
{
m_isAutoExponentialFormat = true;
m_scientificCalculatorEngine->ProcessCommand(IDC_AE);
}
} }
if (m_programmerCalculatorEngine) if (m_programmerCalculatorEngine)
{ {
@ -248,7 +254,7 @@ namespace CalculationManager
m_currentDegreeMode = command; m_currentDegreeMode = command;
} }
if (command != Command::CommandFE) if (command != Command::CommandFE && command != Command::CommandAE)
{ {
m_savedCommands.push_back(MapCommandForSerialize(command)); // Save the commands in the m_savedCommands m_savedCommands.push_back(MapCommandForSerialize(command)); // Save the commands in the m_savedCommands
} }
@ -285,6 +291,8 @@ namespace CalculationManager
break; break;
case Command::CommandFE: case Command::CommandFE:
m_isExponentialFormat = !m_isExponentialFormat; m_isExponentialFormat = !m_isExponentialFormat;
case Command::CommandAE:
m_isAutoExponentialFormat = !m_isAutoExponentialFormat;
// fall through // fall through
default: default:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(command)); m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(command));

View file

@ -57,6 +57,7 @@ namespace CalculationManager
CalcEngine::Rational m_persistedPrimaryValue; CalcEngine::Rational m_persistedPrimaryValue;
bool m_isExponentialFormat; bool m_isExponentialFormat;
bool m_isAutoExponentialFormat;
static const unsigned int m_maximumMemorySize = 100; static const unsigned int m_maximumMemorySize = 100;

View file

@ -99,6 +99,7 @@ namespace CalculationManager
CommandPERCENT = 118, CommandPERCENT = 118,
CommandFE = 119, CommandFE = 119,
CommandAE = 148,
CommandPI = 120, CommandPI = 120,
CommandEQU = 121, CommandEQU = 121,

View file

@ -293,7 +293,7 @@ wstring COpndCommand::GetString(uint32_t radix, int32_t precision, wchar_t decim
if (m_fInitialized) if (m_fInitialized)
{ {
result = m_value.ToString(radix, eNUMOBJ_FMT::FMT_FLOAT, precision); result = m_value.ToString(radix, eNUMOBJ_FMT::FMT_FLOAT, eNUMOBJ_AUTOFMT::AUTOFMT_ENABLED, precision);
} }
return result; return result;

View file

@ -103,6 +103,7 @@
#define IDC_UNARYLAST IDC_PERCENT #define IDC_UNARYLAST IDC_PERCENT
#define IDC_FE 119 #define IDC_FE 119
#define IDC_AE 148
#define IDC_PI 120 #define IDC_PI 120
#define IDC_EQU 121 #define IDC_EQU 121

View file

@ -88,6 +88,7 @@ private:
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. */
eNUMOBJ_AUTOFMT m_nAE; /* Automatic scientific notation conversion flag. */
CalcEngine::Rational m_maxTrigonometricNum; CalcEngine::Rational m_maxTrigonometricNum;
std::unique_ptr<CalcEngine::Rational> m_memoryValue; // Current memory value. std::unique_ptr<CalcEngine::Rational> m_memoryValue; // Current memory value.

View file

@ -64,7 +64,7 @@ namespace CalcEngine
friend bool operator<=(Rational const& lhs, Rational const& rhs); friend bool operator<=(Rational const& lhs, Rational const& rhs);
friend bool operator>=(Rational const& lhs, Rational const& rhs); friend bool operator>=(Rational const& lhs, Rational const& rhs);
std::wstring ToString(uint32_t radix, NUMOBJ_FMT format, int32_t precision) const; std::wstring ToString(uint32_t radix, NUMOBJ_FMT format, NUMOBJ_AUTOFMT autoformat, int32_t precision) const;
uint64_t ToUInt64_t() const; uint64_t ToUInt64_t() const;
private: private:

View file

@ -1038,14 +1038,14 @@ bool stripzeroesnum(_Inout_ PNUMBER pnum, long starting)
// representation. // representation.
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_t precision) wstring NumberToString(_Inout_ PNUMBER& pnum, int format, int autoformat, uint32_t radix, int32_t precision)
{ {
stripzeroesnum(pnum, precision + 2); stripzeroesnum(pnum, precision + 2);
long length = pnum->cdigit; long length = pnum->cdigit;
long exponent = pnum->exp + length; // Actual number of digits to the left of decimal long exponent = pnum->exp + length; // Actual number of digits to the left of decimal
long oldFormat = format; long oldFormat = format;
if (exponent > precision && format == FMT_FLOAT) if (exponent > precision && format == FMT_FLOAT && autoformat == AUTOFMT_ENABLED)
{ {
// Force scientific mode to prevent user from assuming 33rd digit is exact. // Force scientific mode to prevent user from assuming 33rd digit is exact.
format = FMT_SCIENTIFIC; format = FMT_SCIENTIFIC;
@ -1065,7 +1065,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
// - if number is zero no rounding // - if number is zero no rounding
// - if number of digits is less than the maximum output no rounding // - if number of digits is less than the maximum output no rounding
PNUMBER round = nullptr; PNUMBER round = nullptr;
if (!zernum(pnum) && (pnum->cdigit >= precision || (length - exponent > precision && exponent >= -MAX_ZEROS_AFTER_DECIMAL))) if (!zernum(pnum) && (pnum->cdigit >= precision && autoformat == AUTOFMT_ENABLED || (length - exponent > precision && (exponent >= -MAX_ZEROS_AFTER_DECIMAL || autoformat == AUTOFMT_DISABLED))))
{ {
// Otherwise round. // Otherwise round.
round = longtonum(radix, radix); round = longtonum(radix, radix);
@ -1088,9 +1088,9 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
if (format == FMT_FLOAT) if (format == FMT_FLOAT)
{ {
// Figure out if the exponent will fill more space than the non-exponent field. // Figure out if the exponent will fill more space than the non-exponent field.
if ((length - exponent > precision) || (exponent > precision + 3)) if ((length - exponent > precision) || (exponent > precision + 3 && autoformat == AUTOFMT_ENABLED))
{ {
if (exponent >= -MAX_ZEROS_AFTER_DECIMAL) if (exponent >= -MAX_ZEROS_AFTER_DECIMAL || autoformat == AUTOFMT_DISABLED)
{ {
round->exp -= exponent; round->exp -= exponent;
length = precision + exponent; length = precision + exponent;
@ -1119,7 +1119,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
{ {
// WARNING: nesting/recursion, too much has been changed, need to // WARNING: nesting/recursion, too much has been changed, need to
// re-figure format. // re-figure format.
return NumberToString(pnum, oldFormat, radix, precision); return NumberToString(pnum, oldFormat, autoformat, radix, precision);
} }
} }
else else
@ -1257,11 +1257,11 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
// why a pointer to the rational is passed in. // why a pointer to the rational is passed in.
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
wstring RatToString(_Inout_ PRAT& prat, int format, uint32_t radix, int32_t precision) wstring RatToString(_Inout_ PRAT& prat, int format, int autoformat, uint32_t radix, int32_t precision)
{ {
PNUMBER p = RatToNumber(prat, radix, precision); PNUMBER p = RatToNumber(prat, radix, precision);
wstring result = NumberToString(p, format, radix, precision); wstring result = NumberToString(p, format, autoformat, radix, precision);
destroynum(p); destroynum(p);
return result; return result;

View file

@ -34,6 +34,11 @@ enum eNUMOBJ_FMT {
}; };
enum eNUMOBJ_AUTOFMT {
AUTOFMT_DISABLED, // never use scientific notation for FMT_FLOAT
AUTOFMT_ENABLED // use scientific notation if number is out of FMT_FLOAT range
};
enum eANGLE_TYPE { enum eANGLE_TYPE {
ANGLE_DEG, // Calculate trig using 360 degrees per revolution ANGLE_DEG, // Calculate trig using 360 degrees per revolution
ANGLE_RAD, // Calculate trig using 2 pi radians per revolution ANGLE_RAD, // Calculate trig using 2 pi radians per revolution
@ -42,6 +47,7 @@ enum eANGLE_TYPE {
}; };
typedef enum eNUMOBJ_FMT NUMOBJ_FMT; typedef enum eNUMOBJ_FMT NUMOBJ_FMT;
typedef enum eNUMOBJ_AUTOFMT NUMOBJ_AUTOFMT;
typedef enum eANGLE_TYPE ANGLE_TYPE; typedef enum eANGLE_TYPE ANGLE_TYPE;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -312,10 +318,10 @@ extern bool equnum(_In_ PNUMBER a, _In_ PNUMBER b ); // returns true of a ==
extern bool lessnum(_In_ PNUMBER a, _In_ PNUMBER b ); // returns true of a < b extern bool lessnum(_In_ PNUMBER a, _In_ PNUMBER b ); // returns true of a < b
extern bool zernum(_In_ PNUMBER a ); // returns true of a == 0 extern bool zernum(_In_ PNUMBER a ); // returns true of a == 0
extern bool zerrat(_In_ PRAT a ); // returns true if a == 0/q extern bool zerrat(_In_ PRAT a ); // returns true if a == 0/q
extern std::wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_t precision); extern std::wstring NumberToString(_Inout_ PNUMBER& pnum, int format, int autoformat, uint32_t radix, int32_t precision);
// returns a text representation of a PRAT // returns a text representation of a PRAT
extern std::wstring RatToString(_Inout_ PRAT& prat, int format, uint32_t radix, int32_t precision); extern std::wstring RatToString(_Inout_ PRAT& prat, int format, int autoformat, uint32_t radix, int32_t precision);
// converts a PRAT into a PNUMBER // converts a PRAT into a PNUMBER
extern PNUMBER RatToNumber(_In_ PRAT prat, uint32_t radix, int32_t precision); extern PNUMBER RatToNumber(_In_ PRAT prat, uint32_t radix, int32_t precision);
// flattens a PRAT by converting it to a PNUMBER and back to a PRAT // flattens a PRAT by converting it to a PNUMBER and back to a PRAT

View file

@ -48,6 +48,7 @@ namespace CalculatorApp
XPower2 = (int) CM::Command::CommandSQR, XPower2 = (int) CM::Command::CommandSQR,
Mod = (int) CM::Command::CommandMOD, Mod = (int) CM::Command::CommandMOD,
FToE = (int) CM::Command::CommandFE, FToE = (int) CM::Command::CommandFE,
AutoE = (int) CM::Command::CommandAE,
LogBaseE = (int) CM::Command::CommandLN, LogBaseE = (int) CM::Command::CommandLN,
InvSin = (int) CM::Command::CommandASIN, InvSin = (int) CM::Command::CommandASIN,
InvCos = (int) CM::Command::CommandACOS, InvCos = (int) CM::Command::CommandACOS,
@ -179,6 +180,7 @@ namespace CalculatorApp
XPower2 = (int) CM::Command::CommandSQR, XPower2 = (int) CM::Command::CommandSQR,
Mod = (int) CM::Command::CommandMOD, Mod = (int) CM::Command::CommandMOD,
FToE = (int) CM::Command::CommandFE, FToE = (int) CM::Command::CommandFE,
AutoE = (int) CM::Command::CommandAE,
LogBaseE = (int) CM::Command::CommandLN, LogBaseE = (int) CM::Command::CommandLN,
InvSin = (int) CM::Command::CommandASIN, InvSin = (int) CM::Command::CommandASIN,
InvCos = (int) CM::Command::CommandACOS, InvCos = (int) CM::Command::CommandACOS,

View file

@ -73,6 +73,7 @@ StandardCalculatorViewModel::StandardCalculatorViewModel() :
m_MemorizedNumbers(ref new Vector<MemoryItemViewModel^>()), m_MemorizedNumbers(ref new Vector<MemoryItemViewModel^>()),
m_IsMemoryEmpty(true), m_IsMemoryEmpty(true),
m_IsFToEChecked(false), m_IsFToEChecked(false),
m_IsAutoEChecked(true),
m_isShiftChecked(false), m_isShiftChecked(false),
m_IsShiftProgrammerChecked(false), m_IsShiftProgrammerChecked(false),
m_IsQwordEnabled(true), m_IsQwordEnabled(true),
@ -414,6 +415,11 @@ void StandardCalculatorViewModel::FtoEButtonToggled()
OnButtonPressed(NumbersAndOperatorsEnum::FToE); OnButtonPressed(NumbersAndOperatorsEnum::FToE);
} }
void StandardCalculatorViewModel::AutoEButtonToggled()
{
OnButtonPressed(NumbersAndOperatorsEnum::AutoE);
}
void StandardCalculatorViewModel::HandleUpdatedOperandData(Command cmdenum) void StandardCalculatorViewModel::HandleUpdatedOperandData(Command cmdenum)
{ {
DisplayExpressionToken^ displayExpressionToken = ExpressionTokens->GetAt(m_tokenPosition); DisplayExpressionToken^ displayExpressionToken = ExpressionTokens->GetAt(m_tokenPosition);
@ -553,7 +559,7 @@ bool StandardCalculatorViewModel::IsOperator(Command cmdenum)
{ {
if ((cmdenum == Command::Command0) || (cmdenum == Command::Command1) || (cmdenum == Command::Command2) || (cmdenum == Command::Command3) || (cmdenum == Command::Command4) || (cmdenum == Command::Command5) if ((cmdenum == Command::Command0) || (cmdenum == Command::Command1) || (cmdenum == Command::Command2) || (cmdenum == Command::Command3) || (cmdenum == Command::Command4) || (cmdenum == Command::Command5)
|| (cmdenum == Command::Command6) || (cmdenum == Command::Command7) || (cmdenum == Command::Command8) || (cmdenum == Command::Command9) || (cmdenum == Command::CommandPNT) || (cmdenum == Command::CommandBACK) || (cmdenum == Command::Command6) || (cmdenum == Command::Command7) || (cmdenum == Command::Command8) || (cmdenum == Command::Command9) || (cmdenum == Command::CommandPNT) || (cmdenum == Command::CommandBACK)
|| (cmdenum == Command::CommandEXP) || (cmdenum == Command::CommandFE) || (cmdenum == Command::ModeBasic) || (cmdenum == Command::ModeBasic) || (cmdenum == Command::ModeProgrammer) || (cmdenum == Command::ModeScientific) || (cmdenum == Command::CommandEXP) || (cmdenum == Command::CommandFE) || (cmdenum == Command::CommandAE) || (cmdenum == Command::ModeBasic) || (cmdenum == Command::ModeBasic) || (cmdenum == Command::ModeProgrammer) || (cmdenum == Command::ModeScientific)
|| (cmdenum == Command::CommandINV) || (cmdenum == Command::CommandCENTR) || (cmdenum == Command::CommandDEG) || (cmdenum == Command::CommandRAD) || (cmdenum == Command::CommandGRAD) || (cmdenum == Command::CommandINV) || (cmdenum == Command::CommandCENTR) || (cmdenum == Command::CommandDEG) || (cmdenum == Command::CommandRAD) || (cmdenum == Command::CommandGRAD)
|| ((cmdenum >= Command::CommandBINEDITSTART) && (cmdenum <= Command::CommandBINEDITEND))) || ((cmdenum >= Command::CommandBINEDITSTART) && (cmdenum <= Command::CommandBINEDITEND)))
{ {
@ -586,6 +592,7 @@ void StandardCalculatorViewModel::OnButtonPressed(Object^ parameter)
numOpEnum != NumbersAndOperatorsEnum::IsStandardMode && numOpEnum != NumbersAndOperatorsEnum::IsStandardMode &&
numOpEnum != NumbersAndOperatorsEnum::IsProgrammerMode && numOpEnum != NumbersAndOperatorsEnum::IsProgrammerMode &&
numOpEnum != NumbersAndOperatorsEnum::FToE && numOpEnum != NumbersAndOperatorsEnum::FToE &&
numOpEnum != NumbersAndOperatorsEnum::AutoE &&
(numOpEnum != NumbersAndOperatorsEnum::Degree) && (numOpEnum != NumbersAndOperatorsEnum::Radians) && (numOpEnum != NumbersAndOperatorsEnum::Grads)) (numOpEnum != NumbersAndOperatorsEnum::Degree) && (numOpEnum != NumbersAndOperatorsEnum::Radians) && (numOpEnum != NumbersAndOperatorsEnum::Grads))
{ {
if (!m_keyPressed) if (!m_keyPressed)
@ -621,6 +628,10 @@ void StandardCalculatorViewModel::OnButtonPressed(Object^ parameter)
{ {
IsFToEChecked = false; IsFToEChecked = false;
} }
if (!IsAutoEChecked)
{
IsAutoEChecked = true;
}
} }
if (numOpEnum == NumbersAndOperatorsEnum::Degree || numOpEnum == NumbersAndOperatorsEnum::Radians || numOpEnum == NumbersAndOperatorsEnum::Grads) if (numOpEnum == NumbersAndOperatorsEnum::Degree || numOpEnum == NumbersAndOperatorsEnum::Radians || numOpEnum == NumbersAndOperatorsEnum::Grads)
{ {
@ -640,6 +651,7 @@ void StandardCalculatorViewModel::OnButtonPressed(Object^ parameter)
((numOpEnum != NumbersAndOperatorsEnum::Degree) && (numOpEnum != NumbersAndOperatorsEnum::Radians) && (numOpEnum != NumbersAndOperatorsEnum::Grads))) ((numOpEnum != NumbersAndOperatorsEnum::Degree) && (numOpEnum != NumbersAndOperatorsEnum::Radians) && (numOpEnum != NumbersAndOperatorsEnum::Grads)))
{ {
IsFToEEnabled = true; IsFToEEnabled = true;
IsAutoEEnabled = true;
m_isLastOperationHistoryLoad = false; m_isLastOperationHistoryLoad = false;
} }
@ -1144,6 +1156,7 @@ Array<unsigned char>^ StandardCalculatorViewModel::Serialize()
DataWriter^ writer = ref new DataWriter(); DataWriter^ writer = ref new DataWriter();
writer->WriteUInt32(static_cast<UINT32>(m_CurrentAngleType)); writer->WriteUInt32(static_cast<UINT32>(m_CurrentAngleType));
writer->WriteBoolean(IsFToEChecked); writer->WriteBoolean(IsFToEChecked);
writer->WriteBoolean(IsAutoEChecked);
writer->WriteBoolean(IsCurrentViewPinned); writer->WriteBoolean(IsCurrentViewPinned);
writer->WriteUInt32(static_cast<UINT32>(m_standardCalculatorManager.SerializeSavedDegreeMode())); writer->WriteUInt32(static_cast<UINT32>(m_standardCalculatorManager.SerializeSavedDegreeMode()));
@ -1202,6 +1215,7 @@ void StandardCalculatorViewModel::Deserialize(Array<unsigned char>^ state)
m_CurrentAngleType = ConvertIntegerToNumbersAndOperatorsEnum(reader->ReadUInt32()); m_CurrentAngleType = ConvertIntegerToNumbersAndOperatorsEnum(reader->ReadUInt32());
IsFToEChecked = reader->ReadBoolean(); IsFToEChecked = reader->ReadBoolean();
IsAutoEChecked = reader->ReadBoolean();
IsCurrentViewPinned = reader->ReadBoolean(); IsCurrentViewPinned = reader->ReadBoolean();
Command serializedDegreeMode = static_cast<Command>(reader->ReadUInt32()); Command serializedDegreeMode = static_cast<Command>(reader->ReadUInt32());
@ -1566,6 +1580,10 @@ void StandardCalculatorViewModel::Recalculate(bool fromHistory)
{ {
m_standardCalculatorManager.SendCommand(Command::CommandFE); m_standardCalculatorManager.SendCommand(Command::CommandFE);
} }
if (!IsAutoEChecked)
{
m_standardCalculatorManager.SendCommand(Command::CommandAE);
}
m_standardCalculatorManager.SendCommand(currentDegreeMode); m_standardCalculatorManager.SendCommand(currentDegreeMode);
size_t currentCommandsSize = currentCommands.size(); size_t currentCommandsSize = currentCommands.size();

View file

@ -72,6 +72,8 @@ namespace CalculatorApp
OBSERVABLE_PROPERTY_RW(bool, IsMemoryEmpty); OBSERVABLE_PROPERTY_RW(bool, IsMemoryEmpty);
OBSERVABLE_PROPERTY_RW(bool, IsFToEChecked); OBSERVABLE_PROPERTY_RW(bool, IsFToEChecked);
OBSERVABLE_PROPERTY_RW(bool, IsFToEEnabled); OBSERVABLE_PROPERTY_RW(bool, IsFToEEnabled);
OBSERVABLE_PROPERTY_RW(bool, IsAutoEChecked);
OBSERVABLE_PROPERTY_RW(bool, IsAutoEEnabled);
OBSERVABLE_PROPERTY_RW(bool, IsHyperbolicChecked); OBSERVABLE_PROPERTY_RW(bool, IsHyperbolicChecked);
OBSERVABLE_PROPERTY_RW(bool, AreHEXButtonsEnabled); OBSERVABLE_PROPERTY_RW(bool, AreHEXButtonsEnabled);
NAMED_OBSERVABLE_PROPERTY_RW(Platform::String^, CalculationResultAutomationName); NAMED_OBSERVABLE_PROPERTY_RW(Platform::String^, CalculationResultAutomationName);
@ -226,6 +228,7 @@ namespace CalculatorApp
IsDecimalEnabled = value; IsDecimalEnabled = value;
AreHEXButtonsEnabled = IsProgrammer; AreHEXButtonsEnabled = IsProgrammer;
IsFToEEnabled = value; IsFToEEnabled = value;
IsAutoEEnabled = value;
RaisePropertyChanged(L"IsOperandEnabled"); RaisePropertyChanged(L"IsOperandEnabled");
} }
} }
@ -305,6 +308,7 @@ namespace CalculatorApp
void Recalculate(bool fromHistory = false); void Recalculate(bool fromHistory = false);
bool IsOperator(CalculationManager::Command cmdenum); bool IsOperator(CalculationManager::Command cmdenum);
void FtoEButtonToggled(); void FtoEButtonToggled();
void AutoEButtonToggled();
void SwitchProgrammerModeBase(RADIX_TYPE calculatorBase); void SwitchProgrammerModeBase(RADIX_TYPE calculatorBase);
void SetMemorizedNumbersString(); void SetMemorizedNumbersString();
void SwitchAngleType(NumbersAndOperatorsEnum num); void SwitchAngleType(NumbersAndOperatorsEnum num);

View file

@ -3371,4 +3371,8 @@
<value>Microsoft Services Agreement</value> <value>Microsoft Services Agreement</value>
<comment>Displayed on a link to the Microsoft Services Agreement in the about this app information</comment> <comment>Displayed on a link to the Microsoft Services Agreement in the about this app information</comment>
</data> </data>
<data name="autoeButton.[using:CalculatorApp.Common]KeyboardShortcutManager.VirtualKey" xml:space="preserve">
<value>B</value>
<comment>{Locked}This is the value that comes from the VirtualKey enum that represents the button. This value is not localized and must be one value that comes from the Windows::System::VirtualKey enum.</comment>
</data>
</root> </root>

View file

@ -492,6 +492,7 @@ void Calculator::OnHistoryItemClicked(_In_ HistoryItemViewModel^ e)
Model->SetExpressionDisplay(e->GetTokens(), e->GetCommands()); Model->SetExpressionDisplay(e->GetTokens(), e->GetCommands());
Model->SetPrimaryDisplay(e->Result->Data(), false); Model->SetPrimaryDisplay(e->Result->Data(), false);
Model->IsFToEEnabled = false; Model->IsFToEEnabled = false;
Model->IsAutoEEnabled = false;
TraceLogger::GetInstance().LogHistoryItemLoadEnd(tokenSize); TraceLogger::GetInstance().LogHistoryItemLoadEnd(tokenSize);
CloseHistoryFlyout(); CloseHistoryFlyout();

View file

@ -50,6 +50,7 @@
<Setter Target="hyperbolicButton.Style" Value="{StaticResource CaptionToggleButtonSmallStyle}"/> <Setter Target="hyperbolicButton.Style" Value="{StaticResource CaptionToggleButtonSmallStyle}"/>
<Setter Target="ftoeButton.Style" Value="{StaticResource CaptionToggleButtonSmallStyle}"/> <Setter Target="ftoeButton.Style" Value="{StaticResource CaptionToggleButtonSmallStyle}"/>
<Setter Target="autoeButton.Style" Value="{StaticResource CaptionToggleButtonSmallStyle}"/>
</VisualState.Setters> </VisualState.Setters>
</VisualState> </VisualState>
</VisualStateGroup> </VisualStateGroup>
@ -62,6 +63,7 @@
<Setter Target="gradsButton.IsEnabled" Value="False"/> <Setter Target="gradsButton.IsEnabled" Value="False"/>
<Setter Target="hyperbolicButton.IsEnabled" Value="False"/> <Setter Target="hyperbolicButton.IsEnabled" Value="False"/>
<Setter Target="ftoeButton.IsEnabled" Value="False"/> <Setter Target="ftoeButton.IsEnabled" Value="False"/>
<Setter Target="autoeButton.IsEnabled" Value="False"/>
</VisualState.Setters> </VisualState.Setters>
</VisualState> </VisualState>
</VisualStateGroup> </VisualStateGroup>
@ -116,5 +118,21 @@
<local:NumbersAndOperatorsEnum>FToE</local:NumbersAndOperatorsEnum> <local:NumbersAndOperatorsEnum>FToE</local:NumbersAndOperatorsEnum>
</ToggleButton.CommandParameter> </ToggleButton.CommandParameter>
</ToggleButton> </ToggleButton>
<ToggleButton x:Name="autoeButton"
x:Uid="autoeButton"
Grid.Column="3"
Style="{StaticResource CaptionToggleButtonStyle}"
Background="{ThemeResource SystemControlBackgroundTransparentBrush}"
FontWeight="SemiBold"
AutomationProperties.AutomationId="autoeButton"
Checked="AutoEButton_Toggled"
Content="Auto-E"
IsChecked="{Binding IsAutoEChecked, Mode=TwoWay}"
IsEnabled="{x:Bind Model.IsAutoEEnabled, Mode=OneWay}"
Unchecked="AutoEButton_Toggled">
<ToggleButton.CommandParameter>
<local:NumbersAndOperatorsEnum>AutoE</local:NumbersAndOperatorsEnum>
</ToggleButton.CommandParameter>
</ToggleButton>
</Grid> </Grid>
</UserControl> </UserControl>

View file

@ -44,6 +44,19 @@ void CalculatorScientificAngleButtons::FToEButton_Toggled(_In_ Object^ sender,_I
{ {
auto viewModel = safe_cast<StandardCalculatorViewModel^>(this->DataContext); auto viewModel = safe_cast<StandardCalculatorViewModel^>(this->DataContext);
viewModel->FtoEButtonToggled(); viewModel->FtoEButtonToggled();
if (Model->IsFToEChecked)
{
autoeButton->Visibility = ::Visibility::Collapsed;
}
else {
autoeButton->Visibility = ::Visibility::Visible;
}
}
void CalculatorScientificAngleButtons::AutoEButton_Toggled(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
{
auto viewModel = safe_cast<StandardCalculatorViewModel^>(this->DataContext);
viewModel->AutoEButtonToggled();
} }
void CalculatorApp::CalculatorScientificAngleButtons::OnAngleButtonPressed(_In_ Object^ commandParameter) void CalculatorApp::CalculatorScientificAngleButtons::OnAngleButtonPressed(_In_ Object^ commandParameter)

View file

@ -35,6 +35,7 @@ namespace CalculatorApp
private: private:
void OnAngleButtonPressed(_In_ Platform::Object^ commandParameter); void OnAngleButtonPressed(_In_ Platform::Object^ commandParameter);
void FToEButton_Toggled(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e); void FToEButton_Toggled(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
void AutoEButton_Toggled(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
void HypButton_Toggled(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e); void HypButton_Toggled(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
bool m_isErrorVisualState; bool m_isErrorVisualState;

View file

@ -77,6 +77,7 @@ namespace CalculatorFunctionalTests
m_standardViewModel->SetExpressionDisplay(e->GetTokens(), e->GetCommands()); m_standardViewModel->SetExpressionDisplay(e->GetTokens(), e->GetCommands());
m_standardViewModel->SetPrimaryDisplay(e->Result->Data(), false/*IsError*/); m_standardViewModel->SetPrimaryDisplay(e->Result->Data(), false/*IsError*/);
m_standardViewModel->IsFToEEnabled = false; m_standardViewModel->IsFToEEnabled = false;
m_standardViewModel->IsAutoEEnabled = false;
} }
void AddSingleHistoryItem(unsigned int windowId = 0) void AddSingleHistoryItem(unsigned int windowId = 0)