mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-21 22:03:11 -07:00
Set a default base of base64 for Rational class.
This commit is contained in:
parent
fa8c5a42d1
commit
999027da10
9 changed files with 52 additions and 46 deletions
|
@ -302,9 +302,9 @@ wstring CalcInput::ToString(uint32_t radix, bool isIntegerMode)
|
|||
return result;
|
||||
}
|
||||
|
||||
Rational CalcInput::ToRational(int32_t precision)
|
||||
Rational CalcInput::ToRational(uint32_t radix, int32_t precision)
|
||||
{
|
||||
PRAT rat = StringToRat(m_base.IsNegative(), m_base.value, m_exponent.IsNegative(), m_exponent.value, BASEX, precision);
|
||||
PRAT rat = StringToRat(m_base.IsNegative(), m_base.value, m_exponent.IsNegative(), m_exponent.value, radix, precision);
|
||||
if (rat == nullptr)
|
||||
{
|
||||
return 0;
|
||||
|
|
|
@ -213,7 +213,7 @@ namespace CalcEngine
|
|||
|
||||
try
|
||||
{
|
||||
lshrat(&lhsRat, rhsRat, BASEX, precision);
|
||||
lshrat(&lhsRat, rhsRat, DEFAULT_BASE, precision);
|
||||
destroyrat(rhsRat);
|
||||
}
|
||||
catch (DWORD error)
|
||||
|
@ -236,7 +236,7 @@ namespace CalcEngine
|
|||
|
||||
try
|
||||
{
|
||||
rshrat(&lhsRat, rhsRat, BASEX, precision);
|
||||
rshrat(&lhsRat, rhsRat, DEFAULT_BASE, precision);
|
||||
destroyrat(rhsRat);
|
||||
}
|
||||
catch (DWORD error)
|
||||
|
@ -264,7 +264,7 @@ namespace CalcEngine
|
|||
|
||||
try
|
||||
{
|
||||
andrat(&lhsRat, rhsRat, BASEX, precision);
|
||||
andrat(&lhsRat, rhsRat, DEFAULT_BASE, precision);
|
||||
destroyrat(rhsRat);
|
||||
}
|
||||
catch (DWORD error)
|
||||
|
@ -286,7 +286,7 @@ namespace CalcEngine
|
|||
PRAT rhsRat = rhs.ToPRAT();
|
||||
try
|
||||
{
|
||||
orrat(&lhsRat, rhsRat, BASEX, precision);
|
||||
orrat(&lhsRat, rhsRat, DEFAULT_BASE, precision);
|
||||
destroyrat(rhsRat);
|
||||
}
|
||||
catch (DWORD error)
|
||||
|
@ -308,7 +308,7 @@ namespace CalcEngine
|
|||
PRAT rhsRat = rhs.ToPRAT();
|
||||
try
|
||||
{
|
||||
xorrat(&lhsRat, rhsRat, BASEX, precision);
|
||||
xorrat(&lhsRat, rhsRat, DEFAULT_BASE, precision);
|
||||
destroyrat(rhsRat);
|
||||
}
|
||||
catch (DWORD error)
|
||||
|
@ -447,7 +447,7 @@ namespace CalcEngine
|
|||
uint64_t result;
|
||||
try
|
||||
{
|
||||
result = rattoUlonglong(rat, BASEX, precision);
|
||||
result = rattoUlonglong(rat, DEFAULT_BASE, precision);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
|
|
|
@ -139,7 +139,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
|
|||
(IDC_SIGN == wParam && 10 != m_radix))
|
||||
{
|
||||
m_bRecord = false;
|
||||
m_currentVal = m_input.ToRational(m_precision);
|
||||
m_currentVal = m_input.ToRational(m_radix, m_precision);
|
||||
DisplayNum(); // Causes 3.000 to shrink to 3. on first op.
|
||||
}
|
||||
}
|
||||
|
@ -651,7 +651,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
|
|||
case IDM_BYTE:
|
||||
if (m_bRecord)
|
||||
{
|
||||
m_currentVal = m_input.ToRational(m_precision);
|
||||
m_currentVal = m_input.ToRational(m_radix, m_precision);
|
||||
m_bRecord = false;
|
||||
}
|
||||
|
||||
|
@ -1018,7 +1018,7 @@ int CCalcEngine::GetCurrentRadix()
|
|||
|
||||
wstring CCalcEngine::GetCurrentResultForRadix(uint32_t radix, int32_t precision)
|
||||
{
|
||||
Rational rat = (m_bRecord ? m_input.ToRational(m_precision) : m_currentVal);
|
||||
Rational rat = (m_bRecord ? m_input.ToRational(m_radix, m_precision) : m_currentVal);
|
||||
|
||||
ChangeConstants(m_radix, precision);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ Rational RationalMath::Frac(Rational const& rat, int32_t precision)
|
|||
PRAT prat = rat.ToPRAT();
|
||||
try
|
||||
{
|
||||
fracrat(&prat, BASEX, precision);
|
||||
fracrat(&prat, DEFAULT_BASE, precision);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ Rational RationalMath::Integer(Rational const& rat, int32_t precision)
|
|||
PRAT prat = rat.ToPRAT();
|
||||
try
|
||||
{
|
||||
intrat(&prat, BASEX, precision);
|
||||
intrat(&prat, DEFAULT_BASE, precision);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ Rational RationalMath::Pow(Rational const& base, Rational const& pow, int32_t pr
|
|||
|
||||
try
|
||||
{
|
||||
powrat(&baseRat, powRat, BASEX, precision);
|
||||
powrat(&baseRat, powRat, DEFAULT_BASE, precision);
|
||||
destroyrat(powRat);
|
||||
}
|
||||
catch (DWORD error)
|
||||
|
@ -80,7 +80,7 @@ Rational RationalMath::Fact(Rational const& rat, int32_t precision)
|
|||
|
||||
try
|
||||
{
|
||||
factrat(&prat, BASEX, precision);
|
||||
factrat(&prat, DEFAULT_BASE, precision);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
|
@ -100,7 +100,7 @@ Rational RationalMath::Exp(Rational const& rat, int32_t precision)
|
|||
|
||||
try
|
||||
{
|
||||
exprat(&prat, BASEX, precision);
|
||||
exprat(&prat, DEFAULT_BASE, precision);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
|
@ -155,7 +155,7 @@ Rational RationalMath::Sin(Rational const& rat, ANGLE_TYPE angletype, int32_t pr
|
|||
|
||||
try
|
||||
{
|
||||
sinanglerat(&prat, angletype, BASEX, precision);
|
||||
sinanglerat(&prat, angletype, DEFAULT_BASE, precision);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
|
@ -175,7 +175,7 @@ Rational RationalMath::Cos(Rational const& rat, ANGLE_TYPE angletype, int32_t pr
|
|||
|
||||
try
|
||||
{
|
||||
cosanglerat(&prat, angletype, BASEX, precision);
|
||||
cosanglerat(&prat, angletype, DEFAULT_BASE, precision);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
|
@ -195,7 +195,7 @@ Rational RationalMath::Tan(Rational const& rat, ANGLE_TYPE angletype, int32_t pr
|
|||
|
||||
try
|
||||
{
|
||||
tananglerat(&prat, angletype, BASEX, precision);
|
||||
tananglerat(&prat, angletype, DEFAULT_BASE, precision);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
|
@ -215,7 +215,7 @@ Rational RationalMath::ASin(Rational const& rat, ANGLE_TYPE angletype, int32_t p
|
|||
|
||||
try
|
||||
{
|
||||
asinanglerat(&prat, angletype, BASEX, precision);
|
||||
asinanglerat(&prat, angletype, DEFAULT_BASE, precision);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
|
@ -235,7 +235,7 @@ Rational RationalMath::ACos(Rational const& rat, ANGLE_TYPE angletype, int32_t p
|
|||
|
||||
try
|
||||
{
|
||||
acosanglerat(&prat, angletype, BASEX, precision);
|
||||
acosanglerat(&prat, angletype, DEFAULT_BASE, precision);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
|
@ -255,7 +255,7 @@ Rational RationalMath::ATan(Rational const& rat, ANGLE_TYPE angletype, int32_t p
|
|||
|
||||
try
|
||||
{
|
||||
atananglerat(&prat, angletype, BASEX, precision);
|
||||
atananglerat(&prat, angletype, DEFAULT_BASE, precision);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
|
@ -275,7 +275,7 @@ Rational RationalMath::Sinh(Rational const& rat, int32_t precision)
|
|||
|
||||
try
|
||||
{
|
||||
sinhrat(&prat, BASEX, precision);
|
||||
sinhrat(&prat, DEFAULT_BASE, precision);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
|
@ -295,7 +295,7 @@ Rational RationalMath::Cosh(Rational const& rat, int32_t precision)
|
|||
|
||||
try
|
||||
{
|
||||
coshrat(&prat, BASEX, precision);
|
||||
coshrat(&prat, DEFAULT_BASE, precision);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
|
@ -315,7 +315,7 @@ Rational RationalMath::Tanh(Rational const& rat, int32_t precision)
|
|||
|
||||
try
|
||||
{
|
||||
tanhrat(&prat, BASEX, precision);
|
||||
tanhrat(&prat, DEFAULT_BASE, precision);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
|
@ -335,7 +335,7 @@ Rational RationalMath::ASinh(Rational const& rat, int32_t precision)
|
|||
|
||||
try
|
||||
{
|
||||
asinhrat(&prat, BASEX, precision);
|
||||
asinhrat(&prat, DEFAULT_BASE, precision);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
|
@ -355,7 +355,7 @@ Rational RationalMath::ACosh(Rational const& rat, int32_t precision)
|
|||
|
||||
try
|
||||
{
|
||||
acoshrat(&prat, BASEX, precision);
|
||||
acoshrat(&prat, DEFAULT_BASE, precision);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace CalcEngine
|
|||
void Backspace();
|
||||
void SetDecimalSymbol(wchar_t decSymbol);
|
||||
std::wstring ToString(uint32_t radix, bool isIntegerMode);
|
||||
Rational ToRational(int32_t precision);
|
||||
Rational ToRational(uint32_t radix, int32_t precision);
|
||||
|
||||
private:
|
||||
bool m_hasExponent;
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
|
||||
namespace CalcEngine
|
||||
{
|
||||
// Default Base/Radix to use for Rational calculations
|
||||
// Defaults to base 64 rather than the RatPack-internal BASEX because many
|
||||
// calculations do not support bases > 64.
|
||||
static constexpr uint32_t DEFAULT_BASE = BASEX;
|
||||
|
||||
class Rational
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -347,6 +347,7 @@ PNUMBER numtonRadixx(_In_ PNUMBER a, uint32_t radix)
|
|||
// mantissa a string representation of a number
|
||||
// exponentIsNegative true if exponent is less than zero
|
||||
// exponent a string representation of a number
|
||||
// radix is the number base used in the source string
|
||||
//
|
||||
// RETURN: PRAT representation of string input.
|
||||
// Or nullptr if no number scanned.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -75,15 +75,15 @@ void fracrat( PRAT *pa , uint32_t radix, int32_t precision)
|
|||
{
|
||||
// Only do the intrat operation if number is nonzero.
|
||||
// and only if the bottom part is not one.
|
||||
if ( !zernum( (*pa)->pp ) && !equnum( (*pa)->pq, num_one ) )
|
||||
{
|
||||
wstring ratStr = RatToString(*pa, FMT_FLOAT, radix, precision);
|
||||
PNUMBER pnum = StringToNumber(ratStr, radix, precision);
|
||||
|
||||
destroyrat( *pa );
|
||||
*pa = numtorat( pnum, radix);
|
||||
destroynum( pnum );
|
||||
}
|
||||
//if ( !zernum( (*pa)->pp ) && !equnum( (*pa)->pq, num_one ) )
|
||||
//{
|
||||
// wstring ratStr = RatToString(*pa, FMT_FLOAT, radix, precision);
|
||||
// PNUMBER pnum = StringToNumber(ratStr, radix, precision);
|
||||
//
|
||||
// destroyrat( *pa );
|
||||
// *pa = numtorat( pnum, radix);
|
||||
// destroynum( pnum );
|
||||
//}
|
||||
|
||||
remnum( &((*pa)->pp), (*pa)->pq, BASEX );
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -291,12 +291,12 @@ void intrat( PRAT *px, uint32_t radix, int32_t precision)
|
|||
// and only if the bottom part is not one.
|
||||
if ( !zernum( (*px)->pp ) && !equnum( (*px)->pq, num_one ) )
|
||||
{
|
||||
wstring ratStr = RatToString(*px, FMT_FLOAT, radix, precision);
|
||||
PNUMBER pnum = StringToNumber(ratStr, radix, precision);
|
||||
|
||||
destroyrat( *px );
|
||||
*px = numtorat( pnum, radix);
|
||||
destroynum( pnum );
|
||||
//wstring ratStr = RatToString(*px, FMT_FLOAT, radix, precision);
|
||||
//PNUMBER pnum = StringToNumber(ratStr, radix, precision);
|
||||
//
|
||||
//destroyrat( *px );
|
||||
//*px = numtorat( pnum, radix);
|
||||
//destroynum( pnum );
|
||||
|
||||
PRAT pret = nullptr;
|
||||
DUPRAT(pret,*px);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue