From 65045e9375f5ac16a76771d2a5f15b41a4cc8a83 Mon Sep 17 00:00:00 2001 From: Rudy Huyn Date: Mon, 25 Mar 2019 11:11:24 -0700 Subject: [PATCH 01/47] Update the year in the Copyright string (#320) Templatize the copyright string and use a build variable to set the year for use across the entire app. How changes were validated: Tested with English and French and with different dates. --- src/Calculator/AboutFlyout.xaml | 2 +- src/Calculator/AboutFlyout.xaml.cpp | 9 +++++++++ src/Calculator/Resources/af-ZA/Resources.resw | 6 +++--- src/Calculator/Resources/am-ET/Resources.resw | 6 +++--- src/Calculator/Resources/ar-SA/Resources.resw | 6 +++--- src/Calculator/Resources/az-Latn-AZ/Resources.resw | 6 +++--- src/Calculator/Resources/be-BY/Resources.resw | 8 ++++---- src/Calculator/Resources/bg-BG/Resources.resw | 6 +++--- src/Calculator/Resources/bn-BD/Resources.resw | 6 +++--- src/Calculator/Resources/ca-ES/Resources.resw | 10 +++++----- src/Calculator/Resources/cs-CZ/Resources.resw | 6 +++--- src/Calculator/Resources/da-DK/Resources.resw | 10 +++++----- src/Calculator/Resources/de-DE/Resources.resw | 6 +++--- src/Calculator/Resources/el-GR/Resources.resw | 6 +++--- src/Calculator/Resources/en-GB/Resources.resw | 10 +++++----- src/Calculator/Resources/en-US/Resources.resw | 6 +++--- src/Calculator/Resources/es-ES/Resources.resw | 6 +++--- src/Calculator/Resources/es-MX/Resources.resw | 6 +++--- src/Calculator/Resources/et-EE/Resources.resw | 6 +++--- src/Calculator/Resources/eu-ES/Resources.resw | 6 +++--- src/Calculator/Resources/fa-IR/Resources.resw | 6 +++--- src/Calculator/Resources/fi-FI/Resources.resw | 6 +++--- src/Calculator/Resources/fil-PH/Resources.resw | 6 +++--- src/Calculator/Resources/fr-CA/Resources.resw | 10 +++++----- src/Calculator/Resources/fr-FR/Resources.resw | 8 ++++---- src/Calculator/Resources/gl-ES/Resources.resw | 6 +++--- src/Calculator/Resources/he-IL/Resources.resw | 6 +++--- src/Calculator/Resources/hi-IN/Resources.resw | 6 +++--- src/Calculator/Resources/hr-HR/Resources.resw | 4 ++-- src/Calculator/Resources/hu-HU/Resources.resw | 6 +++--- src/Calculator/Resources/id-ID/Resources.resw | 6 +++--- src/Calculator/Resources/is-IS/Resources.resw | 6 +++--- src/Calculator/Resources/it-IT/Resources.resw | 6 +++--- src/Calculator/Resources/ja-JP/Resources.resw | 10 +++++----- src/Calculator/Resources/kk-KZ/Resources.resw | 6 +++--- src/Calculator/Resources/km-KH/Resources.resw | 6 +++--- src/Calculator/Resources/kn-IN/Resources.resw | 6 +++--- src/Calculator/Resources/ko-KR/Resources.resw | 6 +++--- src/Calculator/Resources/lo-LA/Resources.resw | 6 +++--- src/Calculator/Resources/lt-LT/Resources.resw | 10 +++++----- src/Calculator/Resources/lv-LV/Resources.resw | 6 +++--- src/Calculator/Resources/mk-MK/Resources.resw | 6 +++--- src/Calculator/Resources/ml-IN/Resources.resw | 6 +++--- src/Calculator/Resources/ms-MY/Resources.resw | 6 +++--- src/Calculator/Resources/nb-NO/Resources.resw | 6 +++--- src/Calculator/Resources/nl-NL/Resources.resw | 6 +++--- src/Calculator/Resources/pl-PL/Resources.resw | 6 +++--- src/Calculator/Resources/pt-BR/Resources.resw | 6 +++--- src/Calculator/Resources/pt-PT/Resources.resw | 6 +++--- src/Calculator/Resources/ro-RO/Resources.resw | 6 +++--- src/Calculator/Resources/ru-RU/Resources.resw | 10 +++++----- src/Calculator/Resources/sk-SK/Resources.resw | 6 +++--- src/Calculator/Resources/sl-SI/Resources.resw | 6 +++--- src/Calculator/Resources/sq-AL/Resources.resw | 10 +++++----- src/Calculator/Resources/sr-Latn-RS/Resources.resw | 6 +++--- src/Calculator/Resources/sv-SE/Resources.resw | 6 +++--- src/Calculator/Resources/sw-KE/Resources.resw | 6 +++--- src/Calculator/Resources/ta-IN/Resources.resw | 6 +++--- src/Calculator/Resources/te-IN/Resources.resw | 10 +++++----- src/Calculator/Resources/th-TH/Resources.resw | 6 +++--- src/Calculator/Resources/tr-TR/Resources.resw | 6 +++--- src/Calculator/Resources/uk-UA/Resources.resw | 10 +++++----- src/Calculator/Resources/uz-Latn-UZ/Resources.resw | 6 +++--- src/Calculator/Resources/vi-VN/Resources.resw | 10 +++++----- src/Calculator/Resources/zh-CN/Resources.resw | 6 +++--- src/Calculator/Resources/zh-TW/Resources.resw | 10 +++++----- src/Calculator/pch.h | 1 + 67 files changed, 228 insertions(+), 218 deletions(-) diff --git a/src/Calculator/AboutFlyout.xaml b/src/Calculator/AboutFlyout.xaml index cfce6fbc..c2d82f47 100644 --- a/src/Calculator/AboutFlyout.xaml +++ b/src/Calculator/AboutFlyout.xaml @@ -38,7 +38,7 @@ - + SetVersionString(); Header->Text = resourceLoader.GetResourceString("AboutButton/Content"); + + auto copyrightText = LocalizationStringUtil::GetLocalizedString(resourceLoader.GetResourceString("AboutControlCopyright")->Data(), to_wstring(BUILD_YEAR).c_str()); + AboutControlCopyrightRun->Text = ref new String(copyrightText.c_str()); + } void AboutFlyout::FeedbackButton_Click(_In_ Object^ sender, _In_ RoutedEventArgs^ e) diff --git a/src/Calculator/Resources/af-ZA/Resources.resw b/src/Calculator/Resources/af-ZA/Resources.resw index 74f5d134..03914db2 100644 --- a/src/Calculator/Resources/af-ZA/Resources.resw +++ b/src/Calculator/Resources/af-ZA/Resources.resw @@ -2277,9 +2277,9 @@ Microsoft-Privaatheidstelling Displayed on a link to the Microsoft Privacy Statement on the About panel - - © 2018 Microsoft. Alle regte voorbehou. - Copyright statement, displayed on the About panel + + © %1 Microsoft. Alle regte voorbehou. + {Locked="%1"}. Copyright statement, displayed on the About panel. %1 = the current year (4 digits) Inligting oor diff --git a/src/Calculator/Resources/am-ET/Resources.resw b/src/Calculator/Resources/am-ET/Resources.resw index 1d7284ae..bf5de965 100644 --- a/src/Calculator/Resources/am-ET/Resources.resw +++ b/src/Calculator/Resources/am-ET/Resources.resw @@ -2277,9 +2277,9 @@ የ Microsoft ግላዊነት መግለጫ Displayed on a link to the Microsoft Privacy Statement on the About panel - - © 2018 Microsoft. ሁሉም መብቱ የተጠበቀ። - Copyright statement, displayed on the About panel + + © %1 Microsoft. ሁሉም መብቱ የተጠበቀ። + {Locked="%1"}. Copyright statement, displayed on the About panel. %1 = the current year (4 digits) ስለ diff --git a/src/Calculator/Resources/ar-SA/Resources.resw b/src/Calculator/Resources/ar-SA/Resources.resw index 2a7b574d..296f7952 100644 --- a/src/Calculator/Resources/ar-SA/Resources.resw +++ b/src/Calculator/Resources/ar-SA/Resources.resw @@ -2278,9 +2278,9 @@ بيان الخصوصية الخاص بشركة Microsoft Displayed on a link to the Microsoft Privacy Statement on the About panel - - © 2018 Microsoft. جميع الحقوق محفوظة. - Copyright statement, displayed on the About panel + + © %1 Microsoft. جميع الحقوق محفوظة. + {Locked="%1"}. Copyright statement, displayed on the About panel. %1 = the current year (4 digits) حول diff --git a/src/Calculator/Resources/az-Latn-AZ/Resources.resw b/src/Calculator/Resources/az-Latn-AZ/Resources.resw index 1a515cda..8cdfe566 100644 --- a/src/Calculator/Resources/az-Latn-AZ/Resources.resw +++ b/src/Calculator/Resources/az-Latn-AZ/Resources.resw @@ -2277,9 +2277,9 @@ Microsoft Məxfilik Bildirişi Displayed on a link to the Microsoft Privacy Statement on the About panel - - © 2018 Microsoft. Bütün hüquqlar qorunur. - Copyright statement, displayed on the About panel + + © %1 Microsoft. Bütün hüquqlar qorunur. + {Locked="%1"}. Copyright statement, displayed on the About panel. %1 = the current year (4 digits) Haqqında diff --git a/src/Calculator/Resources/be-BY/Resources.resw b/src/Calculator/Resources/be-BY/Resources.resw index 248f348f..bb36bc97 100644 --- a/src/Calculator/Resources/be-BY/Resources.resw +++ b/src/Calculator/Resources/be-BY/Resources.resw @@ -2277,9 +2277,9 @@ Заява аб канфідэнцыйнасці Microsoft Displayed on a link to the Microsoft Privacy Statement on the About panel - - © Microsoft, 2018. Усе правы абароненыя. - Copyright statement, displayed on the About panel + + © Microsoft, %1. Усе правы абароненыя. + {Locked="%1"}. Copyright statement, displayed on the About panel. %1 = the current year (4 digits) Інфармацыя @@ -2899,4 +2899,4 @@ Пагадненне аб выкарыстанні сэрвісаў Microsoft Displayed on a link to the Microsoft Services Agreement in the about this app information - \ No newline at end of file + diff --git a/src/Calculator/Resources/bg-BG/Resources.resw b/src/Calculator/Resources/bg-BG/Resources.resw index e0665849..676ee4d4 100644 --- a/src/Calculator/Resources/bg-BG/Resources.resw +++ b/src/Calculator/Resources/bg-BG/Resources.resw @@ -2277,9 +2277,9 @@ Декларация за поверителност на Microsoft Displayed on a link to the Microsoft Privacy Statement on the About panel - - © 2018 Microsoft. Всички права запазени. - Copyright statement, displayed on the About panel + + © %1 Microsoft. Всички права запазени. + {Locked="%1"}. Copyright statement, displayed on the About panel. %1 = the current year (4 digits) Относно diff --git a/src/Calculator/Resources/bn-BD/Resources.resw b/src/Calculator/Resources/bn-BD/Resources.resw index 64c8777e..2836bc7a 100644 --- a/src/Calculator/Resources/bn-BD/Resources.resw +++ b/src/Calculator/Resources/bn-BD/Resources.resw @@ -2277,9 +2277,9 @@ Microsoft গোপনীয়তার বিবৃতি Displayed on a link to the Microsoft Privacy Statement on the About panel - - © 2018 Microsoft. সর্বস্বত্ব সংরক্ষিত। - Copyright statement, displayed on the About panel + + © %1 Microsoft. সর্বস্বত্ব সংরক্ষিত। + {Locked="%1"}. Copyright statement, displayed on the About panel. %1 = the current year (4 digits) বিষয়ক diff --git a/src/Calculator/Resources/ca-ES/Resources.resw b/src/Calculator/Resources/ca-ES/Resources.resw index 353ca3a8..63e2b9a5 100644 --- a/src/Calculator/Resources/ca-ES/Resources.resw +++ b/src/Calculator/Resources/ca-ES/Resources.resw @@ -1,4 +1,4 @@ - + @@ -651,7 +656,7 @@ - + IsActive = false; } + +// The function will make sure the UI will have enough space to display supplementary results and currency information +void CalculatorApp::UnitConverter::SupplementaryResultsPanelInGrid_SizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e) +{ + //We add 0.01 to be sure to not create an infinite loop with SizeChanged events cascading due to float approximation + RowDltrUnits->MinHeight = max(48.0, e->NewSize.Height + 0.01); +} diff --git a/src/Calculator/Views/UnitConverter.xaml.h b/src/Calculator/Views/UnitConverter.xaml.h index b4b84449..df370eaa 100644 --- a/src/Calculator/Views/UnitConverter.xaml.h +++ b/src/Calculator/Views/UnitConverter.xaml.h @@ -88,5 +88,6 @@ namespace CalculatorApp Windows::UI::Xaml::DispatcherTimer^ m_delayTimer; bool m_isAnimationEnabled; + void SupplementaryResultsPanelInGrid_SizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e); }; } From 7a48f66807fe87c98af9781fda5a526faa13aa86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Tue, 26 Mar 2019 22:30:46 +0100 Subject: [PATCH 08/47] Replace custom types with standard ones (#212) Replace custom types with standard ones --- src/CalcManager/CEngine/CalcInput.cpp | 2 +- src/CalcManager/CEngine/CalcUtils.cpp | 10 +- src/CalcManager/CEngine/History.cpp | 2 +- src/CalcManager/CEngine/Number.cpp | 4 +- src/CalcManager/CEngine/Rational.cpp | 34 +-- src/CalcManager/CEngine/RationalMath.cpp | 36 +-- src/CalcManager/CEngine/calc.cpp | 2 +- src/CalcManager/CEngine/scicomm.cpp | 30 +- src/CalcManager/CEngine/scidisp.cpp | 2 +- src/CalcManager/CEngine/scifunc.cpp | 8 +- src/CalcManager/CEngine/scioper.cpp | 2 +- src/CalcManager/CEngine/sciset.cpp | 8 +- src/CalcManager/CalculatorManager.cpp | 34 +-- src/CalcManager/CalculatorVector.h | 38 +-- src/CalcManager/Header Files/CalcEngine.h | 17 +- src/CalcManager/Header Files/CalcInput.h | 2 +- src/CalcManager/Header Files/CalcUtils.h | 12 +- src/CalcManager/Ratpack/CalcErr.h | 24 +- src/CalcManager/Ratpack/basex.cpp | 32 +-- src/CalcManager/Ratpack/conv.cpp | 324 +++++++++++++--------- src/CalcManager/Ratpack/exp.cpp | 26 +- src/CalcManager/Ratpack/fact.cpp | 14 +- src/CalcManager/Ratpack/itrans.cpp | 10 +- src/CalcManager/Ratpack/logic.cpp | 16 +- src/CalcManager/Ratpack/num.cpp | 42 +-- src/CalcManager/Ratpack/ratconst.h | 8 +- src/CalcManager/Ratpack/ratpak.h | 50 ++-- src/CalcManager/Ratpack/support.cpp | 62 ++--- src/CalcManager/Ratpack/trans.cpp | 6 +- src/CalcManager/Ratpack/transh.cpp | 6 +- src/CalcManager/pch.h | 1 + src/CalcViewModel/Common/DateCalculator.h | 10 +- 32 files changed, 478 insertions(+), 396 deletions(-) diff --git a/src/CalcManager/CEngine/CalcInput.cpp b/src/CalcManager/CEngine/CalcInput.cpp index 4994e025..45e553b9 100644 --- a/src/CalcManager/CEngine/CalcInput.cpp +++ b/src/CalcManager/CEngine/CalcInput.cpp @@ -56,7 +56,7 @@ bool CalcInput::TryToggleSign(bool isIntegerMode, wstring_view maxNumStr) return true; } -bool CalcInput::TryAddDigit(unsigned int value, uint32_t radix, bool isIntegerMode, wstring_view maxNumStr, long wordBitWidth, int maxDigits) +bool CalcInput::TryAddDigit(unsigned int value, uint32_t radix, bool isIntegerMode, wstring_view maxNumStr, int32_t wordBitWidth, int maxDigits) { // Convert from an integer into a character // This includes both normal digits and alpha 'digits' for radixes > 10 diff --git a/src/CalcManager/CEngine/CalcUtils.cpp b/src/CalcManager/CEngine/CalcUtils.cpp index fe488009..7980e4e0 100644 --- a/src/CalcManager/CEngine/CalcUtils.cpp +++ b/src/CalcManager/CEngine/CalcUtils.cpp @@ -5,24 +5,24 @@ #include "Header Files/CalcEngine.h" #include "Header Files/CalcUtils.h" -bool IsOpInRange(WPARAM op, uint32_t x, uint32_t y) +bool IsOpInRange(OpCode op, uint32_t x, uint32_t y) { return ((op >= x) && (op <= y)); } -bool IsBinOpCode(WPARAM opCode) +bool IsBinOpCode(OpCode opCode) { return IsOpInRange(opCode, IDC_AND, IDC_PWR); } // WARNING: IDC_SIGN is a special unary op but still this doesn't catch this. Caller has to be aware // of it and catch it themselves or not needing this -bool IsUnaryOpCode(WPARAM opCode) +bool IsUnaryOpCode(OpCode opCode) { return IsOpInRange(opCode, IDC_UNARYFIRST, IDC_UNARYLAST); } -bool IsDigitOpCode(WPARAM opCode) +bool IsDigitOpCode(OpCode opCode) { return IsOpInRange(opCode, IDC_0, IDC_F); } @@ -32,7 +32,7 @@ bool IsDigitOpCode(WPARAM opCode) // so we abstract this as a separate routine. Note: There is another side to this. Some commands are not // gui mode setting to begin with, but once it is discovered it is invalid and we want to behave as though it // was never inout, we need to revert the state changes made as a result of this test -bool IsGuiSettingOpCode(WPARAM opCode) +bool IsGuiSettingOpCode(OpCode opCode) { if (IsOpInRange(opCode, IDM_HEX, IDM_BIN) || IsOpInRange(opCode, IDM_QWORD, IDM_BYTE) || diff --git a/src/CalcManager/CEngine/History.cpp b/src/CalcManager/CEngine/History.cpp index e5bb746b..ca276a41 100644 --- a/src/CalcManager/CEngine/History.cpp +++ b/src/CalcManager/CEngine/History.cpp @@ -13,7 +13,7 @@ using namespace std; using namespace CalcEngine; namespace { - void IFT(HRESULT hr) + void IFT(ResultCode hr) { if (FAILED(hr)) { diff --git a/src/CalcManager/CEngine/Number.cpp b/src/CalcManager/CEngine/Number.cpp index 0d809917..4bf83a33 100644 --- a/src/CalcManager/CEngine/Number.cpp +++ b/src/CalcManager/CEngine/Number.cpp @@ -28,10 +28,10 @@ namespace CalcEngine PNUMBER Number::ToPNUMBER() const { - PNUMBER ret = _createnum(static_cast(this->Mantissa().size()) + 1); + PNUMBER ret = _createnum(static_cast(this->Mantissa().size()) + 1); ret->sign = this->Sign(); ret->exp = this->Exp(); - ret->cdigit = static_cast(this->Mantissa().size()); + ret->cdigit = static_cast(this->Mantissa().size()); MANTTYPE *ptrRet = ret->mant; for (auto const& digit : this->Mantissa()) diff --git a/src/CalcManager/CEngine/Rational.cpp b/src/CalcManager/CEngine/Rational.cpp index 22a972a3..fd86b72a 100644 --- a/src/CalcManager/CEngine/Rational.cpp +++ b/src/CalcManager/CEngine/Rational.cpp @@ -31,7 +31,7 @@ namespace CalcEngine Rational::Rational(int32_t i) { - PRAT pr = longtorat(static_cast(i)); + PRAT pr = i32torat(static_cast(i)); m_p = Number{ pr->pp }; m_q = Number{ pr->pq }; @@ -41,7 +41,7 @@ namespace CalcEngine Rational::Rational(uint32_t ui) { - PRAT pr = Ulongtorat(static_cast(ui)); + PRAT pr = Ui32torat(static_cast(ui)); m_p = Number{ pr->pp }; m_q = Number{ pr->pq }; @@ -100,7 +100,7 @@ namespace CalcEngine addrat(&lhsRat, rhsRat, RATIONAL_PRECISION); destroyrat(rhsRat); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(lhsRat); destroyrat(rhsRat); @@ -123,7 +123,7 @@ namespace CalcEngine subrat(&lhsRat, rhsRat, RATIONAL_PRECISION); destroyrat(rhsRat); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(lhsRat); destroyrat(rhsRat); @@ -146,7 +146,7 @@ namespace CalcEngine mulrat(&lhsRat, rhsRat, RATIONAL_PRECISION); destroyrat(rhsRat); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(lhsRat); destroyrat(rhsRat); @@ -169,7 +169,7 @@ namespace CalcEngine divrat(&lhsRat, rhsRat, RATIONAL_PRECISION); destroyrat(rhsRat); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(lhsRat); destroyrat(rhsRat); @@ -192,7 +192,7 @@ namespace CalcEngine modrat(&lhsRat, rhsRat); destroyrat(rhsRat); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(lhsRat); destroyrat(rhsRat); @@ -215,7 +215,7 @@ namespace CalcEngine lshrat(&lhsRat, rhsRat, RATIONAL_BASE, RATIONAL_PRECISION); destroyrat(rhsRat); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(lhsRat); destroyrat(rhsRat); @@ -238,7 +238,7 @@ namespace CalcEngine rshrat(&lhsRat, rhsRat, RATIONAL_BASE, RATIONAL_PRECISION); destroyrat(rhsRat); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(lhsRat); destroyrat(rhsRat); @@ -261,7 +261,7 @@ namespace CalcEngine andrat(&lhsRat, rhsRat, RATIONAL_BASE, RATIONAL_PRECISION); destroyrat(rhsRat); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(lhsRat); destroyrat(rhsRat); @@ -283,7 +283,7 @@ namespace CalcEngine orrat(&lhsRat, rhsRat, RATIONAL_BASE, RATIONAL_PRECISION); destroyrat(rhsRat); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(lhsRat); destroyrat(rhsRat); @@ -305,7 +305,7 @@ namespace CalcEngine xorrat(&lhsRat, rhsRat, RATIONAL_BASE, RATIONAL_PRECISION); destroyrat(rhsRat); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(lhsRat); destroyrat(rhsRat); @@ -388,7 +388,7 @@ namespace CalcEngine { result = rat_equ(lhsRat, rhsRat, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(lhsRat); destroyrat(rhsRat); @@ -416,7 +416,7 @@ namespace CalcEngine { result = rat_lt(lhsRat, rhsRat, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(lhsRat); destroyrat(rhsRat); @@ -453,7 +453,7 @@ namespace CalcEngine { result = RatToString(rat, fmt, radix, precision); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(rat); throw(error); @@ -470,9 +470,9 @@ namespace CalcEngine uint64_t result; try { - result = rattoUlonglong(rat, RATIONAL_BASE, RATIONAL_PRECISION); + result = rattoUi64(rat, RATIONAL_BASE, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(rat); throw(error); diff --git a/src/CalcManager/CEngine/RationalMath.cpp b/src/CalcManager/CEngine/RationalMath.cpp index 46b5a086..37dc7926 100644 --- a/src/CalcManager/CEngine/RationalMath.cpp +++ b/src/CalcManager/CEngine/RationalMath.cpp @@ -14,7 +14,7 @@ Rational RationalMath::Frac(Rational const& rat) { fracrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); @@ -33,7 +33,7 @@ Rational RationalMath::Integer(Rational const& rat) { intrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); @@ -55,7 +55,7 @@ Rational RationalMath::Pow(Rational const& base, Rational const& pow) powrat(&baseRat, powRat, RATIONAL_BASE, RATIONAL_PRECISION); destroyrat(powRat); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(baseRat); destroyrat(powRat); @@ -81,7 +81,7 @@ Rational RationalMath::Fact(Rational const& rat) { factrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); @@ -101,7 +101,7 @@ Rational RationalMath::Exp(Rational const& rat) { exprat(&prat, RATIONAL_BASE, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); @@ -121,7 +121,7 @@ Rational RationalMath::Log(Rational const& rat) { lograt(&prat, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); @@ -156,7 +156,7 @@ Rational RationalMath::Sin(Rational const& rat, ANGLE_TYPE angletype) { sinanglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); @@ -176,7 +176,7 @@ Rational RationalMath::Cos(Rational const& rat, ANGLE_TYPE angletype) { cosanglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); @@ -196,7 +196,7 @@ Rational RationalMath::Tan(Rational const& rat, ANGLE_TYPE angletype) { tananglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); @@ -216,7 +216,7 @@ Rational RationalMath::ASin(Rational const& rat, ANGLE_TYPE angletype) { asinanglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); @@ -236,7 +236,7 @@ Rational RationalMath::ACos(Rational const& rat, ANGLE_TYPE angletype) { acosanglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); @@ -256,7 +256,7 @@ Rational RationalMath::ATan(Rational const& rat, ANGLE_TYPE angletype) { atananglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); @@ -276,7 +276,7 @@ Rational RationalMath::Sinh(Rational const& rat) { sinhrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); @@ -296,7 +296,7 @@ Rational RationalMath::Cosh(Rational const& rat) { coshrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); @@ -316,7 +316,7 @@ Rational RationalMath::Tanh(Rational const& rat) { tanhrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); @@ -336,7 +336,7 @@ Rational RationalMath::ASinh(Rational const& rat) { asinhrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); @@ -356,7 +356,7 @@ Rational RationalMath::ACosh(Rational const& rat) { acoshrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); @@ -376,7 +376,7 @@ Rational RationalMath::ATanh(Rational const& rat) { atanhrat(&prat, RATIONAL_PRECISION); } - catch (DWORD error) + catch (uint32_t error) { destroyrat(prat); throw(error); diff --git a/src/CalcManager/CEngine/calc.cpp b/src/CalcManager/CEngine/calc.cpp index 6f93a600..9d1ca9de 100644 --- a/src/CalcManager/CEngine/calc.cpp +++ b/src/CalcManager/CEngine/calc.cpp @@ -15,7 +15,7 @@ using namespace CalcEngine; static constexpr int DEFAULT_MAX_DIGITS = 32; static constexpr int DEFAULT_PRECISION = 32; -static constexpr long DEFAULT_RADIX = 10; +static constexpr int32_t DEFAULT_RADIX = 10; static constexpr wchar_t DEFAULT_DEC_SEPARATOR = L'.'; static constexpr wchar_t DEFAULT_GRP_SEPARATOR = L','; diff --git a/src/CalcManager/CEngine/scicomm.cpp b/src/CalcManager/CEngine/scicomm.cpp index a99397da..f17938bf 100644 --- a/src/CalcManager/CEngine/scicomm.cpp +++ b/src/CalcManager/CEngine/scicomm.cpp @@ -31,9 +31,9 @@ namespace { // // returns a virtual number for precedence for the operator. We expect binary operator only, otherwise the lowest number // 0 is returned. Higher the number, higher the precedence of the operator. - INT NPrecedenceOfOp(int nopCode) + int NPrecedenceOfOp(int nopCode) { - static BYTE rgbPrec[] = { 0,0, IDC_OR,0, IDC_XOR,0, IDC_AND,1, + static uint8_t rgbPrec[] = { 0,0, IDC_OR,0, IDC_XOR,0, IDC_AND,1, IDC_ADD,2, IDC_SUB,2, IDC_RSHF,3, IDC_LSHF,3, IDC_MOD,3, IDC_DIV,3, IDC_MUL,3, IDC_PWR,4, IDC_ROOT, 4 }; unsigned int iPrec; @@ -56,7 +56,7 @@ namespace { // // When it is discovered by the state machine that at this point the input is not valid (eg. "1+)"), we want to proceed as though this input never // occurred and may be some feedback to user like Beep. The rest of input can then continue by just ignoring this command. -void CCalcEngine::HandleErrorCommand(WPARAM idc) +void CCalcEngine::HandleErrorCommand(OpCode idc) { if (!IsGuiSettingOpCode(idc)) { @@ -83,7 +83,7 @@ void CCalcEngine::ClearTemporaryValues() m_bError = false; } -void CCalcEngine::ProcessCommand(WPARAM wParam) +void CCalcEngine::ProcessCommand(OpCode wParam) { if (wParam == IDC_SET_RESULT) { @@ -94,9 +94,9 @@ void CCalcEngine::ProcessCommand(WPARAM wParam) ProcessCommandWorker(wParam); } -void CCalcEngine::ProcessCommandWorker(WPARAM wParam) +void CCalcEngine::ProcessCommandWorker(OpCode wParam) { - INT nx, ni; + int nx, ni; // Save the last command. Some commands are not saved in this manor, these // commands are: @@ -107,7 +107,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam) if (!IsGuiSettingOpCode(wParam)) { m_nLastCom = m_nTempCom; - m_nTempCom = (INT)wParam; + m_nTempCom = (int)wParam; } if (m_bError) @@ -185,10 +185,10 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam) // Change the operation if last input was operation. if (IsBinOpCode(m_nLastCom)) { - INT nPrev; + int nPrev; bool fPrecInvToHigher = false; // Is Precedence Inversion from lower to higher precedence happening ?? - m_nOpCode = (INT)wParam; + m_nOpCode = (int)wParam; // Check to see if by changing this binop, a Precedence inversion is happening. // Eg. 1 * 2 + and + is getting changed to ^. The previous precedence rules would have already computed @@ -285,7 +285,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam) DisplayAnnounceBinaryOperator(); m_lastVal = m_currentVal; - m_nOpCode = (INT)wParam; + m_nOpCode = (int)wParam; m_HistoryCollector.AddBinOpToHistory(m_nOpCode); m_bNoPrevEqu = m_bChangeOp = true; return; @@ -313,7 +313,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam) m_HistoryCollector.AddOpndToHistory(m_numberString, m_currentVal); } - m_HistoryCollector.AddUnaryOpToHistory((INT)wParam, m_bInv, m_angletype); + m_HistoryCollector.AddUnaryOpToHistory((int)wParam, m_bInv, m_angletype); } if ((wParam == IDC_SIN) || (wParam == IDC_COS) || (wParam == IDC_TAN) || (wParam == IDC_SINH) || (wParam == IDC_COSH) || (wParam == IDC_TANH)) @@ -326,7 +326,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam) } } - m_currentVal = SciCalcFunctions(m_currentVal, (DWORD)wParam); + m_currentVal = SciCalcFunctions(m_currentVal, (uint32_t)wParam); if (m_bError) return; @@ -366,7 +366,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam) CheckAndAddLastBinOpToHistory(); - if (TryToggleBit(m_currentVal, (DWORD)wParam - IDC_BINEDITSTART)) + if (TryToggleBit(m_currentVal, (uint32_t)wParam - IDC_BINEDITSTART)) { DisplayNum(); } @@ -442,7 +442,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam) m_nTempCom = m_nLastCom; // Put back this last saved command to the prev state so ) can be handled properly ProcessCommand(IDC_CLOSEP); m_nLastCom = m_nTempCom; // Actually this is IDC_CLOSEP - m_nTempCom = (INT)wParam; // put back in the state where last op seen was IDC_CLOSEP, and current op is IDC_EQU + m_nTempCom = (int)wParam; // put back in the state where last op seen was IDC_CLOSEP, and current op is IDC_EQU } if (!m_bNoPrevEqu) @@ -1060,7 +1060,7 @@ wstring CCalcEngine::GetStringForDisplay(Rational const& rat, uint32_t radix) result = tempRat.ToString(radix, m_nFE, m_precision); } - catch (DWORD) + catch (uint32_t) { } } diff --git a/src/CalcManager/CEngine/scidisp.cpp b/src/CalcManager/CEngine/scidisp.cpp index e01cc239..849fe863 100644 --- a/src/CalcManager/CEngine/scidisp.cpp +++ b/src/CalcManager/CEngine/scidisp.cpp @@ -39,7 +39,7 @@ typedef struct { Rational value; int32_t precision; uint32_t radix; - INT nFE; + int nFE; NUM_WIDTH numwidth; bool fIntMath; bool bRecord; diff --git a/src/CalcManager/CEngine/scifunc.cpp b/src/CalcManager/CEngine/scifunc.cpp index 9c7ef7a3..a1007c1c 100644 --- a/src/CalcManager/CEngine/scifunc.cpp +++ b/src/CalcManager/CEngine/scifunc.cpp @@ -24,7 +24,7 @@ using namespace CalcEngine; using namespace CalcEngine::RationalMath; /* Routines for more complex mathematical functions/error checking. */ -CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& rat, DWORD op) +CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& rat, uint32_t op) { Rational result{}; try @@ -205,7 +205,7 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r } } // end switch( op ) } - catch (DWORD nErrCode) + catch (uint32_t nErrCode) { DisplayError(nErrCode); result = rat; @@ -215,9 +215,9 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r } /* Routine to display error messages and set m_bError flag. Errors are */ -/* called with DisplayError (n), where n is a DWORD between 0 and 5. */ +/* called with DisplayError (n), where n is a uint32_t between 0 and 5. */ -void CCalcEngine::DisplayError(DWORD nError) +void CCalcEngine::DisplayError(uint32_t nError) { wstring errorString{ GetString(IDS_ERRORS_FIRST + SCODE_CODE(nError)) }; diff --git a/src/CalcManager/CEngine/scioper.cpp b/src/CalcManager/CEngine/scioper.cpp index 06fe3450..b09083c4 100644 --- a/src/CalcManager/CEngine/scioper.cpp +++ b/src/CalcManager/CEngine/scioper.cpp @@ -133,7 +133,7 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa break; } } - catch (DWORD dwErrCode) + catch (uint32_t dwErrCode) { DisplayError(dwErrCode); diff --git a/src/CalcManager/CEngine/sciset.cpp b/src/CalcManager/CEngine/sciset.cpp index 95451dc9..5495748e 100644 --- a/src/CalcManager/CEngine/sciset.cpp +++ b/src/CalcManager/CEngine/sciset.cpp @@ -51,10 +51,10 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwid DisplayNum(); } -LONG CCalcEngine::DwWordBitWidthFromeNumWidth(NUM_WIDTH /*numwidth*/) +int32_t CCalcEngine::DwWordBitWidthFromeNumWidth(NUM_WIDTH /*numwidth*/) { static constexpr int nBitMax[] = { 64, 32, 16, 8 }; - LONG wmax = nBitMax[0]; + int32_t wmax = nBitMax[0]; if (m_numwidth >= 0 && (size_t)m_numwidth < size(nBitMax)) { @@ -77,9 +77,9 @@ uint32_t CCalcEngine::NRadixFromRadixType(RADIX_TYPE radixtype) } // Toggles a given bit into the number representation. returns true if it changed it actually. -bool CCalcEngine::TryToggleBit(CalcEngine::Rational& rat, DWORD wbitno) +bool CCalcEngine::TryToggleBit(CalcEngine::Rational& rat, uint32_t wbitno) { - DWORD wmax = DwWordBitWidthFromeNumWidth(m_numwidth); + uint32_t wmax = DwWordBitWidthFromeNumWidth(m_numwidth); if (wbitno >= wmax) { return false; // ignore error cant happen diff --git a/src/CalcManager/CalculatorManager.cpp b/src/CalcManager/CalculatorManager.cpp index ddb28a6b..b4b4dfaf 100644 --- a/src/CalcManager/CalculatorManager.cpp +++ b/src/CalcManager/CalculatorManager.cpp @@ -212,7 +212,7 @@ namespace CalculationManager /// /// Send command to the Calc Engine - /// Cast Command Enum to WPARAM. + /// Cast Command Enum to OpCode. /// Handle special commands such as mode change and combination of two commands. /// /// Enum Command @@ -235,7 +235,7 @@ namespace CalculationManager this->SetProgrammerMode(); break; default: - m_currentCalculatorEngine->ProcessCommand(static_cast(command)); + m_currentCalculatorEngine->ProcessCommand(static_cast(command)); } m_savedCommands.clear(); // Clear the previous command history @@ -263,38 +263,38 @@ namespace CalculationManager switch (command) { case Command::CommandASIN: - m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandINV)); - m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandSIN)); + m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandINV)); + m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandSIN)); break; case Command::CommandACOS: - m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandINV)); - m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandCOS)); + m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandINV)); + m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandCOS)); break; case Command::CommandATAN: - m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandINV)); - m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandTAN)); + m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandINV)); + m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandTAN)); break; case Command::CommandPOWE: - m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandINV)); - m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandLN)); + m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandINV)); + m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandLN)); break; case Command::CommandASINH: - m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandINV)); - m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandSINH)); + m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandINV)); + m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandSINH)); break; case Command::CommandACOSH: - m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandINV)); - m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandCOSH)); + m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandINV)); + m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandCOSH)); break; case Command::CommandATANH: - m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandINV)); - m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandTANH)); + m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandINV)); + m_currentCalculatorEngine->ProcessCommand(static_cast(Command::CommandTANH)); break; case Command::CommandFE: m_isExponentialFormat = !m_isExponentialFormat; [[fallthrough]]; default: - m_currentCalculatorEngine->ProcessCommand(static_cast(command)); + m_currentCalculatorEngine->ProcessCommand(static_cast(command)); break; } } diff --git a/src/CalcManager/CalculatorVector.h b/src/CalcManager/CalculatorVector.h index 7fad7e7d..a4de434d 100644 --- a/src/CalcManager/CalculatorVector.h +++ b/src/CalcManager/CalculatorVector.h @@ -3,13 +3,15 @@ #pragma once +#include "Ratpack/CalcErr.h" + template class CalculatorVector { public: - HRESULT GetAt(_In_opt_ unsigned int index, _Out_ TType *item) + ResultCode GetAt(_In_opt_ unsigned int index, _Out_ TType *item) { - HRESULT hr = S_OK; + ResultCode hr = S_OK; try { *item = m_vector.at(index); @@ -21,15 +23,15 @@ public: return hr; } - HRESULT GetSize(_Out_ unsigned int *size) + ResultCode GetSize(_Out_ unsigned int *size) { *size = static_cast(m_vector.size()); return S_OK; } - HRESULT SetAt(_In_ unsigned int index, _In_opt_ TType item) + ResultCode SetAt(_In_ unsigned int index, _In_opt_ TType item) { - HRESULT hr = S_OK; + ResultCode hr = S_OK; try { m_vector[index] = item; @@ -41,9 +43,9 @@ public: return hr; } - HRESULT RemoveAt(_In_ unsigned int index) + ResultCode RemoveAt(_In_ unsigned int index) { - HRESULT hr = S_OK; + ResultCode hr = S_OK; if (index < m_vector.size()) { m_vector.erase(m_vector.begin() + index); @@ -55,9 +57,9 @@ public: return hr; } - HRESULT InsertAt(_In_ unsigned int index, _In_ TType item) + ResultCode InsertAt(_In_ unsigned int index, _In_ TType item) { - HRESULT hr = S_OK; + ResultCode hr = S_OK; try { auto iter = m_vector.begin() + index; @@ -70,9 +72,9 @@ public: return hr; } - HRESULT Truncate(_In_ unsigned int index) + ResultCode Truncate(_In_ unsigned int index) { - HRESULT hr = S_OK; + ResultCode hr = S_OK; if (index < m_vector.size()) { auto startIter = m_vector.begin() + index; @@ -85,9 +87,9 @@ public: return hr; } - HRESULT Append(_In_opt_ TType item) + ResultCode Append(_In_opt_ TType item) { - HRESULT hr = S_OK; + ResultCode hr = S_OK; try { m_vector.push_back(item); @@ -99,21 +101,21 @@ public: return hr; } - HRESULT RemoveAtEnd() + ResultCode RemoveAtEnd() { m_vector.erase(--(m_vector.end())); return S_OK; } - HRESULT Clear() + ResultCode Clear() { m_vector.clear(); return S_OK; } - HRESULT GetString(_Out_ std::wstring* expression) + ResultCode GetString(_Out_ std::wstring* expression) { - HRESULT hr = S_OK; + ResultCode hr = S_OK; unsigned int nTokens = 0; std::pair currentPair; hr = this->GetSize(&nTokens); @@ -144,7 +146,7 @@ public: return hr; } - HRESULT GetExpressionSuffix(_Out_ std::wstring* suffix) + ResultCode GetExpressionSuffix(_Out_ std::wstring* suffix) { *suffix = L" ="; return S_OK; diff --git a/src/CalcManager/Header Files/CalcEngine.h b/src/CalcManager/Header Files/CalcEngine.h index 3e151e2a..0ad8252f 100644 --- a/src/CalcManager/Header Files/CalcEngine.h +++ b/src/CalcManager/Header Files/CalcEngine.h @@ -22,6 +22,7 @@ #include "RadixType.h" #include "History.h" // for History Collector #include "CalcInput.h" +#include "CalcUtils.h" #include "ICalcDisplay.h" #include "Rational.h" #include "RationalMath.h" @@ -52,8 +53,8 @@ namespace CalculatorUnitTests class CCalcEngine { public: CCalcEngine(bool fPrecedence, bool fIntegerMode, CalculationManager::IResourceProvider* const pResourceProvider, __in_opt ICalcDisplay *pCalcDisplay, __in_opt std::shared_ptr pHistoryDisplay); - void ProcessCommand(WPARAM wID); - void DisplayError (DWORD nError); + void ProcessCommand(OpCode wID); + void DisplayError (uint32_t nError); std::unique_ptr PersistedMemObject(); void PersistedMemObject(CalcEngine::Rational const& memObject); bool FInErrorState() { return m_bError; } @@ -116,7 +117,7 @@ private: int m_nLastCom; // Last command entered. ANGLE_TYPE m_angletype; // Current Angle type when in dec mode. one of deg, rad or grad NUM_WIDTH m_numwidth; // one of qword, dword, word or byte mode. - LONG m_dwWordBitWidth; // # of bits in currently selected word size + int32_t m_dwWordBitWidth; // # of bits in currently selected word size CHistoryCollector m_HistoryCollector; // Accumulator of each line of history as various commands are processed @@ -127,8 +128,8 @@ private: wchar_t m_groupSeparator; private: - void ProcessCommandWorker(WPARAM wParam); - void HandleErrorCommand(WPARAM idc); + void ProcessCommandWorker(OpCode wParam); + void HandleErrorCommand(OpCode idc); void HandleMaxDigitsReached(); void DisplayNum(void); int IsNumberInvalid(const std::wstring& numberString, int iMaxExp, int iMaxMantissa, uint32_t radix) const; @@ -136,13 +137,13 @@ private: void SetPrimaryDisplay(const std::wstring& szText, bool isError = false); void ClearTemporaryValues(); CalcEngine::Rational TruncateNumForIntMath(CalcEngine::Rational const& rat); - CalcEngine::Rational SciCalcFunctions(CalcEngine::Rational const& rat, DWORD op); + CalcEngine::Rational SciCalcFunctions(CalcEngine::Rational const& rat, uint32_t op); CalcEngine::Rational DoOperation(int operation, CalcEngine::Rational const& lhs, CalcEngine::Rational const& rhs); void SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwidth); - LONG DwWordBitWidthFromeNumWidth(NUM_WIDTH numwidth); + int32_t DwWordBitWidthFromeNumWidth(NUM_WIDTH numwidth); uint32_t NRadixFromRadixType( RADIX_TYPE radixtype); - bool TryToggleBit(CalcEngine::Rational& rat, DWORD wbitno); + bool TryToggleBit(CalcEngine::Rational& rat, uint32_t wbitno); void CheckAndAddLastBinOpToHistory(bool addToHistory = true); int IdcSetAngleTypeDecMode(int idc); diff --git a/src/CalcManager/Header Files/CalcInput.h b/src/CalcManager/Header Files/CalcInput.h index 60d628c1..b39021e4 100644 --- a/src/CalcManager/Header Files/CalcInput.h +++ b/src/CalcManager/Header Files/CalcInput.h @@ -47,7 +47,7 @@ namespace CalcEngine void Clear(); bool TryToggleSign(bool isIntegerMode, std::wstring_view maxNumStr); - bool TryAddDigit(unsigned int value, uint32_t radix, bool isIntegerMode, std::wstring_view maxNumStr, long wordBitWidth, int maxDigits); + bool TryAddDigit(unsigned int value, uint32_t radix, bool isIntegerMode, std::wstring_view maxNumStr, int32_t wordBitWidth, int maxDigits); bool TryAddDecimalPt(); bool HasDecimalPt(); bool TryBeginExponent(); diff --git a/src/CalcManager/Header Files/CalcUtils.h b/src/CalcManager/Header Files/CalcUtils.h index 1e0dcae3..bd800783 100644 --- a/src/CalcManager/Header Files/CalcUtils.h +++ b/src/CalcManager/Header Files/CalcUtils.h @@ -3,11 +3,13 @@ #pragma once -bool IsOpInRange(WPARAM op, uint32_t x, uint32_t y); -bool IsBinOpCode(WPARAM opCode); +using OpCode = uintptr_t; + +bool IsOpInRange(OpCode op, uint32_t x, uint32_t y); +bool IsBinOpCode(OpCode opCode); // WARNING: IDC_SIGN is a special unary op but still this doesn't catch this. Caller has to be aware // of it and catch it themselves or not needing this -bool IsUnaryOpCode(WPARAM opCode); -bool IsDigitOpCode(WPARAM opCode); -bool IsGuiSettingOpCode(WPARAM opCode); +bool IsUnaryOpCode(OpCode opCode); +bool IsDigitOpCode(OpCode opCode); +bool IsGuiSettingOpCode(OpCode opCode); diff --git a/src/CalcManager/Ratpack/CalcErr.h b/src/CalcManager/Ratpack/CalcErr.h index b420a766..8c23e440 100644 --- a/src/CalcManager/Ratpack/CalcErr.h +++ b/src/CalcManager/Ratpack/CalcErr.h @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +#pragma once + // CalcErr.h // // Defines the error codes thrown by ratpak and caught by Calculator @@ -24,7 +26,7 @@ // R - Reserved - not currently used for anything // // r - reserved portion of the facility code. Reserved for internal -// use. Used to indicate HRESULT values that are not status +// use. Used to indicate int32_t values that are not status // values, but are instead message ids for display strings. // // Facility - is the facility code @@ -34,49 +36,51 @@ // This format is based loosely on an OLE HRESULT and is compatible with the // SUCCEEDED and FAILED macros as well as the HRESULT_CODE macro +typedef int32_t ResultCode; + // CALC_E_DIVIDEBYZERO // // The current operation would require a divide by zero to complete -#define CALC_E_DIVIDEBYZERO ((DWORD)0x80000000) +#define CALC_E_DIVIDEBYZERO ((uint32_t)0x80000000) // CALC_E_DOMAIN // // The given input is not within the domain of this function -#define CALC_E_DOMAIN ((DWORD)0x80000001) +#define CALC_E_DOMAIN ((uint32_t)0x80000001) // CALC_E_INDEFINITE // // The result of this function is undefined -#define CALC_E_INDEFINITE ((DWORD)0x80000002) +#define CALC_E_INDEFINITE ((uint32_t)0x80000002) // CALC_E_POSINFINITY // // The result of this function is Positive Infinity. -#define CALC_E_POSINFINITY ((DWORD)0x80000003) +#define CALC_E_POSINFINITY ((uint32_t)0x80000003) // CALC_E_NEGINFINITY // // The result of this function is Negative Infinity -#define CALC_E_NEGINFINITY ((DWORD)0x80000004) +#define CALC_E_NEGINFINITY ((uint32_t)0x80000004) // CALC_E_INVALIDRANGE // // The given input is within the domain of the function but is beyond // the range for which calc can successfully compute the answer -#define CALC_E_INVALIDRANGE ((DWORD)0x80000006) +#define CALC_E_INVALIDRANGE ((uint32_t)0x80000006) // CALC_E_OUTOFMEMORY // // There is not enough free memory to complete the requested function -#define CALC_E_OUTOFMEMORY ((DWORD)0x80000007) +#define CALC_E_OUTOFMEMORY ((uint32_t)0x80000007) // CALC_E_OVERFLOW // // The result of this operation is an overflow -#define CALC_E_OVERFLOW ((DWORD)0x80000008) +#define CALC_E_OVERFLOW ((uint32_t)0x80000008) // CALC_E_NORESULT // // The result of this operation is undefined -#define CALC_E_NORESULT ((DWORD)0x80000009) +#define CALC_E_NORESULT ((uint32_t)0x80000009) diff --git a/src/CalcManager/Ratpack/basex.cpp b/src/CalcManager/Ratpack/basex.cpp index 1d4a7303..97a29dd4 100644 --- a/src/CalcManager/Ratpack/basex.cpp +++ b/src/CalcManager/Ratpack/basex.cpp @@ -48,7 +48,7 @@ void __inline mulnumx( PNUMBER *pa, PNUMBER b ) else { // if pa is one and b isn't just copy b. and adjust the sign. - long sign = (*pa)->sign; + int32_t sign = (*pa)->sign; DUPNUM(*pa,b); (*pa)->sign *= sign; } @@ -86,14 +86,14 @@ void _mulnumx( PNUMBER *pa, PNUMBER b ) MANTTYPE *ptrc; // ptrc is a pointer to the mantissa of c. MANTTYPE *ptrcoffset; // ptrcoffset, is the anchor location of the next // single digit multiply partial result. - long iadigit=0; // Index of digit being used in the first number. - long ibdigit=0; // Index of digit being used in the second number. + int32_t iadigit=0; // Index of digit being used in the first number. + int32_t ibdigit=0; // Index of digit being used in the second 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 // a multiplied row into the result. TWO_MANTTYPE mcy=0; // mcy is the resultant from a single // multiply, AND the carry of that multiply. - long icdigit=0; // Index of digit being calculated in final result. + int32_t icdigit=0; // Index of digit being calculated in final result. a=*pa; @@ -117,7 +117,7 @@ void _mulnumx( PNUMBER *pa, PNUMBER b ) for ( ibdigit = b->cdigit; ibdigit > 0; ibdigit-- ) { cy = 0; - mcy = (DWORDLONG)da * (*ptrb); + mcy = (uint64_t)da * (*ptrb); if ( mcy ) { icdigit = 0; @@ -132,10 +132,10 @@ void _mulnumx( PNUMBER *pa, PNUMBER b ) { // update carry from addition(s) and multiply. - cy += (TWO_MANTTYPE)ptrc[icdigit]+((DWORD)mcy&((DWORD)~BASEX)); + cy += (TWO_MANTTYPE)ptrc[icdigit]+((uint32_t)mcy&((uint32_t)~BASEX)); // update result digit from - ptrc[icdigit++]=(MANTTYPE)((DWORD)cy&((DWORD)~BASEX)); + ptrc[icdigit++]=(MANTTYPE)((uint32_t)cy&((uint32_t)~BASEX)); // update carries from mcy >>= BASEXPWR; @@ -160,9 +160,9 @@ void _mulnumx( PNUMBER *pa, PNUMBER b ) } //----------------------------------------------------------------------------- // -// FUNCTION: numpowlongx +// FUNCTION: numpowi32x // -// ARGUMENTS: root as number power as long +// ARGUMENTS: root as number power as int32_t // number. // // RETURN: None root is changed. @@ -174,10 +174,10 @@ void _mulnumx( PNUMBER *pa, PNUMBER b ) // //----------------------------------------------------------------------------- -void numpowlongx( _Inout_ PNUMBER *proot, _In_ long power ) +void numpowi32x( _Inout_ PNUMBER *proot, _In_ int32_t power ) { - PNUMBER lret = longtonum( 1, BASEX ); + PNUMBER lret = i32tonum( 1, BASEX ); // Once the power remaining is zero we are done. while ( power > 0 ) @@ -232,7 +232,7 @@ void __inline divnumx( PNUMBER *pa, PNUMBER b, int32_t precision) else { // if pa is one and b is not one, just copy b, and adjust the sign. - long sign = (*pa)->sign; + int32_t sign = (*pa)->sign; DUPNUM(*pa,b); (*pa)->sign *= sign; } @@ -266,10 +266,10 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision) // guesses one bit too far. PNUMBER tmp = nullptr; // current guess being worked on for divide. PNUMBER rem = nullptr; // remainder after applying guess. - long cdigits; // count of digits for answer. + int32_t cdigits; // count of digits for answer. MANTTYPE *ptrc; // ptrc is a pointer to the mantissa of c. - long thismax = precision + g_ratio; // set a maximum number of internal digits + int32_t thismax = precision + g_ratio; // set a maximum number of internal digits // to shoot for in the divide. a=*pa; @@ -301,14 +301,14 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision) while ( cdigits++ < thismax && !zernum(rem) ) { - long digit = 0; + int32_t digit = 0; *ptrc = 0; while ( !lessnum( rem, b ) ) { digit = 1; DUPNUM( tmp, b ); destroynum( lasttmp ); - lasttmp=longtonum( 0, BASEX ); + lasttmp=i32tonum( 0, BASEX ); while ( lessnum( tmp, rem ) ) { destroynum( lasttmp ); diff --git a/src/CalcManager/Ratpack/conv.cpp b/src/CalcManager/Ratpack/conv.cpp index ca69b844..88228019 100644 --- a/src/CalcManager/Ratpack/conv.cpp +++ b/src/CalcManager/Ratpack/conv.cpp @@ -11,7 +11,7 @@ // Description // // Contains conversion, input and output routines for numbers rationals -// and longs. +// and i32s. // // // @@ -29,12 +29,84 @@ static constexpr wstring_view DIGITS = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabc // ratio of internal 'digits' to output 'digits' // Calculated elsewhere as part of initialization and when base is changed -long g_ratio; // int(log(2L^BASEXPWR)/log(radix)) +int32_t g_ratio; // int(log(2L^BASEXPWR)/log(radix)) // Default decimal separator wchar_t g_decimalSeparator = L'.'; +// The following defines and Calc_ULong* functions were taken from +// https://github.com/dotnet/coreclr/blob/8b1595b74c943b33fa794e63e440e6f4c9679478/src/pal/inc/rt/intsafe.h +// under MIT License +#if defined(MIDL_PASS) || defined(RC_INVOKED) || defined(_M_CEE_PURE) \ + || defined(_M_AMD64) || defined(__ARM_ARCH) || defined(__x86_64__) + +#ifndef Calc_UInt32x32To64 +#define Calc_UInt32x32To64(a, b) ((uint64_t)((uint32_t)(a)) * (uint64_t)((uint32_t)(b))) +#endif + +#elif defined(_M_IX86) || defined(__i386__) + +#ifndef Calc_UInt32x32To64 +#define Calc_UInt32x32To64(a, b) (uint64_t)((uint64_t)(uint32_t)(a) * (uint32_t)(b)) +#endif +#else + +#error Must define a target architecture. + +#endif + +#define CALC_INTSAFE_E_ARITHMETIC_OVERFLOW ((int32_t)0x80070216L) // 0x216 = 534 = ERROR_ARITHMETIC_OVERFLOW +#define CALC_ULONG_ERROR ((uint32_t)0xffffffffU) + +namespace { + int32_t + Calc_ULongAdd( + _In_ uint32_t ulAugend, + _In_ uint32_t ulAddend, + _Out_ uint32_t* pulResult) + { + int32_t hr = CALC_INTSAFE_E_ARITHMETIC_OVERFLOW; + *pulResult = CALC_ULONG_ERROR; + + if ((ulAugend + ulAddend) >= ulAugend) + { + *pulResult = (ulAugend + ulAddend); + hr = S_OK; + } + + return hr; + } + + int32_t + Calc_ULongLongToULong( + _In_ uint64_t ullOperand, + _Out_ uint32_t* pulResult) + { + int32_t hr = CALC_INTSAFE_E_ARITHMETIC_OVERFLOW; + *pulResult = CALC_ULONG_ERROR; + + if (ullOperand <= UINT32_MAX) + { + *pulResult = (uint32_t)ullOperand; + hr = S_OK; + } + + return hr; + } + + int32_t + Calc_ULongMult( + _In_ uint32_t ulMultiplicand, + _In_ uint32_t ulMultiplier, + _Out_ uint32_t* pulResult) + { + uint64_t ull64Result = Calc_UInt32x32To64(ulMultiplicand, ulMultiplier); + + return Calc_ULongLongToULong(ull64Result, pulResult); + } +} + // Used to strip trailing zeros, and prevent combinatorial explosions -bool stripzeroesnum(_Inout_ PNUMBER pnum, long starting); +bool stripzeroesnum(_Inout_ PNUMBER pnum, int32_t starting); void SetDecimalSeparator(wchar_t decimalSeparator) { @@ -125,16 +197,16 @@ void _destroyrat( _In_ PRAT prat ) // //----------------------------------------------------------------------------- -PNUMBER _createnum( _In_ ULONG size ) +PNUMBER _createnum( _In_ uint32_t size ) { PNUMBER pnumret= nullptr; - ULONG cbAlloc; + uint32_t cbAlloc; // sizeof( MANTTYPE ) is the size of a 'digit' - if (SUCCEEDED(ULongAdd(size, 1, &cbAlloc)) && - SUCCEEDED(ULongMult(cbAlloc, sizeof(MANTTYPE), &cbAlloc)) && - SUCCEEDED(ULongAdd(cbAlloc, sizeof(NUMBER), &cbAlloc))) + if (SUCCEEDED(Calc_ULongAdd(size, 1, &cbAlloc)) && + SUCCEEDED(Calc_ULongMult(cbAlloc, sizeof(MANTTYPE), &cbAlloc)) && + SUCCEEDED(Calc_ULongAdd(cbAlloc, sizeof(NUMBER), &cbAlloc))) { pnumret = (PNUMBER)zmalloc( cbAlloc ); if ( pnumret == nullptr) @@ -203,7 +275,7 @@ PRAT numtorat( _In_ PNUMBER pin, uint32_t radix) PNUMBER pnRadixn= nullptr; DUPNUM( pnRadixn, pin ); - PNUMBER qnRadixn=longtonum( 1, radix); + PNUMBER qnRadixn=i32tonum( 1, radix); // Ensure p and q start out as integers. if ( pnRadixn->exp < 0 ) @@ -245,24 +317,24 @@ PRAT numtorat( _In_ PNUMBER pin, uint32_t radix) PNUMBER nRadixxtonum( _In_ PNUMBER a, uint32_t radix, int32_t precision) { - unsigned long bitmask; - unsigned long cdigits; + uint32_t bitmask; + uint32_t cdigits; MANTTYPE *ptr; - PNUMBER sum = longtonum( 0, radix ); - PNUMBER powofnRadix = longtonum( BASEX, radix ); + PNUMBER sum = i32tonum( 0, radix ); + PNUMBER powofnRadix = i32tonum( BASEX, radix ); // A large penalty is paid for conversion of digits no one will see anyway. // limit the digits to the minimum of the existing precision or the // requested precision. cdigits = precision + 1; - if ( cdigits > (unsigned long)a->cdigit ) + if ( cdigits > (uint32_t)a->cdigit ) { - cdigits = (unsigned long)a->cdigit; + cdigits = (uint32_t)a->cdigit; } // scale by the internal base to the internal exponent offset of the LSD - numpowlong( &powofnRadix, a->exp + (a->cdigit - cdigits), radix, precision); + numpowi32( &powofnRadix, a->exp + (a->cdigit - cdigits), radix, precision); // Loop over all the relative digits from MSD to LSD for ( ptr = &(a->mant[a->cdigit-1]); cdigits > 0; @@ -303,8 +375,8 @@ PNUMBER nRadixxtonum( _In_ PNUMBER a, uint32_t radix, int32_t precision) PNUMBER numtonRadixx(_In_ PNUMBER a, uint32_t radix) { - PNUMBER pnumret = longtonum(0, BASEX); // pnumret is the number in internal form. - PNUMBER num_radix = longtonum(radix, BASEX); + PNUMBER pnumret = i32tonum(0, BASEX); // pnumret is the number in internal form. + PNUMBER num_radix = i32tonum(radix, BASEX); MANTTYPE *ptrdigit = a->mant; // pointer to digit being worked on. // Digits are in reverse order, back over them LSD first. @@ -312,20 +384,20 @@ PNUMBER numtonRadixx(_In_ PNUMBER a, uint32_t radix) PNUMBER thisdigit = nullptr; // thisdigit holds the current digit of a // being summed into result. - long idigit; // idigit is the iterate of digits in a. + int32_t idigit; // idigit is the iterate of digits in a. for ( idigit = 0; idigit < a->cdigit; idigit++ ) { mulnumx( &pnumret, num_radix); // WARNING: // This should just smack in each digit into a 'special' thisdigit. // and not do the overhead of recreating the number type each time. - thisdigit = longtonum( *ptrdigit--, BASEX ); + thisdigit = i32tonum( *ptrdigit--, BASEX ); addnum( &pnumret, thisdigit, BASEX ); destroynum( thisdigit ); } // Calculate the exponent of the external base for scaling. - numpowlongx( &num_radix, a->exp ); + numpowi32x( &num_radix, a->exp ); // ... and scale the result. mulnumx( &pnumret, num_radix); @@ -391,7 +463,7 @@ PRAT StringToRat(bool mantissaIsNegative, wstring_view mantissa, bool exponentIs } // Deal with exponent - long expt = 0; + int32_t expt = 0; if (!exponent.empty()) { // Exponent specified, convert to number form. @@ -404,18 +476,18 @@ PRAT StringToRat(bool mantissaIsNegative, wstring_view mantissa, bool exponentIs } // Convert exponent number form to native integral form, and cleanup. - expt = numtolong(numExp, radix); + expt = numtoi32(numExp, radix); destroynum(numExp); } // Convert native integral exponent form to rational multiplier form. - PNUMBER pnumexp = longtonum(radix, BASEX); - numpowlongx(&pnumexp, abs(expt)); + PNUMBER pnumexp = i32tonum(radix, BASEX); + numpowi32x(&pnumexp, abs(expt)); PRAT pratexp = nullptr; createrat(pratexp); DUPNUM(pratexp->pp, pnumexp); - pratexp->pq = longtonum(1, BASEX); + pratexp->pq = i32tonum(1, BASEX); destroynum(pnumexp); if (exponentIsNegative) @@ -574,11 +646,11 @@ wchar_t NormalizeCharDigit(wchar_t c, uint32_t radix) PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precision) { - long expSign = 1L; // expSign is exponent sign ( +/- 1 ) - long expValue = 0L; // expValue is exponent mantissa, should be unsigned + int32_t expSign = 1L; // expSign is exponent sign ( +/- 1 ) + int32_t expValue = 0L; // expValue is exponent mantissa, should be unsigned PNUMBER pnumret = nullptr; - createnum(pnumret, static_cast(numberString.length())); + createnum(pnumret, static_cast(numberString.length())); pnumret->sign = 1L; pnumret->cdigit = 0; pnumret->exp = 0; @@ -637,7 +709,7 @@ PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precis if (pos != wstring_view::npos) { expValue *= radix; - expValue += static_cast(pos); + expValue += static_cast(pos); } else { @@ -683,7 +755,7 @@ PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precis } else { - while (pnumret->cdigit < static_cast(numberString.length())) + while (pnumret->cdigit < static_cast(numberString.length())) { pnumret->cdigit++; pnumret->exp--; @@ -706,65 +778,65 @@ PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precis //----------------------------------------------------------------------------- // -// FUNCTION: longtorat +// FUNCTION: i32torat // -// ARGUMENTS: long +// ARGUMENTS: int32_t // -// RETURN: Rational representation of long input. +// RETURN: Rational representation of int32_t input. // -// DESCRIPTION: Converts long input to rational (p over q) -// form, where q is 1 and p is the long. +// DESCRIPTION: Converts int32_t input to rational (p over q) +// form, where q is 1 and p is the int32_t. // //----------------------------------------------------------------------------- -PRAT longtorat( _In_ long inlong ) +PRAT i32torat( _In_ int32_t ini32 ) { PRAT pratret= nullptr; createrat( pratret ); - pratret->pp = longtonum(inlong, BASEX ); - pratret->pq = longtonum(1L, BASEX ); + pratret->pp = i32tonum(ini32, BASEX ); + pratret->pq = i32tonum(1L, BASEX ); return( pratret ); } //----------------------------------------------------------------------------- // -// FUNCTION: Ulongtorat +// FUNCTION: Ui32torat // -// ARGUMENTS: ulong +// ARGUMENTS: ui32 // -// RETURN: Rational representation of unsigned long input. +// RETURN: Rational representation of uint32_t input. // -// DESCRIPTION: Converts unsigned long input to rational (p over q) -// form, where q is 1 and p is the unsigned long. Being unsigned cant take negative +// DESCRIPTION: Converts uint32_t input to rational (p over q) +// form, where q is 1 and p is the uint32_t. Being unsigned cant take negative // numbers, but the full range of unsigned numbers // //----------------------------------------------------------------------------- -PRAT Ulongtorat( _In_ unsigned long inulong ) +PRAT Ui32torat( _In_ uint32_t inui32 ) { PRAT pratret= nullptr; createrat( pratret ); - pratret->pp = Ulongtonum(inulong, BASEX ); - pratret->pq = longtonum(1L, BASEX ); + pratret->pp = Ui32tonum(inui32, BASEX ); + pratret->pq = i32tonum(1L, BASEX ); return( pratret ); } //----------------------------------------------------------------------------- // -// FUNCTION: longtonum +// FUNCTION: i32tonum // -// ARGUMENTS: long input and radix requested. +// ARGUMENTS: int32_t input and radix requested. // // RETURN: number // // DESCRIPTION: Returns a number representation in the -// base requested of the long value passed in. +// base requested of the int32_t value passed in. // //----------------------------------------------------------------------------- -PNUMBER longtonum( long inlong, uint32_t radix) +PNUMBER i32tonum( int32_t ini32, uint32_t radix) { MANTTYPE *pmant; @@ -774,10 +846,10 @@ PNUMBER longtonum( long inlong, uint32_t radix) pmant = pnumret->mant; pnumret->cdigit = 0; pnumret->exp = 0; - if ( inlong < 0 ) + if ( ini32 < 0 ) { pnumret->sign = -1; - inlong *= -1; + ini32 *= -1; } else { @@ -785,30 +857,30 @@ PNUMBER longtonum( long inlong, uint32_t radix) } do { - *pmant++ = (MANTTYPE)(inlong % radix); - inlong /= radix; + *pmant++ = (MANTTYPE)(ini32 % radix); + ini32 /= radix; pnumret->cdigit++; - } while ( inlong ); + } while ( ini32 ); return( pnumret ); } //----------------------------------------------------------------------------- // -// FUNCTION: Ulongtonum +// FUNCTION: Ui32tonum // -// ARGUMENTS: ULONG input and radix requested. +// ARGUMENTS: uint32_t input and radix requested. // // RETURN: number // // DESCRIPTION: Returns a number representation in the -// base requested of the unsigned long value passed in. Being unsigned number it has no +// base requested of the uint32_t value passed in. Being unsigned number it has no // negative number and takes the full range of unsigned number // //----------------------------------------------------------------------------- -PNUMBER Ulongtonum(unsigned long inlong, uint32_t radix) +PNUMBER Ui32tonum(uint32_t ini32, uint32_t radix) { MANTTYPE *pmant; PNUMBER pnumret= nullptr; @@ -820,10 +892,10 @@ PNUMBER Ulongtonum(unsigned long inlong, uint32_t radix) pnumret->sign = 1; do { - *pmant++ = (MANTTYPE)(inlong % radix); - inlong /= radix; + *pmant++ = (MANTTYPE)(ini32 % radix); + ini32 /= radix; pnumret->cdigit++; - } while ( inlong ); + } while ( ini32 ); return( pnumret ); } @@ -831,23 +903,23 @@ PNUMBER Ulongtonum(unsigned long inlong, uint32_t radix) //----------------------------------------------------------------------------- // -// FUNCTION: rattolong +// FUNCTION: rattoi32 // // ARGUMENTS: rational number in internal base, integer radix and int32_t precision. // -// RETURN: long +// RETURN: int32_t // -// DESCRIPTION: returns the long representation of the +// DESCRIPTION: returns the int32_t representation of the // number input. Assumes that the number is in the internal // base. // //----------------------------------------------------------------------------- -long rattolong( _In_ PRAT prat , uint32_t radix, int32_t precision) +int32_t rattoi32( _In_ PRAT prat , uint32_t radix, int32_t precision) { - if ( rat_gt( prat, rat_max_long, precision) || rat_lt( prat, rat_min_long, precision) ) + if ( rat_gt( prat, rat_max_i32, precision) || rat_lt( prat, rat_min_i32, precision) ) { - // Don't attempt rattolong of anything too big or small + // Don't attempt rattoi32 of anything too big or small throw( CALC_E_DOMAIN ); } @@ -858,7 +930,7 @@ long rattolong( _In_ PRAT prat , uint32_t radix, int32_t precision) divnumx( &(pint->pp), pint->pq, precision); DUPNUM( pint->pq, num_one ); - long lret = numtolong( pint->pp, BASEX ); + int32_t lret = numtoi32( pint->pp, BASEX ); destroyrat(pint); @@ -867,22 +939,22 @@ long rattolong( _In_ PRAT prat , uint32_t radix, int32_t precision) //----------------------------------------------------------------------------- // -// FUNCTION: rattoUlong +// FUNCTION: rattoUi32 // // ARGUMENTS: rational number in internal base, integer radix and int32_t precision. // -// RETURN: Ulong +// RETURN: Ui32 // -// DESCRIPTION: returns the Ulong representation of the +// DESCRIPTION: returns the Ui32 representation of the // number input. Assumes that the number is in the internal // base. // //----------------------------------------------------------------------------- -unsigned long rattoUlong( _In_ PRAT prat, uint32_t radix, int32_t precision) +uint32_t rattoUi32( _In_ PRAT prat, uint32_t radix, int32_t precision) { if ( rat_gt( prat, rat_dword, precision) || rat_lt( prat, rat_zero, precision) ) { - // Don't attempt rattoulong of anything too big or small + // Don't attempt rattoui32 of anything too big or small throw( CALC_E_DOMAIN ); } @@ -893,7 +965,7 @@ unsigned long rattoUlong( _In_ PRAT prat, uint32_t radix, int32_t precision) divnumx( &(pint->pp), pint->pq, precision); DUPNUM( pint->pq, num_one ); - unsigned long lret = numtolong( pint->pp, BASEX ); // This happens to work even if it is only signed + uint32_t lret = numtoi32( pint->pp, BASEX ); // This happens to work even if it is only signed destroyrat(pint); @@ -903,11 +975,11 @@ unsigned long rattoUlong( _In_ PRAT prat, uint32_t radix, int32_t precision) //----------------------------------------------------------------------------- // -// FUNCTION: rattoUlonglong +// FUNCTION: rattoUi64 // // ARGUMENTS: rational number in internal base, integer radix and int32_t precision // -// RETURN: Ulonglong +// RETURN: Ui64 // // DESCRIPTION: returns the 64 bit (irrespective of which processor this is running in) representation of the // number input. Assumes that the number is in the internal @@ -916,50 +988,50 @@ unsigned long rattoUlong( _In_ PRAT prat, uint32_t radix, int32_t precision) // internal base chosen happens to be 2^32, this is easier. //----------------------------------------------------------------------------- -ULONGLONG rattoUlonglong( _In_ PRAT prat, uint32_t radix, int32_t precision) +uint64_t rattoUi64( _In_ PRAT prat, uint32_t radix, int32_t precision) { PRAT pint = nullptr; // first get the LO 32 bit word DUPRAT(pint, prat); andrat(&pint, rat_dword, radix, precision); // & 0xFFFFFFFF (2 ^ 32 -1) - unsigned long lo = rattoUlong(pint, radix, precision); // wont throw exception because already hi-dword chopped off + uint32_t lo = rattoUi32(pint, radix, precision); // wont throw exception because already hi-dword chopped off DUPRAT(pint, prat); // previous pint will get freed by this as well - PRAT prat32 = longtorat(32); + PRAT prat32 = i32torat(32); rshrat(&pint, prat32, radix, precision); intrat( &pint, radix, precision); andrat(&pint, rat_dword, radix, precision); // & 0xFFFFFFFF (2 ^ 32 -1) - unsigned long hi = rattoUlong(pint, radix, precision); + uint32_t hi = rattoUi32(pint, radix, precision); destroyrat(prat32); destroyrat(pint); - return (((ULONGLONG)hi << 32) | lo); + return (((uint64_t)hi << 32) | lo); } //----------------------------------------------------------------------------- // -// FUNCTION: numtolong +// FUNCTION: numtoi32 // // ARGUMENTS: number input and base of that number. // -// RETURN: long +// RETURN: int32_t // -// DESCRIPTION: returns the long representation of the +// DESCRIPTION: returns the int32_t representation of the // number input. Assumes that the number is really in the // base claimed. // //----------------------------------------------------------------------------- -long numtolong( _In_ PNUMBER pnum, uint32_t radix ) +int32_t numtoi32( _In_ PNUMBER pnum, uint32_t radix ) { - long lret = 0; + int32_t lret = 0; MANTTYPE *pmant = pnum->mant; pmant += pnum->cdigit - 1; - long expt = pnum->exp; - for (long length = pnum->cdigit; length > 0 && length + expt > 0; length--) + int32_t expt = pnum->exp; + for (int32_t length = pnum->cdigit; length > 0 && length + expt > 0; length--) { lret *= radix; lret += *(pmant--); @@ -986,10 +1058,10 @@ long numtolong( _In_ PNUMBER pnum, uint32_t radix ) // //----------------------------------------------------------------------------- -bool stripzeroesnum(_Inout_ PNUMBER pnum, long starting) +bool stripzeroesnum(_Inout_ PNUMBER pnum, int32_t starting) { MANTTYPE *pmant; - long cdigits; + int32_t cdigits; bool fstrip = false; // point pmant to the LeastCalculatedDigit @@ -1042,10 +1114,10 @@ bool stripzeroesnum(_Inout_ PNUMBER pnum, long starting) wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_t precision) { stripzeroesnum(pnum, precision + 2); - long length = pnum->cdigit; - long exponent = pnum->exp + length; // Actual number of digits to the left of decimal + int32_t length = pnum->cdigit; + int32_t exponent = pnum->exp + length; // Actual number of digits to the left of decimal - long oldFormat = format; + int32_t oldFormat = format; if (exponent > precision && format == FMT_FLOAT) { // Force scientific mode to prevent user from assuming 33rd digit is exact. @@ -1065,7 +1137,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_ if (!zernum(pnum) && (pnum->cdigit >= precision || (length - exponent > precision && exponent >= -MAX_ZEROS_AFTER_DECIMAL))) { // Otherwise round. - round = longtonum(radix, radix); + round = i32tonum(radix, radix); divnum(&round, num_two, radix, precision); // Make round number exponent one below the LSD for the number. @@ -1110,7 +1182,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_ if (round != nullptr) { addnum(&pnum, round, radix); - long offset = (pnum->cdigit + pnum->exp) - (round->cdigit + round->exp); + int32_t offset = (pnum->cdigit + pnum->exp) - (round->cdigit + round->exp); destroynum(round); if (stripzeroesnum(pnum, offset)) { @@ -1126,7 +1198,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_ // Set up all the post rounding stuff. bool useSciForm = false; - long eout = exponent - 1; // Displayed exponent. + int32_t eout = exponent - 1; // Displayed exponent. MANTTYPE *pmant = pnum->mant + pnum->cdigit - 1; // Case where too many digits are to the left of the decimal or // FMT_SCIENTIFIC or FMT_ENGINEERING was specified. @@ -1240,7 +1312,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_ // // ARGUMENTS: // PRAT *representation of a number. -// long representation of base to dump to screen. +// i32 representation of base to dump to screen. // fmt, one of FMT_FLOAT FMT_SCIENTIFIC or FMT_ENGINEERING // precision uint32_t // @@ -1270,8 +1342,8 @@ PNUMBER RatToNumber(_In_ PRAT prat, uint32_t radix, int32_t precision) DUPRAT(temprat, prat); // Convert p and q of rational form from internal base to requested base. // Scale by largest power of BASEX possible. - long scaleby = min(temprat->pp->exp, temprat->pq->exp); - scaleby = max(scaleby, 0l); + int32_t scaleby = min(temprat->pp->exp, temprat->pq->exp); + scaleby = max(scaleby, 0); temprat->pp->exp -= scaleby; temprat->pq->exp -= scaleby; @@ -1359,12 +1431,12 @@ PNUMBER gcd( _In_ PNUMBER a, _In_ PNUMBER b) //----------------------------------------------------------------------------- // -// FUNCTION: longfactnum +// FUNCTION: i32factnum // // ARGUMENTS: -// long integer to factorialize. -// long integer representing base of answer. -// unsigned long integer for radix +// int32_t integer to factorialize. +// int32_t integer representing base of answer. +// uint32_t integer for radix // // RETURN: Factorial of input in radix PNUMBER form. // @@ -1372,17 +1444,17 @@ PNUMBER gcd( _In_ PNUMBER a, _In_ PNUMBER b) // //----------------------------------------------------------------------------- -PNUMBER longfactnum(long inlong, uint32_t radix) +PNUMBER i32factnum(int32_t ini32, uint32_t radix) { PNUMBER lret= nullptr; PNUMBER tmp= nullptr; - lret = longtonum( 1, radix); + lret = i32tonum( 1, radix); - while ( inlong > 0 ) + while ( ini32 > 0 ) { - tmp = longtonum( inlong--, radix); + tmp = i32tonum( ini32--, radix); mulnum( &lret, tmp, radix); destroynum( tmp ); } @@ -1391,30 +1463,30 @@ PNUMBER longfactnum(long inlong, uint32_t radix) //----------------------------------------------------------------------------- // -// FUNCTION: longprodnum +// FUNCTION: i32prodnum // // ARGUMENTS: -// long integer to factorialize. -// long integer representing base of answer. -// unsigned long integer for radix +// int32_t integer to factorialize. +// int32_t integer representing base of answer. +// uint32_t integer for radix // // RETURN: Factorial of input in base PNUMBER form. // //----------------------------------------------------------------------------- -PNUMBER longprodnum(long start, long stop, uint32_t radix) +PNUMBER i32prodnum(int32_t start, int32_t stop, uint32_t radix) { PNUMBER lret= nullptr; PNUMBER tmp= nullptr; - lret = longtonum( 1, radix); + lret = i32tonum( 1, radix); while ( start <= stop ) { if ( start ) { - tmp = longtonum( start, radix); + tmp = i32tonum( start, radix); mulnum( &lret, tmp, radix); destroynum( tmp ); } @@ -1425,10 +1497,10 @@ PNUMBER longprodnum(long start, long stop, uint32_t radix) //----------------------------------------------------------------------------- // -// FUNCTION: numpowlong +// FUNCTION: numpowi32 // -// ARGUMENTS: root as number power as long and radix of -// number along with the precision value in long. +// ARGUMENTS: root as number power as int32_t and radix of +// number along with the precision value in int32_t. // // RETURN: None root is changed. // @@ -1437,9 +1509,9 @@ PNUMBER longprodnum(long start, long stop, uint32_t radix) // //----------------------------------------------------------------------------- -void numpowlong( _Inout_ PNUMBER *proot, long power, uint32_t radix, int32_t precision) +void numpowi32( _Inout_ PNUMBER *proot, int32_t power, uint32_t radix, int32_t precision) { - PNUMBER lret = longtonum( 1, radix ); + PNUMBER lret = i32tonum( 1, radix ); while ( power > 0 ) { @@ -1458,9 +1530,9 @@ void numpowlong( _Inout_ PNUMBER *proot, long power, uint32_t radix, int32_t pre //----------------------------------------------------------------------------- // -// FUNCTION: ratpowlong +// FUNCTION: ratpowi32 // -// ARGUMENTS: root as rational, power as long and precision as uint32_t. +// ARGUMENTS: root as rational, power as int32_t and precision as int32_t. // // RETURN: None root is changed. // @@ -1469,14 +1541,14 @@ void numpowlong( _Inout_ PNUMBER *proot, long power, uint32_t radix, int32_t pre // //----------------------------------------------------------------------------- -void ratpowlong( _Inout_ PRAT *proot, long power, int32_t precision) +void ratpowi32( _Inout_ PRAT *proot, int32_t power, int32_t precision) { if ( power < 0 ) { // Take the positive power and invert answer. PNUMBER pnumtemp = nullptr; - ratpowlong( proot, -power, precision); + ratpowi32( proot, -power, precision); pnumtemp = (*proot)->pp; (*proot)->pp = (*proot)->pq; (*proot)->pq = pnumtemp; @@ -1485,7 +1557,7 @@ void ratpowlong( _Inout_ PRAT *proot, long power, int32_t precision) { PRAT lret= nullptr; - lret = longtorat( 1 ); + lret = i32torat( 1 ); while ( power > 0 ) { diff --git a/src/CalcManager/Ratpack/exp.cpp b/src/CalcManager/Ratpack/exp.cpp index 8e0e58af..c8691cfa 100644 --- a/src/CalcManager/Ratpack/exp.cpp +++ b/src/CalcManager/Ratpack/exp.cpp @@ -50,7 +50,7 @@ void _exprat( PRAT *px, int32_t precision) addnum(&(pret->pq),num_one, BASEX); DUPRAT(thisterm,pret); - n2=longtonum(0L, BASEX); + n2=i32tonum(0L, BASEX); do { NEXTTERM(*px, INC(n2) DIVNUM(n2), precision); @@ -64,7 +64,7 @@ void exprat( PRAT *px, uint32_t radix, int32_t precision) { PRAT pwr= nullptr; PRAT pint= nullptr; - long intpwr; + int32_t intpwr; if ( rat_gt( *px, rat_max_exp, precision) || rat_lt( *px, rat_min_exp, precision) ) { @@ -77,8 +77,8 @@ void exprat( PRAT *px, uint32_t radix, int32_t precision) intrat(&pint, radix, precision); - intpwr = rattolong(pint, radix, precision); - ratpowlong( &pwr, intpwr, precision); + intpwr = rattoi32(pint, radix, precision); + ratpowi32( &pwr, intpwr, precision); subrat(px, pint, precision); @@ -140,7 +140,7 @@ void _lograt( PRAT *px, int32_t precision) DUPRAT(pret,*px); DUPRAT(thisterm,*px); - n2=longtonum(1L, BASEX); + n2=i32tonum(1L, BASEX); (*px)->pp->sign *= -1; do { @@ -183,10 +183,10 @@ void lograt( PRAT *px, int32_t precision) { // Take advantage of px's base BASEX to scale quickly down to // a reasonable range. - long intpwr; + int32_t intpwr; intpwr=LOGRAT2(*px)-1; (*px)->pq->exp += intpwr; - pwr=longtorat(intpwr*BASEXPWR); + pwr=i32torat(intpwr*BASEXPWR); mulrat(&pwr, ln_two, precision); // ln(x+e)-ln(x) looks close to e when x is close to one using some // expansions. This means we can trim past precision digits+1. @@ -309,7 +309,7 @@ void powratNumeratorDenominator(PRAT *px, PRAT y, uint32_t radix, int32_t precis // Calculate the following use the Powers of Powers rule: // px ^ (yNum/yDenom) == px ^ yNum ^ (1/yDenom) - // 1. For px ^ yNum, we call powratcomp directly which will call ratpowlong + // 1. For px ^ yNum, we call powratcomp directly which will call ratpowi32 // and store the result in pxPowNum // 2. For pxPowNum ^ (1/yDenom), we call powratcomp // 3. Validate the result of 2 by adding/subtracting 0.5, flooring and call powratcomp with yDenom @@ -408,7 +408,7 @@ void powratNumeratorDenominator(PRAT *px, PRAT y, uint32_t radix, int32_t precis //--------------------------------------------------------------------------- void powratcomp(PRAT *px, PRAT y, uint32_t radix, int32_t precision) { - long sign = ((*px)->pp->sign * (*px)->pq->sign); + int32_t sign = ((*px)->pp->sign * (*px)->pq->sign); // Take the absolute value (*px)->pp->sign = 1; @@ -451,12 +451,12 @@ void powratcomp(PRAT *px, PRAT y, uint32_t radix, int32_t precision) fracrat(&podd, radix, precision); if ( rat_gt( podd, rat_negsmallest, precision) && rat_lt( podd, rat_smallest, precision) ) { - // If power is an integer let ratpowlong deal with it. + // If power is an integer let ratpowi32 deal with it. PRAT iy = nullptr; - long inty; + int32_t inty; DUPRAT(iy,y); subrat(&iy, podd, precision); - inty = rattolong(iy, radix, precision); + inty = rattoi32(iy, radix, precision); PRAT plnx = nullptr; DUPRAT(plnx,*px); @@ -472,7 +472,7 @@ void powratcomp(PRAT *px, PRAT y, uint32_t radix, int32_t precision) throw( CALC_E_DOMAIN ); } destroyrat(plnx); - ratpowlong(px, inty, precision); + ratpowi32(px, inty, precision); if ( ( inty & 1 ) == 0 ) { sign=1; diff --git a/src/CalcManager/Ratpack/fact.cpp b/src/CalcManager/Ratpack/fact.cpp index 1a992bc0..c974b005 100644 --- a/src/CalcManager/Ratpack/fact.cpp +++ b/src/CalcManager/Ratpack/fact.cpp @@ -72,14 +72,14 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision) PRAT mpy= nullptr; PRAT ratprec = nullptr; PRAT ratRadix = nullptr; - long oldprec; + int32_t oldprec; // Set up constants and initial conditions oldprec = precision; - ratprec = longtorat( oldprec ); + ratprec = i32torat( oldprec ); // Find the best 'A' for convergence to the required precision. - a=longtorat( radix ); + a=i32torat( radix ); lograt(&a, precision); mulrat(&a, ratprec, precision); @@ -96,7 +96,7 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision) // The following code is equivalent to // precision += ln(exp(a)*pow(a,n+1.5))-ln(radix)); DUPRAT(tmp,*pn); - one_pt_five=longtorat( 3L ); + one_pt_five=i32torat( 3L ); divrat( &one_pt_five, rat_two, precision); addrat( &tmp, one_pt_five, precision); DUPRAT(term,a); @@ -105,15 +105,15 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision) exprat( &tmp, radix, precision); mulrat( &term, tmp, precision); lograt( &term, precision); - ratRadix = longtorat(radix); + ratRadix = i32torat(radix); DUPRAT(tmp,ratRadix); lograt( &tmp, precision); subrat( &term, tmp, precision); - precision += rattolong( term, radix, precision); + precision += rattoi32( term, radix, precision); // Set up initial terms for series, refer to series in above comment block. DUPRAT(factorial,rat_one); // Start factorial out with one - count = longtonum( 0L, BASEX ); + count = i32tonum( 0L, BASEX ); DUPRAT(mpy,a); powratcomp(&mpy,*pn, radix, precision); diff --git a/src/CalcManager/Ratpack/itrans.cpp b/src/CalcManager/Ratpack/itrans.cpp index ef687b93..1ecbf4a1 100644 --- a/src/CalcManager/Ratpack/itrans.cpp +++ b/src/CalcManager/Ratpack/itrans.cpp @@ -92,7 +92,7 @@ void asinanglerat( _Inout_ PRAT *pa, ANGLE_TYPE angletype, uint32_t radix, int32 void asinrat( PRAT *px, uint32_t radix, int32_t precision) { - long sgn; + int32_t sgn; PRAT pret= nullptr; PRAT phack= nullptr; @@ -186,8 +186,8 @@ void _acosrat( PRAT *px, int32_t precision) CREATETAYLOR(); createrat(thisterm); - thisterm->pp=longtonum( 1L, BASEX ); - thisterm->pq=longtonum( 1L, BASEX ); + thisterm->pp=i32tonum( 1L, BASEX ); + thisterm->pq=i32tonum( 1L, BASEX ); DUPNUM(n2,num_one); @@ -204,7 +204,7 @@ void _acosrat( PRAT *px, int32_t precision) void acosrat( PRAT *px, uint32_t radix, int32_t precision) { - long sgn; + int32_t sgn; sgn = (*px)->pp->sign*(*px)->pq->sign; @@ -291,7 +291,7 @@ void _atanrat( PRAT *px, int32_t precision) void atanrat( PRAT *px, uint32_t radix, int32_t precision) { - long sgn; + int32_t sgn; PRAT tmpx= nullptr; sgn = (*px)->pp->sign * (*px)->pq->sign; diff --git a/src/CalcManager/Ratpack/logic.cpp b/src/CalcManager/Ratpack/logic.cpp index c4c26330..c7f8a3a3 100644 --- a/src/CalcManager/Ratpack/logic.cpp +++ b/src/CalcManager/Ratpack/logic.cpp @@ -22,7 +22,7 @@ void lshrat( PRAT *pa, PRAT b, uint32_t radix, int32_t precision) { PRAT pwr= nullptr; - long intb; + int32_t intb; intrat(pa, radix, precision); if ( !zernum( (*pa)->pp ) ) @@ -33,9 +33,9 @@ void lshrat( PRAT *pa, PRAT b, uint32_t radix, int32_t precision) // Don't attempt lsh of anything big throw( CALC_E_DOMAIN ); } - intb = rattolong(b, radix, precision); + intb = rattoi32(b, radix, precision); DUPRAT(pwr,rat_two); - ratpowlong(&pwr, intb, precision); + ratpowi32(&pwr, intb, precision); mulrat(pa, pwr, precision); destroyrat(pwr); } @@ -45,7 +45,7 @@ void rshrat( PRAT *pa, PRAT b, uint32_t radix, int32_t precision) { PRAT pwr= nullptr; - long intb; + int32_t intb; intrat(pa, radix, precision); if ( !zernum( (*pa)->pp ) ) @@ -56,9 +56,9 @@ void rshrat( PRAT *pa, PRAT b, uint32_t radix, int32_t precision) // Don't attempt rsh of anything big and negative. throw( CALC_E_DOMAIN ); } - intb = rattolong(b, radix, precision); + intb = rattoi32(b, radix, precision); DUPRAT(pwr,rat_two); - ratpowlong(&pwr, intb, precision); + ratpowi32(&pwr, intb, precision); divrat(pa, pwr, precision); destroyrat(pwr); } @@ -138,8 +138,8 @@ void boolnum( PNUMBER *pa, PNUMBER b, int func ) MANTTYPE *pcha; MANTTYPE *pchb; MANTTYPE *pchc; - long cdigits; - long mexp; + int32_t cdigits; + int32_t mexp; MANTTYPE da; MANTTYPE db; diff --git a/src/CalcManager/Ratpack/num.cpp b/src/CalcManager/Ratpack/num.cpp index 817fe02c..2bfa6b89 100644 --- a/src/CalcManager/Ratpack/num.cpp +++ b/src/CalcManager/Ratpack/num.cpp @@ -66,14 +66,14 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix) MANTTYPE *pcha; // pcha is a pointer to the mantissa of a. MANTTYPE *pchb; // pchb is a pointer to the mantissa of b. MANTTYPE *pchc; // pchc is a pointer to the mantissa of c. - long cdigits; // cdigits is the max count of the digits results + int32_t cdigits; // cdigits is the max count of the digits results // used as a counter. - long mexp; // mexp is the exponent of the result. + int32_t mexp; // mexp is the exponent of the result. MANTTYPE da; // da is a single 'digit' after possible padding. MANTTYPE db; // db is a single 'digit' after possible padding. MANTTYPE cy=0; // cy is the value of a carry after adding two 'digits' - long fcompla = 0; // fcompla is a flag to signal a is negative. - long fcomplb = 0; // fcomplb is a flag to signal b is negative. + int32_t fcompla = 0; // fcompla is a flag to signal a is negative. + int32_t fcomplb = 0; // fcomplb is a flag to signal b is negative. a=*pa; @@ -205,7 +205,7 @@ void __inline mulnum( PNUMBER *pa, PNUMBER b, uint32_t radix) } else { // if pa is one and b isn't just copy b, and adjust the sign. - long sign = (*pa)->sign; + int32_t sign = (*pa)->sign; DUPNUM(*pa,b); (*pa)->sign *= sign; } @@ -226,14 +226,14 @@ void _mulnum( PNUMBER *pa, PNUMBER b, uint32_t radix) MANTTYPE *pchc; // pchc is a pointer to the mantissa of c. MANTTYPE *pchcoffset; // pchcoffset, is the anchor location of the next // single digit multiply partial result. - long iadigit = 0; // Index of digit being used in the first number. - long ibdigit = 0; // Index of digit being used in the second number. + int32_t iadigit = 0; // Index of digit being used in the first number. + int32_t ibdigit = 0; // Index of digit being used in the second 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 // a multiplied row into the result. TWO_MANTTYPE mcy = 0; // mcy is the resultant from a single // multiply, AND the carry of that multiply. - long icdigit = 0; // Index of digit being calculated in final result. + int32_t icdigit = 0; // Index of digit being calculated in final result. a=*pa; ibdigit = a->cdigit + b->cdigit - 1; @@ -334,7 +334,7 @@ void remnum( PNUMBER *pa, PNUMBER b, uint32_t radix) } destroynum( lasttmp ); - lasttmp=longtonum( 0, radix); + lasttmp=i32tonum( 0, radix); while ( lessnum( tmp, *pa ) ) { @@ -394,7 +394,7 @@ void __inline divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision) void _divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision) { PNUMBER a = *pa; - long thismax = precision + 2; + int32_t thismax = precision + 2; if (thismax < a->cdigit) { thismax = a->cdigit; @@ -420,8 +420,8 @@ void _divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision) // Build a table of multiplications of the divisor, this is quicker for // more than radix 'digits' - list numberList{ longtonum(0L, radix) }; - for (unsigned long i = 1; i < radix; i++) + list numberList{ i32tonum(0L, radix) }; + for (uint32_t i = 1; i < radix; i++) { PNUMBER newValue = nullptr; DUPNUM(newValue, numberList.front()); @@ -431,8 +431,8 @@ void _divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision) } destroynum(tmp); - long digit; - long cdigits = 0; + int32_t digit; + int32_t cdigits = 0; while (cdigits++ < thismax && !zernum(rem)) { digit = radix - 1; @@ -505,11 +505,11 @@ void _divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision) bool equnum( PNUMBER a, PNUMBER b ) { - long diff; + int32_t diff; MANTTYPE *pa; MANTTYPE *pb; - long cdigits; - long ccdigits; + int32_t cdigits; + int32_t ccdigits; MANTTYPE da; MANTTYPE db; @@ -573,11 +573,11 @@ bool equnum( PNUMBER a, PNUMBER b ) bool lessnum( PNUMBER a, PNUMBER b ) { - long diff; + int32_t diff; MANTTYPE *pa; MANTTYPE *pb; - long cdigits; - long ccdigits; + int32_t cdigits; + int32_t ccdigits; MANTTYPE da; MANTTYPE db; @@ -635,7 +635,7 @@ bool lessnum( PNUMBER a, PNUMBER b ) bool zernum( PNUMBER a ) { - long length; + int32_t length; MANTTYPE *pcha; length = a->cdigit; pcha = a->mant; diff --git a/src/CalcManager/Ratpack/ratconst.h b/src/CalcManager/Ratpack/ratconst.h index be24b002..7367cd36 100644 --- a/src/CalcManager/Ratpack/ratconst.h +++ b/src/CalcManager/Ratpack/ratconst.h @@ -325,26 +325,26 @@ inline const NUMBER init_q_rat_dword = { { 1,} }; // Autogenerated by _dumprawrat in support.cpp -inline const NUMBER init_p_rat_max_long = { +inline const NUMBER init_p_rat_max_i32 = { 1, 1, 0, { 2147483647,} }; -inline const NUMBER init_q_rat_max_long = { +inline const NUMBER init_q_rat_max_i32 = { 1, 1, 0, { 1,} }; // Autogenerated by _dumprawrat in support.cpp -inline const NUMBER init_p_rat_min_long = { +inline const NUMBER init_p_rat_min_i32 = { -1, 2, 0, { 0, 1,} }; -inline const NUMBER init_q_rat_min_long = { +inline const NUMBER init_q_rat_min_i32 = { 1, 1, 0, diff --git a/src/CalcManager/Ratpack/ratpak.h b/src/CalcManager/Ratpack/ratpak.h index 914682ca..75ac28de 100644 --- a/src/CalcManager/Ratpack/ratpak.h +++ b/src/CalcManager/Ratpack/ratpak.h @@ -24,8 +24,8 @@ static constexpr uint32_t BASEX = 0x80000000; // Internal radix used in calculat // this to 2^32 after solving scaling problems with // overflow detection esp. in mul -typedef unsigned long MANTTYPE; -typedef unsigned __int64 TWO_MANTTYPE; +typedef uint32_t MANTTYPE; +typedef uint64_t TWO_MANTTYPE; enum eNUMOBJ_FMT { FMT_FLOAT, // returns floating point, or exponential if number is too big @@ -54,10 +54,10 @@ typedef enum eANGLE_TYPE ANGLE_TYPE; #pragma warning(disable:4200) // nonstandard extension used : zero-sized array in struct/union typedef struct _number { - long sign; // The sign of the mantissa, +1, or -1 - long cdigit; // The number of digits, or what passes for digits in the + int32_t sign; // The sign of the mantissa, +1, or -1 + int32_t cdigit; // The number of digits, or what passes for digits in the // radix being used. - long exp; // The offset of digits from the radix point + int32_t exp; // The offset of digits from the radix point // (decimal point in radix 10) MANTTYPE mant[]; // This is actually allocated as a continuation of the @@ -127,8 +127,8 @@ extern PRAT rat_max_exp; extern PRAT rat_min_exp; extern PRAT rat_max_fact; extern PRAT rat_min_fact; -extern PRAT rat_max_long; -extern PRAT rat_min_long; +extern PRAT rat_max_i32; +extern PRAT rat_min_i32; // DUPNUM Duplicates a number taking care of allocation and internals #define DUPNUM(a,b) destroynum(a);createnum( a, (b)->cdigit );_dupnum(a, b); @@ -208,7 +208,7 @@ _destroynum(x),(x)=nullptr // TRIMNUM ASSUMES the number is in radix form NOT INTERNAL BASEX!!! #define TRIMNUM(x, precision) if ( !g_ftrueinfinite ) { \ - long trim = (x)->cdigit - precision-g_ratio;\ + int32_t trim = (x)->cdigit - precision-g_ratio;\ if ( trim > 1 ) \ { \ memmove( (x)->mant, &((x)->mant[trim]), sizeof(MANTTYPE)*((x)->cdigit-trim) ); \ @@ -218,7 +218,7 @@ memmove( (x)->mant, &((x)->mant[trim]), sizeof(MANTTYPE)*((x)->cdigit-trim) ); \ } // TRIMTOP ASSUMES the number is in INTERNAL BASEX!!! #define TRIMTOP(x, precision) if ( !g_ftrueinfinite ) { \ - long trim = (x)->pp->cdigit - (precision/g_ratio) - 2;\ + int32_t trim = (x)->pp->cdigit - (precision/g_ratio) - 2;\ if ( trim > 1 ) \ { \ memmove( (x)->pp->mant, &((x)->pp->mant[trim]), sizeof(MANTTYPE)*((x)->pp->cdigit-trim) ); \ @@ -246,8 +246,8 @@ memmove( (x)->pp->mant, &((x)->pp->mant[trim]), sizeof(MANTTYPE)*((x)->pp->cdigi DUPRAT(xx,*px); \ mulrat(&xx,*px, precision); \ createrat(pret); \ - pret->pp=longtonum( 0L, BASEX ); \ - pret->pq=longtonum( 0L, BASEX ); + pret->pp=i32tonum( 0L, BASEX ); \ + pret->pq=i32tonum( 0L, BASEX ); #define DESTROYTAYLOR() destroynum( n2 ); \ destroyrat( xx );\ @@ -294,7 +294,7 @@ extern bool g_ftrueinfinite; // set to true to allow infinite precision // don't use unless you know what you are doing // used to help decide when to stop calculating. -extern long g_ratio; // Internally calculated ratio of internal radix +extern int32_t g_ratio; // Internally calculated ratio of internal radix //----------------------------------------------------------------------------- // @@ -321,10 +321,10 @@ 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 extern void flatrat(_Inout_ PRAT& prat, uint32_t radix, int32_t precision); -extern long numtolong(_In_ PNUMBER pnum, uint32_t radix ); -extern long rattolong(_In_ PRAT prat, uint32_t radix, int32_t precision); -ULONGLONG rattoUlonglong(_In_ PRAT prat, uint32_t radix, int32_t precision); -extern PNUMBER _createnum(_In_ ULONG size ); // returns an empty number structure with size digits +extern int32_t numtoi32(_In_ PNUMBER pnum, uint32_t radix ); +extern int32_t rattoi32(_In_ PRAT prat, uint32_t radix, int32_t precision); +uint64_t rattoUi64(_In_ PRAT prat, uint32_t radix, int32_t precision); +extern PNUMBER _createnum(_In_ uint32_t size ); // returns an empty number structure with size digits extern PNUMBER nRadixxtonum(_In_ PNUMBER a, uint32_t radix, int32_t precision); extern PNUMBER gcd(_In_ PNUMBER a, _In_ PNUMBER b ); extern PNUMBER StringToNumber(std::wstring_view numberString, uint32_t radix, int32_t precision); // takes a text representation of a number and returns a number. @@ -332,10 +332,10 @@ extern PNUMBER StringToNumber(std::wstring_view numberString, uint32_t radix, in // takes a text representation of a number as a mantissa with sign and an exponent with sign. extern PRAT StringToRat(bool mantissaIsNegative, std::wstring_view mantissa, bool exponentIsNegative, std::wstring_view exponent, uint32_t radix, int32_t precision); -extern PNUMBER longfactnum(long inlong, uint32_t radix); -extern PNUMBER longprodnum(long start, long stop, uint32_t radix); -extern PNUMBER longtonum(long inlong, uint32_t radix); -extern PNUMBER Ulongtonum(unsigned long inlong, uint32_t radix); +extern PNUMBER i32factnum(int32_t ini32, uint32_t radix); +extern PNUMBER i32prodnum(int32_t start, int32_t stop, uint32_t radix); +extern PNUMBER i32tonum(int32_t ini32, uint32_t radix); +extern PNUMBER Ui32tonum(uint32_t ini32, uint32_t radix); extern PNUMBER numtonRadixx(PNUMBER a, uint32_t radix); // creates a empty/undefined rational representation (p/q) @@ -393,8 +393,8 @@ extern void log10rat( _Inout_ PRAT *px, int32_t precision); // returns a new rat structure with the natural log of x->p/x->q extern void lograt( _Inout_ PRAT *px, int32_t precision); -extern PRAT longtorat( long inlong ); -extern PRAT Ulongtorat( unsigned long inulong ); +extern PRAT i32torat( int32_t ini32 ); +extern PRAT Ui32torat( uint32_t inui32 ); extern PRAT numtorat( _In_ PNUMBER pin, uint32_t radix); extern void sinhrat( _Inout_ PRAT *px, uint32_t radix, int32_t precision); @@ -429,13 +429,13 @@ extern void intrat( _Inout_ PRAT *px, uint32_t radix, int32_t precision); extern void mulnum( _Inout_ PNUMBER *pa, _In_ PNUMBER b, uint32_t radix); extern void mulnumx( _Inout_ PNUMBER *pa, _In_ PNUMBER b ); extern void mulrat( _Inout_ PRAT *pa, _In_ PRAT b, int32_t precision); -extern void numpowlong( _Inout_ PNUMBER *proot, long power, uint32_t radix, int32_t precision); -extern void numpowlongx( _Inout_ PNUMBER *proot, long power ); +extern void numpowi32( _Inout_ PNUMBER *proot, int32_t power, uint32_t radix, int32_t precision); +extern void numpowi32x( _Inout_ PNUMBER *proot, int32_t power ); extern void orrat( _Inout_ PRAT *pa, _In_ PRAT b, uint32_t radix, int32_t precision); extern void powrat( _Inout_ PRAT *pa, _In_ PRAT b , uint32_t radix, int32_t precision); extern void powratNumeratorDenominator(_Inout_ PRAT *pa, _In_ PRAT b, uint32_t radix, int32_t precision); extern void powratcomp(_Inout_ PRAT *pa, _In_ PRAT b, uint32_t radix, int32_t precision); -extern void ratpowlong( _Inout_ PRAT *proot, long power, int32_t precision); +extern void ratpowi32( _Inout_ PRAT *proot, int32_t power, int32_t precision); extern void remnum( _Inout_ PNUMBER *pa, _In_ PNUMBER b, uint32_t radix); extern void rootrat( _Inout_ PRAT *pa, _In_ PRAT b , uint32_t radix, int32_t precision); extern void scale2pi( _Inout_ PRAT *px, uint32_t radix, int32_t precision); diff --git a/src/CalcManager/Ratpack/support.cpp b/src/CalcManager/Ratpack/support.cpp index f3b00d2f..ebee00c6 100644 --- a/src/CalcManager/Ratpack/support.cpp +++ b/src/CalcManager/Ratpack/support.cpp @@ -45,8 +45,8 @@ static int cbitsofprecision = 0; DUPNUM((v)->pq,(&(init_q_##v))); #define READRAWNUM(v) DUPNUM(v,(&(init_##v))) -#define INIT_AND_DUMP_RAW_NUM_IF_NULL(r, v) if (r == nullptr) { r = longtonum(v, BASEX); DUMPRAWNUM(v); } -#define INIT_AND_DUMP_RAW_RAT_IF_NULL(r, v) if (r == nullptr) { r = longtorat(v); DUMPRAWRAT(v); } +#define INIT_AND_DUMP_RAW_NUM_IF_NULL(r, v) if (r == nullptr) { r = i32tonum(v, BASEX); DUMPRAWNUM(v); } +#define INIT_AND_DUMP_RAW_RAT_IF_NULL(r, v) if (r == nullptr) { r = i32torat(v); DUMPRAWRAT(v); } static constexpr int RATIO_FOR_DECIMAL = 9; static constexpr int DECIMAL = 10; @@ -87,7 +87,7 @@ PRAT rat_exp= nullptr; PRAT rad_to_deg= nullptr; PRAT rad_to_grad= nullptr; PRAT rat_qword= nullptr; -PRAT rat_dword= nullptr; // unsigned max ulong +PRAT rat_dword= nullptr; // unsigned max ui32 PRAT rat_word= nullptr; PRAT rat_byte= nullptr; PRAT rat_360= nullptr; @@ -101,8 +101,8 @@ PRAT rat_max_exp= nullptr; PRAT rat_min_exp= nullptr; PRAT rat_max_fact = nullptr; PRAT rat_min_fact = nullptr; -PRAT rat_min_long= nullptr; // min signed long -PRAT rat_max_long= nullptr; // max signed long +PRAT rat_min_i32= nullptr; // min signed i32 +PRAT rat_max_i32= nullptr; // max signed i32 //---------------------------------------------------------------------------- // @@ -132,7 +132,7 @@ void ChangeConstants(uint32_t radix, int32_t precision) g_ratio += !g_ratio; destroyrat(rat_nRadix); - rat_nRadix=longtorat( radix ); + rat_nRadix=i32torat( radix ); // Check to see what we have to recalculate and what we don't if (cbitsofprecision < (g_ratio * static_cast(radix) * precision)) @@ -166,7 +166,7 @@ void ChangeConstants(uint32_t radix, int32_t precision) INIT_AND_DUMP_RAW_RAT_IF_NULL(rat_min_fact, -1000); DUPRAT(rat_smallest, rat_nRadix); - ratpowlong(&rat_smallest, -precision, precision); + ratpowi32(&rat_smallest, -precision, precision); DUPRAT(rat_negsmallest, rat_smallest); rat_negsmallest->pp->sign = -1; DUMPRAWRAT(rat_smallest); @@ -183,29 +183,29 @@ void ChangeConstants(uint32_t radix, int32_t precision) if (pt_eight_five == nullptr) { createrat(pt_eight_five); - pt_eight_five->pp = longtonum(85L, BASEX); - pt_eight_five->pq = longtonum(100L, BASEX); + pt_eight_five->pp = i32tonum(85L, BASEX); + pt_eight_five->pq = i32tonum(100L, BASEX); DUMPRAWRAT(pt_eight_five); } DUPRAT(rat_qword, rat_two); - numpowlong(&(rat_qword->pp), 64, BASEX, precision); + numpowi32(&(rat_qword->pp), 64, BASEX, precision); subrat(&rat_qword, rat_one, precision); DUMPRAWRAT(rat_qword); DUPRAT(rat_dword, rat_two); - numpowlong(&(rat_dword->pp), 32, BASEX, precision); + numpowi32(&(rat_dword->pp), 32, BASEX, precision); subrat(&rat_dword, rat_one, precision); DUMPRAWRAT(rat_dword); - DUPRAT(rat_max_long, rat_two); - numpowlong(&(rat_max_long->pp), 31, BASEX, precision); - DUPRAT(rat_min_long, rat_max_long); - subrat(&rat_max_long, rat_one, precision); // rat_max_long = 2^31 -1 - DUMPRAWRAT(rat_max_long); + DUPRAT(rat_max_i32, rat_two); + numpowi32(&(rat_max_i32->pp), 31, BASEX, precision); + DUPRAT(rat_min_i32, rat_max_i32); + subrat(&rat_max_i32, rat_one, precision); // rat_max_i32 = 2^31 -1 + DUMPRAWRAT(rat_max_i32); - rat_min_long->pp->sign *= -1; // rat_min_long = -2^31 - DUMPRAWRAT(rat_min_long); + rat_min_i32->pp->sign *= -1; // rat_min_i32 = -2^31 + DUMPRAWRAT(rat_min_i32); DUPRAT(rat_min_exp, rat_max_exp); rat_min_exp->pp->sign *= -1; @@ -215,7 +215,7 @@ void ChangeConstants(uint32_t radix, int32_t precision) // Apparently when dividing 180 by pi, another (internal) digit of // precision is needed. - long extraPrecision = precision + g_ratio; + int32_t extraPrecision = precision + g_ratio; DUPRAT(pi, rat_half); asinrat(&pi, radix, extraPrecision); mulrat(&pi, rat_six, extraPrecision); @@ -253,12 +253,12 @@ void ChangeConstants(uint32_t radix, int32_t precision) destroyrat(rad_to_deg); - rad_to_deg = longtorat(180L); + rad_to_deg = i32torat(180L); divrat(&rad_to_deg, pi, extraPrecision); DUMPRAWRAT(rad_to_deg); destroyrat(rad_to_grad); - rad_to_grad = longtorat(200L); + rad_to_grad = i32torat(200L); divrat(&rad_to_grad, pi, extraPrecision); DUMPRAWRAT(rad_to_grad); } @@ -267,7 +267,7 @@ void ChangeConstants(uint32_t radix, int32_t precision) _readconstants(); DUPRAT(rat_smallest, rat_nRadix); - ratpowlong(&rat_smallest, -precision, precision); + ratpowi32(&rat_smallest, -precision, precision); DUPRAT(rat_negsmallest, rat_smallest); rat_negsmallest->pp->sign = -1; } @@ -333,7 +333,7 @@ bool rat_equ( PRAT a, PRAT b, int32_t precision) // // FUNCTION: rat_ge // -// ARGUMENTS: PRAT a, PRAT b and long precision +// ARGUMENTS: PRAT a, PRAT b and int32_t precision // // RETURN: true if a is greater than or equal to b // @@ -384,7 +384,7 @@ bool rat_gt( PRAT a, PRAT b, int32_t precision) // // FUNCTION: rat_le // -// ARGUMENTS: PRAT a, PRAT b and long precision +// ARGUMENTS: PRAT a, PRAT b and int32_t precision // // RETURN: true if a is less than or equal to b // @@ -411,7 +411,7 @@ bool rat_le( PRAT a, PRAT b, int32_t precision) // // FUNCTION: rat_lt // -// ARGUMENTS: PRAT a, PRAT b and long precision +// ARGUMENTS: PRAT a, PRAT b and int32_t precision // // RETURN: true if a is less than b // @@ -475,7 +475,7 @@ void scale( PRAT *px, PRAT scalefact, uint32_t radix, int32_t precision ) // Logscale is a quick way to tell how much extra precision is needed for // scaling by scalefact. - long logscale = g_ratio * ( (pret->pp->cdigit+pret->pp->exp) - + int32_t logscale = g_ratio * ( (pret->pp->cdigit+pret->pp->exp) - (pret->pq->cdigit+pret->pq->exp) ); if ( logscale > 0 ) { @@ -510,7 +510,7 @@ void scale2pi( PRAT *px, uint32_t radix, int32_t precision ) // Logscale is a quick way to tell how much extra precision is needed for // scaling by 2 pi. - long logscale = g_ratio * ( (pret->pp->cdigit+pret->pp->exp) - + int32_t logscale = g_ratio * ( (pret->pp->cdigit+pret->pp->exp) - (pret->pq->cdigit+pret->pq->exp) ); if ( logscale > 0 ) { @@ -652,15 +652,15 @@ void _readconstants( void ) READRAWRAT(rat_min_exp); READRAWRAT(rat_max_fact); READRAWRAT(rat_min_fact); - READRAWRAT(rat_min_long); - READRAWRAT(rat_max_long); + READRAWRAT(rat_min_i32); + READRAWRAT(rat_max_i32); } //--------------------------------------------------------------------------- // // FUNCTION: trimit // -// ARGUMENTS: PRAT *px, long precision +// ARGUMENTS: PRAT *px, int32_t precision // // // DESCRIPTION: Chops off digits from rational numbers to avoid time @@ -681,7 +681,7 @@ void trimit( PRAT *px, int32_t precision) { if ( !g_ftrueinfinite ) { - long trim; + int32_t trim; PNUMBER pp=(*px)->pp; PNUMBER pq=(*px)->pq; trim = g_ratio * (min((pp->cdigit+pp->exp),(pq->cdigit+pq->exp))-1) - precision; diff --git a/src/CalcManager/Ratpack/trans.cpp b/src/CalcManager/Ratpack/trans.cpp index 5b46a936..82897564 100644 --- a/src/CalcManager/Ratpack/trans.cpp +++ b/src/CalcManager/Ratpack/trans.cpp @@ -168,12 +168,12 @@ void _cosrat( PRAT *px, uint32_t radix, int32_t precision) destroynum(pret->pp); destroynum(pret->pq); - pret->pp=longtonum( 1L, radix); - pret->pq=longtonum( 1L, radix); + pret->pp=i32tonum( 1L, radix); + pret->pq=i32tonum( 1L, radix); DUPRAT(thisterm,pret) - n2=longtonum(0L, radix); + n2=i32tonum(0L, radix); xx->pp->sign *= -1; do { diff --git a/src/CalcManager/Ratpack/transh.cpp b/src/CalcManager/Ratpack/transh.cpp index 8a835341..92a12583 100644 --- a/src/CalcManager/Ratpack/transh.cpp +++ b/src/CalcManager/Ratpack/transh.cpp @@ -159,12 +159,12 @@ void _coshrat( PRAT *px, uint32_t radix, int32_t precision) CREATETAYLOR(); - pret->pp=longtonum( 1L, radix); - pret->pq=longtonum( 1L, radix); + pret->pp=i32tonum( 1L, radix); + pret->pq=i32tonum( 1L, radix); DUPRAT(thisterm,pret) - n2=longtonum(0L, radix); + n2=i32tonum(0L, radix); do { NEXTTERM(xx,INC(n2) DIVNUM(n2) INC(n2) DIVNUM(n2), precision); diff --git a/src/CalcManager/pch.h b/src/CalcManager/pch.h index ff0ca451..c5f39b6d 100644 --- a/src/CalcManager/pch.h +++ b/src/CalcManager/pch.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include diff --git a/src/CalcViewModel/Common/DateCalculator.h b/src/CalcViewModel/Common/DateCalculator.h index b755e2ee..3e8a78a5 100644 --- a/src/CalcViewModel/Common/DateCalculator.h +++ b/src/CalcViewModel/Common/DateCalculator.h @@ -3,11 +3,11 @@ #pragma once -const ULONGLONG c_millisecond = 10000; -const ULONGLONG c_second = 1000 * c_millisecond; -const ULONGLONG c_minute = 60 * c_second; -const ULONGLONG c_hour = 60 * c_minute; -const ULONGLONG c_day = 24 * c_hour; +const uint64_t c_millisecond = 10000; +const uint64_t c_second = 1000 * c_millisecond; +const uint64_t c_minute = 60 * c_second; +const uint64_t c_hour = 60 * c_minute; +const uint64_t c_day = 24 * c_hour; const int c_unitsOfDate = 4; // Units Year,Month,Week,Day const int c_unitsGreaterThanDays = 3; // Units Greater than Days (Year/Month/Week) 3 From f6a6aae6e6ce1c485b4b4b02413259649cf2b58f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Thu, 28 Mar 2019 19:17:06 +0100 Subject: [PATCH 09/47] Add additional defines for MSVC ARM and ARM64 to conv.cpp (#399) Fixes ARM(64) regression introduced with #212 --- src/CalcManager/Ratpack/conv.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/CalcManager/Ratpack/conv.cpp b/src/CalcManager/Ratpack/conv.cpp index 88228019..c25d4481 100644 --- a/src/CalcManager/Ratpack/conv.cpp +++ b/src/CalcManager/Ratpack/conv.cpp @@ -36,14 +36,17 @@ wchar_t g_decimalSeparator = L'.'; // The following defines and Calc_ULong* functions were taken from // https://github.com/dotnet/coreclr/blob/8b1595b74c943b33fa794e63e440e6f4c9679478/src/pal/inc/rt/intsafe.h // under MIT License +// See also +// * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros +// * https://sourceforge.net/p/predef/wiki/Architectures/ #if defined(MIDL_PASS) || defined(RC_INVOKED) || defined(_M_CEE_PURE) \ - || defined(_M_AMD64) || defined(__ARM_ARCH) || defined(__x86_64__) + || defined(_M_AMD64) || defined(__ARM_ARCH) || defined(__x86_64__) || defined(_M_ARM64) #ifndef Calc_UInt32x32To64 #define Calc_UInt32x32To64(a, b) ((uint64_t)((uint32_t)(a)) * (uint64_t)((uint32_t)(b))) #endif -#elif defined(_M_IX86) || defined(__i386__) +#elif defined(_M_IX86) || defined(__i386__) || defined(_M_ARM) #ifndef Calc_UInt32x32To64 #define Calc_UInt32x32To64(a, b) (uint64_t)((uint64_t)(uint32_t)(a) * (uint32_t)(b)) From cb31349ee2b109ecc080b7c40151b3ce1b0c6a1b Mon Sep 17 00:00:00 2001 From: Sonali Agrawal Date: Wed, 3 Apr 2019 19:15:47 +0530 Subject: [PATCH 10/47] Update README to add description of "date calculation" functionality (#365) Fixes #140. Added a one-liner description about the date calculation functionality Description of the changes: * This change maintains consistency by writing it after the description of the programmer calculator so that it matches the order of the positions of these functionalities in the hamburger menu of the calculator. * Just like the other descriptions, this is also a one-liner * This description covers both the functionality under "date calculation" i.e. the difference between the dates and adding/subtracting a date from another. Co-Authored-By: sonali9696 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ffba40c0..d967b175 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Calculator ships regularly with new features and bug fixes. You can get the late - Standard Calculator functionality which offers basic operations and evaluates commands immediately as they are entered. - Scientific Calculator functionality which offers expanded operations and evaluates commands using order of operations. - Programmer Calculator functionality which offers common mathematical operations for developers including conversion between common bases. +- Date Calculation functionality which offers the difference between two dates, as well as the ability to add/subtract years, months and/or days to/from a given input date. - Calculation history and memory capabilities. - Conversion between many units of measurement. - Currency conversion based on data retrieved from [Bing](https://www.bing.com). From 6d779a8815651fa0450583c3e7d762d134be12e1 Mon Sep 17 00:00:00 2001 From: Matt Cooley Date: Thu, 4 Apr 2019 09:19:59 -0700 Subject: [PATCH 11/47] Updating version of release builds to 1904 (#422) --- build/pipelines/azure-pipelines.release.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/pipelines/azure-pipelines.release.yaml b/build/pipelines/azure-pipelines.release.yaml index a4507e21..f687ec4a 100644 --- a/build/pipelines/azure-pipelines.release.yaml +++ b/build/pipelines/azure-pipelines.release.yaml @@ -9,8 +9,8 @@ pr: none variables: versionMajor: 10 - versionMinor: 1903 - versionBuild: $[counter('10.1903.*', 0)] + versionMinor: 1904 + versionBuild: $[counter('10.1904.*', 0)] versionPatch: 0 name: '$(versionMajor).$(versionMinor).$(versionBuild).$(versionPatch)' From 71e34c6f01a3148b18e37da5cde873ed76d221a2 Mon Sep 17 00:00:00 2001 From: Matt Cooley Date: Thu, 4 Apr 2019 16:11:13 -0700 Subject: [PATCH 12/47] Fix inline script in loc pipeline (#434) --- build/pipelines/azure-pipelines.loc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/pipelines/azure-pipelines.loc.yaml b/build/pipelines/azure-pipelines.loc.yaml index d1ef8552..7c5ef246 100644 --- a/build/pipelines/azure-pipelines.loc.yaml +++ b/build/pipelines/azure-pipelines.loc.yaml @@ -35,7 +35,7 @@ jobs: cd $(Build.SourcesDirectory) git add -A git diff --cached --exit-code - echo '##vso[task.setvariable variable=hasChanges]%errorlevel%' + echo ##vso[task.setvariable variable=hasChanges]%errorlevel% git diff --cached > $(Build.ArtifactStagingDirectory)\LocalizedStrings.patch displayName: Check for changes and create patch file From 6f49b17bf099c10830c15ea93e1207068896045b Mon Sep 17 00:00:00 2001 From: Rudy Huyn Date: Thu, 4 Apr 2019 16:55:12 -0700 Subject: [PATCH 13/47] =?UTF-8?q?Add=20Reveal=20Highlight=20on=20AccentCal?= =?UTF-8?q?cButtonStyle=20+=20fix=20accessibility=20iss=E2=80=A6=20(#374)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add Reveal Highlight effect on the 4 basic operator buttons + Equal button (effect more visible with purple and all grey-ish accent colors). Also fixes a high contrast issue when the operator buttons were pressed. --- src/Calculator/App.xaml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Calculator/App.xaml b/src/Calculator/App.xaml index 60103662..51c2846d 100644 --- a/src/Calculator/App.xaml +++ b/src/Calculator/App.xaml @@ -34,7 +34,11 @@ FallbackColor="Transparent" TargetTheme="Dark" Color="Transparent"/> - + @@ -66,7 +70,11 @@ FallbackColor="Transparent" TargetTheme="Light" Color="Transparent"/> - + @@ -93,7 +101,8 @@ - + + @@ -326,9 +335,9 @@ @@ -701,7 +710,7 @@ - + From e7eace57f8734555157a4ebb61606524ddd38193 Mon Sep 17 00:00:00 2001 From: Matt Cooley Date: Fri, 5 Apr 2019 08:39:29 -0700 Subject: [PATCH 14/47] Update localized strings 2019-04-04 (#438) --- src/Calculator/Resources/af-ZA/Resources.resw | 8 +++++++ src/Calculator/Resources/am-ET/Resources.resw | 10 ++++++++- src/Calculator/Resources/ar-SA/Resources.resw | 10 ++++++++- .../Resources/az-Latn-AZ/Resources.resw | 8 +++++++ src/Calculator/Resources/be-BY/Resources.resw | 10 ++++++++- src/Calculator/Resources/bg-BG/Resources.resw | 8 +++++++ src/Calculator/Resources/bn-BD/Resources.resw | 10 ++++++++- src/Calculator/Resources/ca-ES/Resources.resw | 12 ++++++++-- src/Calculator/Resources/cs-CZ/Resources.resw | 8 +++++++ src/Calculator/Resources/da-DK/Resources.resw | 12 ++++++++-- src/Calculator/Resources/de-DE/Resources.resw | 22 +++++++++++++------ src/Calculator/Resources/el-GR/Resources.resw | 8 +++++++ src/Calculator/Resources/en-GB/Resources.resw | 12 ++++++++-- src/Calculator/Resources/es-ES/Resources.resw | 10 ++++++++- src/Calculator/Resources/es-MX/Resources.resw | 10 ++++++++- src/Calculator/Resources/et-EE/Resources.resw | 8 +++++++ src/Calculator/Resources/eu-ES/Resources.resw | 8 +++++++ src/Calculator/Resources/fa-IR/Resources.resw | 8 +++++++ src/Calculator/Resources/fi-FI/Resources.resw | 8 +++++++ .../Resources/fil-PH/Resources.resw | 10 ++++++++- src/Calculator/Resources/fr-CA/Resources.resw | 14 +++++++++--- src/Calculator/Resources/fr-FR/Resources.resw | 10 ++++++++- src/Calculator/Resources/gl-ES/Resources.resw | 8 +++++++ src/Calculator/Resources/he-IL/Resources.resw | 8 +++++++ src/Calculator/Resources/hi-IN/Resources.resw | 10 ++++++++- src/Calculator/Resources/hr-HR/Resources.resw | 10 ++++++++- src/Calculator/Resources/hu-HU/Resources.resw | 8 +++++++ src/Calculator/Resources/id-ID/Resources.resw | 8 +++++++ src/Calculator/Resources/is-IS/Resources.resw | 8 +++++++ src/Calculator/Resources/it-IT/Resources.resw | 8 +++++++ src/Calculator/Resources/ja-JP/Resources.resw | 12 ++++++++-- src/Calculator/Resources/kk-KZ/Resources.resw | 10 ++++++++- src/Calculator/Resources/km-KH/Resources.resw | 8 +++++++ src/Calculator/Resources/kn-IN/Resources.resw | 8 +++++++ src/Calculator/Resources/ko-KR/Resources.resw | 8 +++++++ src/Calculator/Resources/lo-LA/Resources.resw | 8 +++++++ src/Calculator/Resources/lt-LT/Resources.resw | 14 +++++++++--- src/Calculator/Resources/lv-LV/Resources.resw | 8 +++++++ src/Calculator/Resources/mk-MK/Resources.resw | 10 ++++++++- src/Calculator/Resources/ml-IN/Resources.resw | 10 ++++++++- src/Calculator/Resources/ms-MY/Resources.resw | 8 +++++++ src/Calculator/Resources/nb-NO/Resources.resw | 8 +++++++ src/Calculator/Resources/nl-NL/Resources.resw | 8 +++++++ src/Calculator/Resources/pl-PL/Resources.resw | 8 +++++++ src/Calculator/Resources/pt-BR/Resources.resw | 8 +++++++ src/Calculator/Resources/pt-PT/Resources.resw | 8 +++++++ src/Calculator/Resources/ro-RO/Resources.resw | 8 +++++++ src/Calculator/Resources/ru-RU/Resources.resw | 12 ++++++++-- src/Calculator/Resources/sk-SK/Resources.resw | 8 +++++++ src/Calculator/Resources/sl-SI/Resources.resw | 8 +++++++ src/Calculator/Resources/sq-AL/Resources.resw | 12 ++++++++-- .../Resources/sr-Latn-RS/Resources.resw | 16 ++++++++++---- src/Calculator/Resources/sv-SE/Resources.resw | 8 +++++++ src/Calculator/Resources/sw-KE/Resources.resw | 8 +++++++ src/Calculator/Resources/ta-IN/Resources.resw | 8 +++++++ src/Calculator/Resources/te-IN/Resources.resw | 12 ++++++++-- src/Calculator/Resources/th-TH/Resources.resw | 10 ++++++++- src/Calculator/Resources/tr-TR/Resources.resw | 8 +++++++ src/Calculator/Resources/uk-UA/Resources.resw | 12 ++++++++-- .../Resources/uz-Latn-UZ/Resources.resw | 8 +++++++ src/Calculator/Resources/vi-VN/Resources.resw | 12 ++++++++-- src/Calculator/Resources/zh-CN/Resources.resw | 8 +++++++ src/Calculator/Resources/zh-TW/Resources.resw | 14 +++++++++--- 63 files changed, 556 insertions(+), 52 deletions(-) diff --git a/src/Calculator/Resources/af-ZA/Resources.resw b/src/Calculator/Resources/af-ZA/Resources.resw index 03914db2..366e0a09 100644 --- a/src/Calculator/Resources/af-ZA/Resources.resw +++ b/src/Calculator/Resources/af-ZA/Resources.resw @@ -909,6 +909,14 @@ Hakies regs Screen reader prompt for the Calculator ")" button on the scientific operator keypad + + Aantal oop hakies %1 + {Locked="%1"} Screen reader prompt for the Calculator "(" button on the scientific and programmer operator keypad. %1 is the localized count of open parenthesis, e.g. "2". + + + Daar is geen oop hakies om te sluit nie. + {Locked="%1"} Screen reader prompt for the Calculator when the ")" button on the scientific and programmer operator keypad cannot be added to the equation. e.g. "1+)". + Wetenskaplike notering Screen reader prompt for the Calculator F-E the scientific operator keypad diff --git a/src/Calculator/Resources/am-ET/Resources.resw b/src/Calculator/Resources/am-ET/Resources.resw index bf5de965..24edcb5f 100644 --- a/src/Calculator/Resources/am-ET/Resources.resw +++ b/src/Calculator/Resources/am-ET/Resources.resw @@ -909,6 +909,14 @@ የቀኝ ቅንፍ Screen reader prompt for the Calculator ")" button on the scientific operator keypad + + የክፍት ቅንፎች ብዛት %1 + {Locked="%1"} Screen reader prompt for the Calculator "(" button on the scientific and programmer operator keypad. %1 is the localized count of open parenthesis, e.g. "2". + + + ምንም የሚዘጋ ክፍት ቅንፍ የለም። + {Locked="%1"} Screen reader prompt for the Calculator when the ")" button on the scientific and programmer operator keypad cannot be added to the equation. e.g. "1+)". + ሳይንሳዊ እሳቤ Screen reader prompt for the Calculator F-E the scientific operator keypad @@ -2278,7 +2286,7 @@ Displayed on a link to the Microsoft Privacy Statement on the About panel - © %1 Microsoft. ሁሉም መብቱ የተጠበቀ። + © %1 Microsoft. ሁሉም መብቶች በህግ የተከበሩ ናቸው። {Locked="%1"}. Copyright statement, displayed on the About panel. %1 = the current year (4 digits) diff --git a/src/Calculator/Resources/ar-SA/Resources.resw b/src/Calculator/Resources/ar-SA/Resources.resw index 296f7952..051c055c 100644 --- a/src/Calculator/Resources/ar-SA/Resources.resw +++ b/src/Calculator/Resources/ar-SA/Resources.resw @@ -909,6 +909,14 @@ أقواس يمنى Screen reader prompt for the Calculator ")" button on the scientific operator keypad + + عدد الأقواس المفتوحة %1 + {Locked="%1"} Screen reader prompt for the Calculator "(" button on the scientific and programmer operator keypad. %1 is the localized count of open parenthesis, e.g. "2". + + + لا توجد أي أقواس مفتوحة لإغلاقها. + {Locked="%1"} Screen reader prompt for the Calculator when the ")" button on the scientific and programmer operator keypad cannot be added to the equation. e.g. "1+)". + رموز علمية Screen reader prompt for the Calculator F-E the scientific operator keypad @@ -2279,7 +2287,7 @@ Displayed on a link to the Microsoft Privacy Statement on the About panel - © %1 Microsoft. جميع الحقوق محفوظة. + حقوق النشر © محفوظة لشركة Microsoft لعام %1. جميع الحقوق محفوظة. {Locked="%1"}. Copyright statement, displayed on the About panel. %1 = the current year (4 digits) diff --git a/src/Calculator/Resources/az-Latn-AZ/Resources.resw b/src/Calculator/Resources/az-Latn-AZ/Resources.resw index 8cdfe566..60fa2da8 100644 --- a/src/Calculator/Resources/az-Latn-AZ/Resources.resw +++ b/src/Calculator/Resources/az-Latn-AZ/Resources.resw @@ -909,6 +909,14 @@ Sağ mötərizə Screen reader prompt for the Calculator ")" button on the scientific operator keypad + + Açıq mötərizənin sayı %1 + {Locked="%1"} Screen reader prompt for the Calculator "(" button on the scientific and programmer operator keypad. %1 is the localized count of open parenthesis, e.g. "2". + + + Bağlamaq üçün açıq mötərizələr yoxdur. + {Locked="%1"} Screen reader prompt for the Calculator when the ")" button on the scientific and programmer operator keypad cannot be added to the equation. e.g. "1+)". + Eksponensial format Screen reader prompt for the Calculator F-E the scientific operator keypad diff --git a/src/Calculator/Resources/be-BY/Resources.resw b/src/Calculator/Resources/be-BY/Resources.resw index bb36bc97..f5498b31 100644 --- a/src/Calculator/Resources/be-BY/Resources.resw +++ b/src/Calculator/Resources/be-BY/Resources.resw @@ -909,6 +909,14 @@ Правая дужка Screen reader prompt for the Calculator ")" button on the scientific operator keypad + + Лік адсутных дужак %1 + {Locked="%1"} Screen reader prompt for the Calculator "(" button on the scientific and programmer operator keypad. %1 is the localized count of open parenthesis, e.g. "2". + + + Няма незакрытых дужак. + {Locked="%1"} Screen reader prompt for the Calculator when the ")" button on the scientific and programmer operator keypad cannot be added to the equation. e.g. "1+)". + Экспанентавы запіс Screen reader prompt for the Calculator F-E the scientific operator keypad @@ -2899,4 +2907,4 @@ Пагадненне аб выкарыстанні сэрвісаў Microsoft Displayed on a link to the Microsoft Services Agreement in the about this app information - + \ No newline at end of file diff --git a/src/Calculator/Resources/bg-BG/Resources.resw b/src/Calculator/Resources/bg-BG/Resources.resw index 676ee4d4..069f995a 100644 --- a/src/Calculator/Resources/bg-BG/Resources.resw +++ b/src/Calculator/Resources/bg-BG/Resources.resw @@ -909,6 +909,14 @@ Дясна скоба Screen reader prompt for the Calculator ")" button on the scientific operator keypad + + Брой отворени скоби: %1 + {Locked="%1"} Screen reader prompt for the Calculator "(" button on the scientific and programmer operator keypad. %1 is the localized count of open parenthesis, e.g. "2". + + + Няма отворени скоби за затваряне. + {Locked="%1"} Screen reader prompt for the Calculator when the ")" button on the scientific and programmer operator keypad cannot be added to the equation. e.g. "1+)". + Експоненциален запис Screen reader prompt for the Calculator F-E the scientific operator keypad diff --git a/src/Calculator/Resources/bn-BD/Resources.resw b/src/Calculator/Resources/bn-BD/Resources.resw index 2836bc7a..f4a13742 100644 --- a/src/Calculator/Resources/bn-BD/Resources.resw +++ b/src/Calculator/Resources/bn-BD/Resources.resw @@ -909,6 +909,14 @@ ডান বন্ধনী Screen reader prompt for the Calculator ")" button on the scientific operator keypad + + বন্ধনী গণনা খুলুন %1 + {Locked="%1"} Screen reader prompt for the Calculator "(" button on the scientific and programmer operator keypad. %1 is the localized count of open parenthesis, e.g. "2". + + + বন্ধ করার জন্য এখানে কোনো খোলা বন্ধনী নেই। + {Locked="%1"} Screen reader prompt for the Calculator when the ")" button on the scientific and programmer operator keypad cannot be added to the equation. e.g. "1+)". + বৈজ্ঞানিক নোটেশন Screen reader prompt for the Calculator F-E the scientific operator keypad @@ -2278,7 +2286,7 @@ Displayed on a link to the Microsoft Privacy Statement on the About panel - © %1 Microsoft. সর্বস্বত্ব সংরক্ষিত। + © %1 Microsoft। সর্বস্বত্ব সংরক্ষিত। {Locked="%1"}. Copyright statement, displayed on the About panel. %1 = the current year (4 digits) diff --git a/src/Calculator/Resources/ca-ES/Resources.resw b/src/Calculator/Resources/ca-ES/Resources.resw index 63e2b9a5..b2672e8f 100644 --- a/src/Calculator/Resources/ca-ES/Resources.resw +++ b/src/Calculator/Resources/ca-ES/Resources.resw @@ -1,4 +1,4 @@ - + 15 - 72 - 46 - 28 - - - - - - - - - - - - + - - - - - + - - - - - - - - -