Replace custom types with standard ones (#212)

Replace custom types with standard ones
This commit is contained in:
Michał Janiszewski 2019-03-26 22:30:46 +01:00 committed by Daniel Belcher
parent ef3f5e9cbb
commit 7a48f66807
32 changed files with 478 additions and 396 deletions

View File

@ -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

View File

@ -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) ||

View File

@ -13,7 +13,7 @@ using namespace std;
using namespace CalcEngine;
namespace {
void IFT(HRESULT hr)
void IFT(ResultCode hr)
{
if (FAILED(hr))
{

View File

@ -28,10 +28,10 @@ namespace CalcEngine
PNUMBER Number::ToPNUMBER() const
{
PNUMBER ret = _createnum(static_cast<ULONG>(this->Mantissa().size()) + 1);
PNUMBER ret = _createnum(static_cast<uint32_t>(this->Mantissa().size()) + 1);
ret->sign = this->Sign();
ret->exp = this->Exp();
ret->cdigit = static_cast<long>(this->Mantissa().size());
ret->cdigit = static_cast<int32_t>(this->Mantissa().size());
MANTTYPE *ptrRet = ret->mant;
for (auto const& digit : this->Mantissa())

View File

@ -31,7 +31,7 @@ namespace CalcEngine
Rational::Rational(int32_t i)
{
PRAT pr = longtorat(static_cast<long>(i));
PRAT pr = i32torat(static_cast<int32_t>(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<unsigned long>(ui));
PRAT pr = Ui32torat(static_cast<uint32_t>(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);

View File

@ -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);

View File

@ -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',';

View File

@ -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)
{
}
}

View File

@ -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;

View File

@ -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)) };

View File

@ -133,7 +133,7 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
break;
}
}
catch (DWORD dwErrCode)
catch (uint32_t dwErrCode)
{
DisplayError(dwErrCode);

View File

@ -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

View File

@ -212,7 +212,7 @@ namespace CalculationManager
/// <summary>
/// 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.
/// </summary>
/// <param name="command">Enum Command</command>
@ -235,7 +235,7 @@ namespace CalculationManager
this->SetProgrammerMode();
break;
default:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(command));
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(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<WPARAM>(Command::CommandINV));
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandSIN));
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandSIN));
break;
case Command::CommandACOS:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV));
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandCOS));
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandCOS));
break;
case Command::CommandATAN:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV));
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandTAN));
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandTAN));
break;
case Command::CommandPOWE:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV));
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandLN));
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandLN));
break;
case Command::CommandASINH:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV));
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandSINH));
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandSINH));
break;
case Command::CommandACOSH:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV));
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandCOSH));
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandCOSH));
break;
case Command::CommandATANH:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandINV));
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(Command::CommandTANH));
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandINV));
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(Command::CommandTANH));
break;
case Command::CommandFE:
m_isExponentialFormat = !m_isExponentialFormat;
[[fallthrough]];
default:
m_currentCalculatorEngine->ProcessCommand(static_cast<WPARAM>(command));
m_currentCalculatorEngine->ProcessCommand(static_cast<OpCode>(command));
break;
}
}

View File

@ -3,13 +3,15 @@
#pragma once
#include "Ratpack/CalcErr.h"
template <typename TType>
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<unsigned>(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 <std::wstring, int> 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;

View File

@ -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<IHistoryDisplay> pHistoryDisplay);
void ProcessCommand(WPARAM wID);
void DisplayError (DWORD nError);
void ProcessCommand(OpCode wID);
void DisplayError (uint32_t nError);
std::unique_ptr<CalcEngine::Rational> 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);

View File

@ -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();

View File

@ -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);

View File

@ -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)

View File

@ -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 );

View File

@ -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<ULONG>(numberString.length()));
createnum(pnumret, static_cast<uint32_t>(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<long>(pos);
expValue += static_cast<int32_t>(pos);
}
else
{
@ -683,7 +755,7 @@ PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precis
}
else
{
while (pnumret->cdigit < static_cast<long>(numberString.length()))
while (pnumret->cdigit < static_cast<int32_t>(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<int32_t>(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 )
{

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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<PNUMBER> numberList{ longtonum(0L, radix) };
for (unsigned long i = 1; i < radix; i++)
list<PNUMBER> 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;

View File

@ -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,

View File

@ -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);

View File

@ -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<int32_t>(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;

View File

@ -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 {

View File

@ -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);

View File

@ -21,6 +21,7 @@
#include <memory>
#include <vector>
#include <limits>
#include <list>
#include <regex>
#include <unordered_map>
#include <intsafe.h>

View File

@ -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