Updating comments per the C++ core guidelines and removing trailing whitespace (#194)
Fixed comments that were inconsistent with the style guidelines described in C++ core guidelines and the modern C++/WinRT language projections and removed trailing whitespace. Inserted a space after the beginning of the comment so the text wasn't touching the // on all occurrences. Removed all occurrences of trailing whitespace
This commit is contained in:
@@ -413,7 +413,7 @@ int CHistoryCollector::AddCommand(_In_ const std::shared_ptr<IExpressionCommand>
|
||||
return nCommands - 1;
|
||||
}
|
||||
|
||||
//To Update the operands in the Expression according to the current Radix
|
||||
// To Update the operands in the Expression according to the current Radix
|
||||
void CHistoryCollector::UpdateHistoryExpression(uint32_t radix, int32_t precision)
|
||||
{
|
||||
if (m_spTokens != nullptr)
|
||||
@@ -451,7 +451,7 @@ void CHistoryCollector::SetDecimalSymbol(wchar_t decimalSymbol)
|
||||
m_decimalSymbol = decimalSymbol;
|
||||
}
|
||||
|
||||
//Update the commands corresponding to the passed string Number
|
||||
// Update the commands corresponding to the passed string Number
|
||||
std::shared_ptr<CalculatorVector<int>> CHistoryCollector::GetOperandCommandsFromString(wstring_view numStr)
|
||||
{
|
||||
std::shared_ptr<CalculatorVector<int>> commands = std::make_shared<CalculatorVector<int>>();
|
||||
|
@@ -29,7 +29,7 @@ using namespace CalcEngine;
|
||||
namespace {
|
||||
// NPrecedenceOfOp
|
||||
//
|
||||
// returns a virtual number for precedence for the operator. We expect binary operator only, otherwise the lowest number
|
||||
// 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)
|
||||
{
|
||||
@@ -54,13 +54,13 @@ namespace {
|
||||
|
||||
// HandleErrorCommand
|
||||
//
|
||||
// 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
|
||||
// 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)
|
||||
{
|
||||
if (!IsGuiSettingOpCode(idc))
|
||||
{
|
||||
// we would have saved the prev command. Need to forget this state
|
||||
// We would have saved the prev command. Need to forget this state
|
||||
m_nTempCom = m_nLastCom;
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
|
||||
}
|
||||
}
|
||||
|
||||
// Toggle Record/Display mode if appropriate.
|
||||
// Toggle Record/Display mode if appropriate.
|
||||
if (m_bRecord)
|
||||
{
|
||||
if (IsOpInRange(wParam, IDC_AND, IDC_MMINUS) ||
|
||||
@@ -182,7 +182,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
|
||||
// BINARY OPERATORS:
|
||||
if (IsBinOpCode(wParam))
|
||||
{
|
||||
/* Change the operation if last input was operation. */
|
||||
// Change the operation if last input was operation.
|
||||
if (IsBinOpCode(m_nLastCom))
|
||||
{
|
||||
INT nPrev;
|
||||
@@ -574,7 +574,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
|
||||
m_lastVal = 0;
|
||||
if (IsBinOpCode(m_nLastCom))
|
||||
{
|
||||
// We want 1 + ( to start as 1 + (0. Any number you type replaces 0. But if it is 1 + 3 (, it is
|
||||
// We want 1 + ( to start as 1 + (0. Any number you type replaces 0. But if it is 1 + 3 (, it is
|
||||
// treated as 1 + (3
|
||||
m_currentVal = 0;
|
||||
}
|
||||
@@ -803,7 +803,7 @@ void CCalcEngine::CheckAndAddLastBinOpToHistory(bool addToHistory)
|
||||
{
|
||||
if (m_HistoryCollector.FOpndAddedToHistory())
|
||||
{
|
||||
// if last time opnd was added but the last command was not a binary operator, then it must have come
|
||||
// if last time opnd was added but the last command was not a binary operator, then it must have come
|
||||
// from commands which add the operand, like unary operator. So history at this is showing 1 + sqrt(4)
|
||||
// but in reality the sqrt(4) is getting replaced by new number (may be unary op, or MR or SUM etc.)
|
||||
// So erase the last operand
|
||||
@@ -855,7 +855,7 @@ void CCalcEngine::DisplayAnnounceBinaryOperator()
|
||||
}
|
||||
|
||||
// Unary operator Function Name table Element
|
||||
// since unary operators button names aren't exactly friendly for history purpose,
|
||||
// since unary operators button names aren't exactly friendly for history purpose,
|
||||
// we have this separate table to get its localized name and for its Inv function if it exists.
|
||||
typedef struct
|
||||
{
|
||||
@@ -1027,7 +1027,7 @@ wstring CCalcEngine::GetCurrentResultForRadix(uint32_t radix, int32_t precision)
|
||||
wstring numberString = GetStringForDisplay(rat, radix);
|
||||
if (!numberString.empty())
|
||||
{
|
||||
//revert the precision to previously stored precision
|
||||
// Revert the precision to previously stored precision
|
||||
ChangeConstants(m_radix, m_precision);
|
||||
}
|
||||
|
||||
|
@@ -70,7 +70,7 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r
|
||||
|
||||
uint64_t w64Bits = result.ToUInt64_t();
|
||||
uint64_t lsb = ((w64Bits & 0x01) == 1) ? 1 : 0;
|
||||
w64Bits >>= 1; //RShift by 1
|
||||
w64Bits >>= 1; // RShift by 1
|
||||
w64Bits |= (lsb << (m_dwWordBitWidth - 1));
|
||||
|
||||
result = w64Bits;
|
||||
|
@@ -12,10 +12,10 @@ using namespace std;
|
||||
// dont change that.
|
||||
void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwidth)
|
||||
{
|
||||
// When in integer mode, the number is represented in 2's complement form. When a bit width is changing, we can
|
||||
// change the number representation back to sign, abs num form in ratpak. Soon when display sees this, it will
|
||||
// convert to 2's complement form, but this time all high bits will be propagated. Eg. -127, in byte mode is
|
||||
// represented as 1000,0001. This puts it back as sign=-1, 01111111 . But DisplayNum will see this and convert it
|
||||
// When in integer mode, the number is represented in 2's complement form. When a bit width is changing, we can
|
||||
// change the number representation back to sign, abs num form in ratpak. Soon when display sees this, it will
|
||||
// convert to 2's complement form, but this time all high bits will be propagated. Eg. -127, in byte mode is
|
||||
// represented as 1000,0001. This puts it back as sign=-1, 01111111 . But DisplayNum will see this and convert it
|
||||
// back to 1111,1111,1000,0001 when in Word mode.
|
||||
if (m_fIntegerMode)
|
||||
{
|
||||
@@ -46,7 +46,7 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwid
|
||||
// inform ratpak that a change in base or precision has occurred
|
||||
BaseOrPrecisionChanged();
|
||||
|
||||
// display the correct number for the new state (ie convert displayed
|
||||
// display the correct number for the new state (ie convert displayed
|
||||
// number to correct base)
|
||||
DisplayNum();
|
||||
}
|
||||
@@ -143,7 +143,7 @@ void CCalcEngine::UpdateMaxIntDigits()
|
||||
if (m_fIntegerMode)
|
||||
{
|
||||
m_cIntDigitsSav = static_cast<int>(m_maxDecimalValueStrings[m_numwidth].length()) - 1;
|
||||
// This is the max digits you can enter a decimal in fixed width mode aka integer mode -1. The last digit
|
||||
// This is the max digits you can enter a decimal in fixed width mode aka integer mode -1. The last digit
|
||||
// has to be checked separately
|
||||
}
|
||||
else
|
||||
@@ -161,10 +161,10 @@ void CCalcEngine::ChangeBaseConstants(uint32_t radix, int maxIntDigits, int32_t
|
||||
{
|
||||
if (10 == radix)
|
||||
{
|
||||
ChangeConstants(radix, precision); // Base 10 precision for internal computing still needs to be 32, to
|
||||
ChangeConstants(radix, precision); // Base 10 precision for internal computing still needs to be 32, to
|
||||
// take care of decimals precisely. For eg. to get the HI word of a qword, we do a rsh, which depends on getting
|
||||
// 18446744073709551615 / 4294967296 = 4294967295.9999917... This is important it works this and doesn't reduce
|
||||
// the precision to number of digits allowed to enter. In other words, precision and # of allowed digits to be
|
||||
// 18446744073709551615 / 4294967296 = 4294967295.9999917... This is important it works this and doesn't reduce
|
||||
// the precision to number of digits allowed to enter. In other words, precision and # of allowed digits to be
|
||||
// entered are different.
|
||||
}
|
||||
else
|
||||
|
@@ -23,7 +23,7 @@ unsigned int CalculatorHistory::AddToHistory(_In_ shared_ptr<CalculatorVector <p
|
||||
|
||||
// to be changed when pszexp is back
|
||||
tokens->GetString(&generatedExpression);
|
||||
// Prefixing and suffixing the special Unicode markers to ensure that the expression
|
||||
// Prefixing and suffixing the special Unicode markers to ensure that the expression
|
||||
// in the history doesn't get broken for RTL languages
|
||||
spHistoryItem->historyItemVector.expression = L'\u202d' + generatedExpression + L'\u202c';
|
||||
spHistoryItem->historyItemVector.result = wstring(result);
|
||||
|
@@ -300,7 +300,7 @@ namespace CalculationManager
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert Command to unsigned char.
|
||||
/// Convert Command to unsigned char.
|
||||
/// Since some Commands are higher than 255, they are saved after subtracting 255
|
||||
/// The smallest Command is CommandSIGN = 80, thus, subtracted value does not overlap with other values.
|
||||
/// </summary>
|
||||
@@ -435,9 +435,9 @@ namespace CalculationManager
|
||||
if (*commandItr >= MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::MemorizeNumber) &&
|
||||
*commandItr <= MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::MemorizedNumberClearAll))
|
||||
{
|
||||
//MemoryCommands(which have values above 255) are pushed on m_savedCommands upon casting to unsigned char.
|
||||
//SerializeCommands uses m_savedCommands, which is then used in DeSerializeCommands.
|
||||
//Hence, a simple cast to MemoryCommand is not sufficient.
|
||||
// MemoryCommands(which have values above 255) are pushed on m_savedCommands upon casting to unsigned char.
|
||||
// SerializeCommands uses m_savedCommands, which is then used in DeSerializeCommands.
|
||||
// Hence, a simple cast to MemoryCommand is not sufficient.
|
||||
MemoryCommand memoryCommand = static_cast<MemoryCommand>(*commandItr + UCHAR_MAX + 1);
|
||||
unsigned int indexOfMemory = 0;
|
||||
switch (memoryCommand)
|
||||
@@ -761,7 +761,7 @@ namespace CalculationManager
|
||||
}
|
||||
|
||||
void CalculatorManager::UpdateMaxIntDigits()
|
||||
{
|
||||
{
|
||||
m_currentCalculatorEngine->UpdateMaxIntDigits();
|
||||
}
|
||||
|
||||
@@ -785,7 +785,7 @@ namespace CalculationManager
|
||||
/// How Rational is serialized :
|
||||
/// Serialized Rational.P(Number) + Serialized Rational.Q(Number)
|
||||
/// How Number is saved :
|
||||
/// [0] = Rational.P.Sign
|
||||
/// [0] = Rational.P.Sign
|
||||
/// [1] = Rational.P.Mantissa.size
|
||||
/// [2] = Rational.P.Exp
|
||||
/// [3] = Rational.P.Mantissa[0]
|
||||
@@ -823,7 +823,7 @@ namespace CalculationManager
|
||||
/// <summary>
|
||||
/// Serialize Number to vector of long
|
||||
/// How Number is saved :
|
||||
/// [0] = Number.Sign
|
||||
/// [0] = Number.Sign
|
||||
/// [1] = Number.Mantissa.size
|
||||
/// [2] = Number.Exp
|
||||
/// [3] = Number.Mantissa[0]
|
||||
@@ -850,7 +850,7 @@ namespace CalculationManager
|
||||
/// <summary>
|
||||
/// DeserializeNumber vector and construct a Number
|
||||
/// How Number is saved :
|
||||
/// [0] = Number.Sign
|
||||
/// [0] = Number.Sign
|
||||
/// [1] = Number.Mantissa.size
|
||||
/// [2] = Number.Exp
|
||||
/// [3] = Number.Mantissa[0]
|
||||
|
@@ -27,9 +27,9 @@ namespace CalculationManager
|
||||
ProgrammerModePrecision = 64
|
||||
};
|
||||
|
||||
// Numbering continues from the Enum Command from Command.h
|
||||
// Numbering continues from the Enum Command from Command.h
|
||||
// with some gap to ensure there is no overlap of these ids
|
||||
// when static_cast<unsigned char> is performed on these ids
|
||||
// when static_cast<unsigned char> is performed on these ids
|
||||
// they shouldn't fall in any number range greater than 80. So never
|
||||
// make the memory command ids go below 330
|
||||
enum class MemoryCommand
|
||||
|
@@ -10,7 +10,7 @@ namespace CalculationManager
|
||||
public:
|
||||
virtual ~IResourceProvider() { }
|
||||
|
||||
// Should return a string from the resource table for strings used
|
||||
// Should return a string from the resource table for strings used
|
||||
// by the calculation engine. The strings that must be defined
|
||||
// and the ids to define them with can be seen in EngineStrings.h
|
||||
// with SIDS prefix. Additionally it must provide values for string
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
template <typename TType>
|
||||
class CalculatorVector
|
||||
class CalculatorVector
|
||||
{
|
||||
public:
|
||||
HRESULT GetAt(_In_opt_ unsigned int index, _Out_ TType *item)
|
||||
|
@@ -94,7 +94,7 @@ namespace CalculationManager
|
||||
CommandFAC = 113,
|
||||
CommandREC = 114,
|
||||
CommandDMS = 115,
|
||||
CommandCUBEROOT = 116, //x ^ 1/3
|
||||
CommandCUBEROOT = 116, // x ^ 1/3
|
||||
CommandPOW10 = 117, // 10 ^ x
|
||||
CommandPERCENT = 118,
|
||||
|
||||
|
@@ -75,19 +75,19 @@ void CUnaryCommand::Accept(_In_ ISerializeCommandVisitor &commandVisitor)
|
||||
CBinaryCommand::CBinaryCommand(int command) :m_command(command)
|
||||
{}
|
||||
|
||||
void CBinaryCommand::SetCommand(int command)
|
||||
{
|
||||
m_command = command;
|
||||
void CBinaryCommand::SetCommand(int command)
|
||||
{
|
||||
m_command = command;
|
||||
}
|
||||
|
||||
int CBinaryCommand::GetCommand() const
|
||||
{
|
||||
return m_command;
|
||||
{
|
||||
return m_command;
|
||||
}
|
||||
|
||||
CalculationManager::CommandType CBinaryCommand::GetCommandType() const
|
||||
{
|
||||
return CalculationManager::CommandType::BinaryCommand;
|
||||
{
|
||||
return CalculationManager::CommandType::BinaryCommand;
|
||||
}
|
||||
|
||||
void CBinaryCommand::Accept(_In_ ISerializeCommandVisitor &commandVisitor)
|
||||
@@ -111,8 +111,8 @@ void COpndCommand::Initialize(Rational const& rat)
|
||||
}
|
||||
|
||||
const shared_ptr<CalculatorVector<int>> & COpndCommand::GetCommands() const
|
||||
{
|
||||
return m_commands;
|
||||
{
|
||||
return m_commands;
|
||||
}
|
||||
|
||||
void COpndCommand::SetCommands(shared_ptr<CalculatorVector<int>> const& commands)
|
||||
@@ -166,7 +166,7 @@ void COpndCommand::RemoveFromEnd()
|
||||
{
|
||||
unsigned int nCommands;
|
||||
m_commands->GetSize(&nCommands);
|
||||
|
||||
|
||||
if (nCommands == 1)
|
||||
{
|
||||
ClearAllAndAppendCommand(CalculationManager::Command::Command0);
|
||||
@@ -185,8 +185,8 @@ void COpndCommand::RemoveFromEnd()
|
||||
}
|
||||
|
||||
bool COpndCommand::IsNegative() const
|
||||
{
|
||||
return m_fNegative;
|
||||
{
|
||||
return m_fNegative;
|
||||
}
|
||||
|
||||
bool COpndCommand::IsSciFmt() const
|
||||
@@ -195,13 +195,13 @@ bool COpndCommand::IsSciFmt() const
|
||||
}
|
||||
|
||||
bool COpndCommand::IsDecimalPresent() const
|
||||
{
|
||||
return m_fDecimal;
|
||||
{
|
||||
return m_fDecimal;
|
||||
}
|
||||
|
||||
CalculationManager::CommandType COpndCommand::GetCommandType() const
|
||||
{
|
||||
return CalculationManager::CommandType::OperandCommand;
|
||||
{
|
||||
return CalculationManager::CommandType::OperandCommand;
|
||||
}
|
||||
|
||||
void COpndCommand::ClearAllAndAppendCommand(CalculationManager::Command command)
|
||||
@@ -283,7 +283,7 @@ const wstring & COpndCommand::GetToken(wchar_t decimalSymbol)
|
||||
m_token.clear();
|
||||
m_token.append(&chZero);
|
||||
}
|
||||
|
||||
|
||||
return m_token;
|
||||
}
|
||||
|
||||
|
@@ -45,7 +45,7 @@
|
||||
|
||||
|
||||
// Key IDs:
|
||||
// These id's must be consecutive from IDC_FIRSTCONTROL to IDC_LASTCONTROL.
|
||||
// These id's must be consecutive from IDC_FIRSTCONTROL to IDC_LASTCONTROL.
|
||||
// The actual values don't matter but the order and sequence are very important.
|
||||
// Also, the order of the controls must match the order of the control names
|
||||
// in the string table.
|
||||
@@ -97,7 +97,7 @@
|
||||
#define IDC_FAC 113
|
||||
#define IDC_REC 114
|
||||
#define IDC_DMS 115
|
||||
#define IDC_CUBEROOT 116 //x ^ 1/3
|
||||
#define IDC_CUBEROOT 116 // x ^ 1/3
|
||||
#define IDC_POW10 117 // 10 ^ x
|
||||
#define IDC_PERCENT 118
|
||||
#define IDC_UNARYLAST IDC_PERCENT
|
||||
|
@@ -85,7 +85,7 @@ private:
|
||||
// if it hasn't yet been computed
|
||||
bool m_bChangeOp; /* Flag for changing operation. */
|
||||
bool m_bRecord; // Global mode: recording or displaying
|
||||
bool m_bSetCalcState; //Flag for setting the engine result state
|
||||
bool m_bSetCalcState; // Flag for setting the engine result state
|
||||
CalcEngine::CalcInput m_input; // Global calc input object for decimal strings
|
||||
eNUMOBJ_FMT m_nFE; /* Scientific notation conversion flag. */
|
||||
CalcEngine::Rational m_maxTrigonometricNum;
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#include "Rational.h"
|
||||
|
||||
// Space to hold enough digits for a quadword binary number (64) plus digit separator strings for that number (20)
|
||||
constexpr int MAX_STRLEN = 84;
|
||||
constexpr int MAX_STRLEN = 84;
|
||||
|
||||
namespace CalcEngine
|
||||
{
|
||||
|
@@ -128,7 +128,7 @@
|
||||
#define SIDS_NFACTORIAL L"33"
|
||||
#define SIDS_RECIPROCAL L"34"
|
||||
#define SIDS_DMS L"35"
|
||||
#define SIDS_CUBEROOT L"36"
|
||||
#define SIDS_CUBEROOT L"36"
|
||||
#define SIDS_POWTEN L"37"
|
||||
#define SIDS_PERCENT L"38"
|
||||
#define SIDS_SCIENTIFIC_NOTATION L"39"
|
||||
@@ -200,7 +200,7 @@
|
||||
#define SIDS_NOMEM L"105"
|
||||
#define SIDS_TOOMANY L"106"
|
||||
#define SIDS_OVERFLOW L"107"
|
||||
#define SIDS_NORESULT L"108"
|
||||
#define SIDS_NORESULT L"108"
|
||||
#define SIDS_INSUFFICIENT_DATA L"109"
|
||||
// 110 is skipped by CSTRINGSENGMAX
|
||||
#define SIDS_ERR_UNK_CH L"111"
|
||||
@@ -214,7 +214,7 @@
|
||||
#define SIDS_ERR_INPUT_OVERFLOW L"119"
|
||||
#define SIDS_ERR_OUTPUT_OVERFLOW L"120"
|
||||
|
||||
__declspec(selectany) std::wstring g_sids[] =
|
||||
__declspec(selectany) std::wstring g_sids[] =
|
||||
{
|
||||
std::wstring(SIDS_PLUS_MINUS),
|
||||
std::wstring(SIDS_C),
|
||||
@@ -252,7 +252,7 @@ __declspec(selectany) std::wstring g_sids[] =
|
||||
std::wstring(SIDS_NFACTORIAL),
|
||||
std::wstring(SIDS_RECIPROCAL),
|
||||
std::wstring(SIDS_DMS),
|
||||
std::wstring(SIDS_CUBEROOT),
|
||||
std::wstring(SIDS_CUBEROOT),
|
||||
std::wstring(SIDS_POWTEN),
|
||||
std::wstring(SIDS_PERCENT),
|
||||
std::wstring(SIDS_SCIENTIFIC_NOTATION),
|
||||
@@ -324,7 +324,7 @@ __declspec(selectany) std::wstring g_sids[] =
|
||||
std::wstring(SIDS_NOMEM),
|
||||
std::wstring(SIDS_TOOMANY),
|
||||
std::wstring(SIDS_OVERFLOW),
|
||||
std::wstring(SIDS_NORESULT),
|
||||
std::wstring(SIDS_NORESULT),
|
||||
std::wstring(SIDS_INSUFFICIENT_DATA),
|
||||
std::wstring(SIDS_ERR_UNK_CH),
|
||||
std::wstring(SIDS_ERR_UNK_FN),
|
||||
|
@@ -10,8 +10,8 @@
|
||||
// maximum depth you can get by precedence. It is just an array's size limit.
|
||||
static constexpr size_t MAXPRECDEPTH = 25;
|
||||
|
||||
// Helper class really a internal class to CCalcEngine, to accumulate each history line of text by collecting the
|
||||
// operands, operator, unary operator etc. Since it is a separate entity, it can be unit tested on its own but does
|
||||
// Helper class really a internal class to CCalcEngine, to accumulate each history line of text by collecting the
|
||||
// operands, operator, unary operator etc. Since it is a separate entity, it can be unit tested on its own but does
|
||||
// rely on CCalcEngine calling it in appropriate order.
|
||||
class CHistoryCollector {
|
||||
public:
|
||||
@@ -39,13 +39,13 @@ private:
|
||||
ICalcDisplay *m_pCalcDisplay;
|
||||
|
||||
int m_iCurLineHistStart; // index of the beginning of the current equation
|
||||
// a sort of state, set to the index before 2 after 2 in the expression 2 + 3 say. Useful for auto correct portion of history and for
|
||||
// a sort of state, set to the index before 2 after 2 in the expression 2 + 3 say. Useful for auto correct portion of history and for
|
||||
// attaching the unary op around the last operand
|
||||
int m_lastOpStartIndex; // index of the beginning of the last operand added to the history
|
||||
int m_lastBinOpStartIndex; // index of the beginning of the last binary operator added to the history
|
||||
std::array<int, MAXPRECDEPTH> m_operandIndices; // Stack of index of opnd's beginning for each '('. A parallel array to m_hnoParNum, but abstracted independently of that
|
||||
int m_curOperandIndex; // Stack index for the above stack
|
||||
bool m_bLastOpndBrace; // iff the last opnd in history is already braced so we can avoid putting another one for unary operator
|
||||
bool m_bLastOpndBrace; // iff the last opnd in history is already braced so we can avoid putting another one for unary operator
|
||||
wchar_t m_decimalSymbol;
|
||||
std::shared_ptr<CalculatorVector <std::pair<std::wstring, int>>> m_spTokens;
|
||||
std::shared_ptr<CalculatorVector<std::shared_ptr<IExpressionCommand>>> m_spCommands;
|
||||
|
@@ -2,17 +2,17 @@
|
||||
// Licensed under the MIT License.
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Package Title ratpak
|
||||
// File basex.c
|
||||
// Copyright (C) 1995-97 Microsoft
|
||||
// Date 03-14-97
|
||||
//
|
||||
//
|
||||
// Description
|
||||
//
|
||||
// Contains number routines for internal base computations, these assume
|
||||
// internal base is a power of 2.
|
||||
//
|
||||
// Package Title ratpak
|
||||
// File basex.c
|
||||
// Copyright (C) 1995-97 Microsoft
|
||||
// Date 03-14-97
|
||||
//
|
||||
//
|
||||
// Description
|
||||
//
|
||||
// Contains number routines for internal base computations, these assume
|
||||
// internal base is a power of 2.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "pch.h"
|
||||
#include "ratpak.h"
|
||||
@@ -41,7 +41,7 @@ void __inline mulnumx( PNUMBER *pa, PNUMBER b )
|
||||
{
|
||||
// If b is not one we multiply
|
||||
if ( (*pa)->cdigit > 1 || (*pa)->mant[0] != 1 || (*pa)->exp != 0 )
|
||||
{
|
||||
{
|
||||
// pa and b are both non-one.
|
||||
_mulnumx( pa, b );
|
||||
}
|
||||
@@ -91,7 +91,7 @@ void _mulnumx( PNUMBER *pa, PNUMBER b )
|
||||
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
|
||||
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.
|
||||
|
||||
@@ -110,8 +110,8 @@ void _mulnumx( PNUMBER *pa, PNUMBER b )
|
||||
{
|
||||
da = *ptra++;
|
||||
ptrb = b->mant;
|
||||
|
||||
// Shift ptrc, and ptrcoffset, one for each digit
|
||||
|
||||
// Shift ptrc, and ptrcoffset, one for each digit
|
||||
ptrc = ptrcoffset++;
|
||||
|
||||
for ( ibdigit = b->cdigit; ibdigit > 0; ibdigit-- )
|
||||
@@ -126,28 +126,28 @@ void _mulnumx( PNUMBER *pa, PNUMBER b )
|
||||
c->cdigit++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If result is nonzero, or while result of carry is nonzero...
|
||||
while ( mcy || cy )
|
||||
{
|
||||
|
||||
|
||||
// update carry from addition(s) and multiply.
|
||||
cy += (TWO_MANTTYPE)ptrc[icdigit]+((DWORD)mcy&((DWORD)~BASEX));
|
||||
|
||||
// update result digit from
|
||||
|
||||
// update result digit from
|
||||
ptrc[icdigit++]=(MANTTYPE)((DWORD)cy&((DWORD)~BASEX));
|
||||
|
||||
|
||||
// update carries from
|
||||
mcy >>= BASEXPWR;
|
||||
cy >>= BASEXPWR;
|
||||
}
|
||||
|
||||
|
||||
ptrb++;
|
||||
ptrc++;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// prevent different kinds of zeros, by stripping leading duplicate zeros.
|
||||
// digits are in order of increasing significance.
|
||||
while ( c->cdigit > 1 && c->mant[c->cdigit-1] == 0 )
|
||||
@@ -198,7 +198,7 @@ void numpowlongx( _Inout_ PNUMBER *proot, _In_ long power )
|
||||
}
|
||||
destroynum( *proot );
|
||||
*proot=lret;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision);
|
||||
@@ -275,14 +275,14 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
|
||||
a=*pa;
|
||||
if ( thismax < a->cdigit )
|
||||
{
|
||||
// a has more digits than precision specified, bump up digits to shoot
|
||||
// a has more digits than precision specified, bump up digits to shoot
|
||||
// for.
|
||||
thismax = a->cdigit;
|
||||
}
|
||||
|
||||
if ( thismax < b->cdigit )
|
||||
{
|
||||
// b has more digits than precision specified, bump up digits to shoot
|
||||
// b has more digits than precision specified, bump up digits to shoot
|
||||
// for.
|
||||
thismax = b->cdigit;
|
||||
}
|
||||
@@ -317,7 +317,7 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
|
||||
digit *= 2;
|
||||
}
|
||||
if ( lessnum( rem, tmp ) )
|
||||
{
|
||||
{
|
||||
// too far, back up...
|
||||
destroynum( tmp );
|
||||
digit /= 2;
|
||||
@@ -326,7 +326,7 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
|
||||
}
|
||||
|
||||
tmp->sign *= -1;
|
||||
addnum( &rem, tmp, BASEX );
|
||||
addnum( &rem, tmp, BASEX );
|
||||
destroynum( tmp );
|
||||
destroynum( lasttmp );
|
||||
*ptrc |= digit;
|
||||
@@ -341,7 +341,7 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
|
||||
}
|
||||
|
||||
if ( !cdigits )
|
||||
{
|
||||
{
|
||||
// A zero, make sure no weird exponents creep in
|
||||
c->exp = 0;
|
||||
c->cdigit = 1;
|
||||
@@ -350,7 +350,7 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
|
||||
{
|
||||
c->cdigit = cdigits;
|
||||
c->exp -= cdigits;
|
||||
// prevent different kinds of zeros, by stripping leading duplicate
|
||||
// prevent different kinds of zeros, by stripping leading duplicate
|
||||
// zeros. digits are in order of increasing significance.
|
||||
while ( c->cdigit > 1 && c->mant[c->cdigit-1] == 0 )
|
||||
{
|
||||
|
@@ -801,7 +801,7 @@ PNUMBER longtonum( long inlong, uint32_t radix)
|
||||
// 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 unsigned long value passed in. Being unsigned number it has no
|
||||
// negative number and takes the full range of unsigned number
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -817,7 +817,7 @@ PNUMBER Ulongtonum(unsigned long inlong, uint32_t radix)
|
||||
pnumret->cdigit = 0;
|
||||
pnumret->exp = 0;
|
||||
pnumret->sign = 1;
|
||||
|
||||
|
||||
do {
|
||||
*pmant++ = (MANTTYPE)(inlong % radix);
|
||||
inlong /= radix;
|
||||
|
@@ -46,8 +46,8 @@ void _exprat( PRAT *px, int32_t precision)
|
||||
{
|
||||
CREATETAYLOR();
|
||||
|
||||
addnum(&(pret->pp),num_one, BASEX);
|
||||
addnum(&(pret->pq),num_one, BASEX);
|
||||
addnum(&(pret->pp),num_one, BASEX);
|
||||
addnum(&(pret->pq),num_one, BASEX);
|
||||
DUPRAT(thisterm,pret);
|
||||
|
||||
n2=longtonum(0L, BASEX);
|
||||
@@ -81,7 +81,7 @@ void exprat( PRAT *px, uint32_t radix, int32_t precision)
|
||||
ratpowlong( &pwr, intpwr, precision);
|
||||
|
||||
subrat(px, pint, precision);
|
||||
|
||||
|
||||
// It just so happens to be an integral power of e.
|
||||
if ( rat_gt( *px, rat_negsmallest, precision) && rat_lt( *px, rat_smallest, precision) )
|
||||
{
|
||||
@@ -131,7 +131,7 @@ void _lograt( PRAT *px, int32_t precision)
|
||||
CREATETAYLOR();
|
||||
|
||||
createrat(thisterm);
|
||||
|
||||
|
||||
// sub one from x
|
||||
(*px)->pq->sign *= -1;
|
||||
addnum(&((*px)->pp),(*px)->pq, BASEX);
|
||||
@@ -158,14 +158,14 @@ void lograt( PRAT *px, int32_t precision)
|
||||
bool fneglog;
|
||||
PRAT pwr = nullptr; // pwr is the large scaling factor.
|
||||
PRAT offset = nullptr; // offset is the incremental scaling factor.
|
||||
|
||||
|
||||
|
||||
|
||||
// Check for someone taking the log of zero or a negative number.
|
||||
if ( rat_le( *px, rat_zero, precision) )
|
||||
{
|
||||
throw( CALC_E_DOMAIN );
|
||||
}
|
||||
|
||||
|
||||
// Get number > 1, for scaling
|
||||
fneglog = rat_lt( *px, rat_one, precision);
|
||||
if ( fneglog )
|
||||
@@ -176,12 +176,12 @@ void lograt( PRAT *px, int32_t precision)
|
||||
(*px)->pp = (*px)->pq;
|
||||
(*px)->pq = pnumtemp;
|
||||
}
|
||||
|
||||
|
||||
// Scale the number within BASEX factor of 1, for the large scale.
|
||||
// log(x*2^(BASEXPWR*k)) = BASEXPWR*k*log(2)+log(x)
|
||||
if ( LOGRAT2(*px) > 1 )
|
||||
{
|
||||
// Take advantage of px's base BASEX to scale quickly down to
|
||||
// Take advantage of px's base BASEX to scale quickly down to
|
||||
// a reasonable range.
|
||||
long intpwr;
|
||||
intpwr=LOGRAT2(*px)-1;
|
||||
@@ -206,17 +206,17 @@ void lograt( PRAT *px, int32_t precision)
|
||||
}
|
||||
|
||||
_lograt(px, precision);
|
||||
|
||||
|
||||
// Add the large and small scaling factors, take into account
|
||||
// small scaling was done in e_to_one_half chunks.
|
||||
divrat(&offset, rat_two, precision);
|
||||
addrat(&pwr, offset, precision);
|
||||
|
||||
|
||||
// And add the resulting scaling factor to the answer.
|
||||
addrat(px, pwr, precision);
|
||||
|
||||
trimit(px, precision);
|
||||
|
||||
|
||||
// If number started out < 1 rescale answer to negative.
|
||||
if ( fneglog )
|
||||
{
|
||||
@@ -224,9 +224,9 @@ void lograt( PRAT *px, int32_t precision)
|
||||
}
|
||||
|
||||
destroyrat(offset);
|
||||
destroyrat(pwr);
|
||||
destroyrat(pwr);
|
||||
}
|
||||
|
||||
|
||||
void log10rat( PRAT *px, int32_t precision)
|
||||
|
||||
{
|
||||
@@ -235,7 +235,7 @@ void log10rat( PRAT *px, int32_t precision)
|
||||
}
|
||||
|
||||
//
|
||||
// return if the given x is even number. The assumption here is its denominator is 1 and we are testing the numerator is
|
||||
// return if the given x is even number. The assumption here is its denominator is 1 and we are testing the numerator is
|
||||
// even or not
|
||||
bool IsEven(PRAT x, uint32_t radix, int32_t precision)
|
||||
{
|
||||
@@ -318,7 +318,7 @@ void powratNumeratorDenominator(PRAT *px, PRAT y, uint32_t radix, int32_t precis
|
||||
// 1. Initialize result.
|
||||
PRAT pxPow = nullptr;
|
||||
DUPRAT(pxPow, *px);
|
||||
|
||||
|
||||
// 2. Calculate pxPow = px ^ yNumerator
|
||||
// if yNumerator is not 1
|
||||
if (!rat_equ(yNumerator, rat_one, precision))
|
||||
@@ -341,7 +341,7 @@ void powratNumeratorDenominator(PRAT *px, PRAT y, uint32_t radix, int32_t precis
|
||||
PRAT originalResult = nullptr;
|
||||
DUPRAT(originalResult, pxPow);
|
||||
powratcomp(&originalResult, oneoveryDenom, radix, precision);
|
||||
|
||||
|
||||
// ##################################
|
||||
// Round the originalResult to roundedResult
|
||||
// ##################################
|
||||
@@ -375,7 +375,7 @@ void powratNumeratorDenominator(PRAT *px, PRAT y, uint32_t radix, int32_t precis
|
||||
else
|
||||
{
|
||||
DUPRAT(*px, originalResult);
|
||||
}
|
||||
}
|
||||
|
||||
destroyrat(oneoveryDenom);
|
||||
destroyrat(originalResult);
|
||||
@@ -429,7 +429,7 @@ void powratcomp(PRAT *px, PRAT y, uint32_t radix, int32_t precision)
|
||||
sign = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
PRAT pxint= nullptr;
|
||||
DUPRAT(pxint,*px);
|
||||
@@ -491,7 +491,7 @@ void powratcomp(PRAT *px, PRAT y, uint32_t radix, int32_t precision)
|
||||
PRAT pNumerator = nullptr;
|
||||
PRAT pDenominator = nullptr;
|
||||
bool fBadExponent = false;
|
||||
|
||||
|
||||
// Get the numbers in arbitrary precision rational number format
|
||||
DUPRAT(pNumerator, rat_zero); // pNumerator->pq is 1 one
|
||||
DUPRAT(pDenominator, rat_zero); // pDenominator->pq is 1 one
|
||||
@@ -516,7 +516,7 @@ void powratcomp(PRAT *px, PRAT y, uint32_t radix, int32_t precision)
|
||||
}
|
||||
destroyrat(pNumerator);
|
||||
destroyrat(pDenominator);
|
||||
|
||||
|
||||
if (fBadExponent)
|
||||
{
|
||||
throw( CALC_E_DOMAIN );
|
||||
|
@@ -73,17 +73,17 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
|
||||
PRAT ratprec = nullptr;
|
||||
PRAT ratRadix = nullptr;
|
||||
long oldprec;
|
||||
|
||||
|
||||
// Set up constants and initial conditions
|
||||
oldprec = precision;
|
||||
ratprec = longtorat( oldprec );
|
||||
|
||||
|
||||
// Find the best 'A' for convergence to the required precision.
|
||||
a=longtorat( radix );
|
||||
lograt(&a, precision);
|
||||
mulrat(&a, ratprec, precision);
|
||||
|
||||
// Really is -ln(n)+1, but -ln(n) will be < 1
|
||||
// Really is -ln(n)+1, but -ln(n) will be < 1
|
||||
// if we scale n between 0.5 and 1.5
|
||||
addrat(&a, rat_two, precision);
|
||||
DUPRAT(tmp,a);
|
||||
@@ -91,9 +91,9 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
|
||||
mulrat(&tmp, *pn, precision);
|
||||
addrat(&a, tmp, precision);
|
||||
addrat(&a, rat_one, precision);
|
||||
|
||||
|
||||
// Calculate the necessary bump in precision and up the precision.
|
||||
// The following code is equivalent to
|
||||
// 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 );
|
||||
@@ -110,7 +110,7 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
|
||||
lograt( &tmp, precision);
|
||||
subrat( &term, tmp, precision);
|
||||
precision += rattolong( 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 );
|
||||
@@ -120,7 +120,7 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
|
||||
// a2=a^2
|
||||
DUPRAT(a2,a);
|
||||
mulrat(&a2, a, precision);
|
||||
|
||||
|
||||
// sum=(1/n)-(a/(n+1))
|
||||
DUPRAT(sum,rat_one);
|
||||
divrat(&sum, *pn, precision);
|
||||
@@ -136,14 +136,14 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
|
||||
divrat(&err, ratRadix, precision);
|
||||
|
||||
// Just get something not tiny in term
|
||||
DUPRAT(term, rat_two );
|
||||
DUPRAT(term, rat_two );
|
||||
|
||||
// Loop until precision is reached, or asked to halt.
|
||||
while ( !zerrat( term ) && rat_gt( term, err, precision) )
|
||||
{
|
||||
addrat(pn, rat_two, precision);
|
||||
|
||||
// WARNING: mixing numbers and rationals here.
|
||||
|
||||
// WARNING: mixing numbers and rationals here.
|
||||
// for speed and efficiency.
|
||||
INC(count);
|
||||
mulnumx(&(factorial->pp),count);
|
||||
@@ -166,15 +166,15 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
|
||||
DUPRAT(term,rat_one);
|
||||
divrat( &term, *pn, precision);
|
||||
subrat( &term, tmp, precision);
|
||||
|
||||
|
||||
divrat (&term, factorial, precision);
|
||||
addrat( &sum, term, precision);
|
||||
ABSRAT(term);
|
||||
}
|
||||
|
||||
|
||||
// Multiply by factor.
|
||||
mulrat( &sum, mpy, precision);
|
||||
|
||||
|
||||
// And cleanup
|
||||
precision = oldprec;
|
||||
destroyrat(ratprec);
|
||||
@@ -199,13 +199,13 @@ void factrat( PRAT *px, uint32_t radix, int32_t precision)
|
||||
PRAT fact = nullptr;
|
||||
PRAT frac = nullptr;
|
||||
PRAT neg_rat_one = nullptr;
|
||||
|
||||
|
||||
if ( rat_gt( *px, rat_max_fact, precision) || rat_lt( *px, rat_min_fact, precision) )
|
||||
{
|
||||
// Don't attempt factorial of anything too large or small.
|
||||
throw CALC_E_OVERFLOW;
|
||||
}
|
||||
|
||||
|
||||
DUPRAT(fact,rat_one);
|
||||
|
||||
DUPRAT(neg_rat_one,rat_one);
|
||||
@@ -226,7 +226,7 @@ void factrat( PRAT *px, uint32_t radix, int32_t precision)
|
||||
mulrat( &fact, *px, precision);
|
||||
subrat( px, rat_one, precision);
|
||||
}
|
||||
|
||||
|
||||
// Added to make numbers 'close enough' to integers use integer factorial.
|
||||
if ( LOGRATRADIX(*px) <= -precision)
|
||||
{
|
||||
|
@@ -69,13 +69,13 @@ void _asinrat( PRAT *px, int32_t precision)
|
||||
|
||||
{
|
||||
CREATETAYLOR();
|
||||
DUPRAT(pret,*px);
|
||||
DUPRAT(pret,*px);
|
||||
DUPRAT(thisterm,*px);
|
||||
DUPNUM(n2,num_one);
|
||||
|
||||
do
|
||||
{
|
||||
NEXTTERM(xx,MULNUM(n2) MULNUM(n2)
|
||||
NEXTTERM(xx,MULNUM(n2) MULNUM(n2)
|
||||
INC(n2) DIVNUM(n2) INC(n2) DIVNUM(n2), precision);
|
||||
}
|
||||
while ( !SMALL_ENOUGH_RAT( thisterm, precision) );
|
||||
@@ -100,7 +100,7 @@ void asinrat( PRAT *px, uint32_t radix, int32_t precision)
|
||||
|
||||
(*px)->pp->sign = 1;
|
||||
(*px)->pq->sign = 1;
|
||||
|
||||
|
||||
// Avoid the really bad part of the asin curve near +/-1.
|
||||
DUPRAT(phack,*px);
|
||||
subrat(&phack, rat_one, precision);
|
||||
@@ -185,15 +185,15 @@ void _acosrat( PRAT *px, int32_t precision)
|
||||
{
|
||||
CREATETAYLOR();
|
||||
|
||||
createrat(thisterm);
|
||||
createrat(thisterm);
|
||||
thisterm->pp=longtonum( 1L, BASEX );
|
||||
thisterm->pq=longtonum( 1L, BASEX );
|
||||
thisterm->pq=longtonum( 1L, BASEX );
|
||||
|
||||
DUPNUM(n2,num_one);
|
||||
|
||||
do
|
||||
{
|
||||
NEXTTERM(xx,MULNUM(n2) MULNUM(n2)
|
||||
NEXTTERM(xx,MULNUM(n2) MULNUM(n2)
|
||||
INC(n2) DIVNUM(n2) INC(n2) DIVNUM(n2), precision);
|
||||
}
|
||||
while ( !SMALL_ENOUGH_RAT( thisterm, precision) );
|
||||
@@ -210,7 +210,7 @@ void acosrat( PRAT *px, uint32_t radix, int32_t precision)
|
||||
|
||||
(*px)->pp->sign = 1;
|
||||
(*px)->pq->sign = 1;
|
||||
|
||||
|
||||
if ( rat_equ( *px, rat_one, precision) )
|
||||
{
|
||||
if ( sgn == -1 )
|
||||
@@ -274,7 +274,7 @@ void _atanrat( PRAT *px, int32_t precision)
|
||||
{
|
||||
CREATETAYLOR();
|
||||
|
||||
DUPRAT(pret,*px);
|
||||
DUPRAT(pret,*px);
|
||||
DUPRAT(thisterm,*px);
|
||||
|
||||
DUPNUM(n2,num_one);
|
||||
@@ -298,7 +298,7 @@ void atanrat( PRAT *px, uint32_t radix, int32_t precision)
|
||||
|
||||
(*px)->pp->sign = 1;
|
||||
(*px)->pq->sign = 1;
|
||||
|
||||
|
||||
if ( rat_gt( (*px), pt_eight_five, precision) )
|
||||
{
|
||||
if ( rat_gt( (*px), rat_two, precision) )
|
||||
@@ -314,7 +314,7 @@ void atanrat( PRAT *px, uint32_t radix, int32_t precision)
|
||||
subrat(px, tmpx, precision);
|
||||
destroyrat( tmpx );
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
(*px)->pp->sign = sgn;
|
||||
DUPRAT(tmpx,*px);
|
||||
|
@@ -60,7 +60,7 @@ void asinhrat( PRAT *px, uint32_t radix, int32_t precision)
|
||||
if ( rat_gt( *px, pt_eight_five, precision) || rat_lt( *px, neg_pt_eight_five, precision) )
|
||||
{
|
||||
PRAT ptmp = nullptr;
|
||||
DUPRAT(ptmp,(*px));
|
||||
DUPRAT(ptmp,(*px));
|
||||
mulrat(&ptmp, *px, precision);
|
||||
addrat(&ptmp, rat_one, precision);
|
||||
rootrat(&ptmp, rat_two, radix, precision);
|
||||
@@ -73,14 +73,14 @@ void asinhrat( PRAT *px, uint32_t radix, int32_t precision)
|
||||
CREATETAYLOR();
|
||||
xx->pp->sign *= -1;
|
||||
|
||||
DUPRAT(pret,(*px));
|
||||
DUPRAT(pret,(*px));
|
||||
DUPRAT(thisterm,(*px));
|
||||
|
||||
DUPNUM(n2,num_one);
|
||||
|
||||
do
|
||||
{
|
||||
NEXTTERM(xx,MULNUM(n2) MULNUM(n2)
|
||||
NEXTTERM(xx,MULNUM(n2) MULNUM(n2)
|
||||
INC(n2) DIVNUM(n2) INC(n2) DIVNUM(n2), precision);
|
||||
}
|
||||
while ( !SMALL_ENOUGH_RAT( thisterm, precision) );
|
||||
@@ -99,7 +99,7 @@ void asinhrat( PRAT *px, uint32_t radix, int32_t precision)
|
||||
// hyperbolic cose of
|
||||
// RETURN: acosh of x in PRAT form.
|
||||
//
|
||||
// EXPLANATION: This uses
|
||||
// EXPLANATION: This uses
|
||||
//
|
||||
// acosh(x)=ln(x+sqrt(x^2-1))
|
||||
//
|
||||
@@ -117,7 +117,7 @@ void acoshrat( PRAT *px, uint32_t radix, int32_t precision)
|
||||
else
|
||||
{
|
||||
PRAT ptmp = nullptr;
|
||||
DUPRAT(ptmp,(*px));
|
||||
DUPRAT(ptmp,(*px));
|
||||
mulrat(&ptmp, *px, precision);
|
||||
subrat(&ptmp, rat_one, precision);
|
||||
rootrat(&ptmp,rat_two, radix, precision);
|
||||
@@ -148,7 +148,7 @@ void atanhrat( PRAT *px, int32_t precision)
|
||||
|
||||
{
|
||||
PRAT ptmp = nullptr;
|
||||
DUPRAT(ptmp,(*px));
|
||||
DUPRAT(ptmp,(*px));
|
||||
subrat(&ptmp, rat_one, precision);
|
||||
addrat(px, rat_one, precision);
|
||||
divrat(px, ptmp, precision);
|
||||
|
@@ -49,7 +49,7 @@ void rshrat( PRAT *pa, PRAT b, uint32_t radix, int32_t precision)
|
||||
|
||||
intrat(pa, radix, precision);
|
||||
if ( !zernum( (*pa)->pp ) )
|
||||
{
|
||||
{
|
||||
// If input is zero we're done.
|
||||
if ( rat_lt( b, rat_min_exp, precision) )
|
||||
{
|
||||
@@ -155,11 +155,11 @@ void boolnum( PNUMBER *pa, PNUMBER b, int func )
|
||||
pchc = c->mant;
|
||||
for ( ;cdigits > 0; cdigits--, mexp++ )
|
||||
{
|
||||
da = ( ( ( mexp >= a->exp ) && ( cdigits + a->exp - c->exp >
|
||||
(c->cdigit - a->cdigit) ) ) ?
|
||||
da = ( ( ( mexp >= a->exp ) && ( cdigits + a->exp - c->exp >
|
||||
(c->cdigit - a->cdigit) ) ) ?
|
||||
*pcha++ : 0 );
|
||||
db = ( ( ( mexp >= b->exp ) && ( cdigits + b->exp - c->exp >
|
||||
(c->cdigit - b->cdigit) ) ) ?
|
||||
db = ( ( ( mexp >= b->exp ) && ( cdigits + b->exp - c->exp >
|
||||
(c->cdigit - b->cdigit) ) ) ?
|
||||
*pchb++ : 0 );
|
||||
switch ( func )
|
||||
{
|
||||
@@ -205,15 +205,14 @@ void modrat( PRAT *pa, PRAT b )
|
||||
throw CALC_E_INDEFINITE;
|
||||
}
|
||||
DUPRAT(tmp,b);
|
||||
|
||||
|
||||
mulnumx( &((*pa)->pp), tmp->pq );
|
||||
mulnumx( &(tmp->pp), (*pa)->pq );
|
||||
remnum( &((*pa)->pp), tmp->pp, BASEX );
|
||||
mulnumx( &((*pa)->pq), tmp->pq );
|
||||
|
||||
//Get *pa back in the integer over integer form.
|
||||
|
||||
// Get *pa back in the integer over integer form.
|
||||
RENORMALIZE(*pa);
|
||||
|
||||
destroyrat( tmp );
|
||||
}
|
||||
|
||||
|
@@ -2,20 +2,20 @@
|
||||
// Licensed under the MIT License.
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Package Title ratpak
|
||||
// File num.c
|
||||
// Copyright (C) 1995-97 Microsoft
|
||||
// Date 01-16-95
|
||||
//
|
||||
//
|
||||
// Description
|
||||
//
|
||||
// Contains number routines for add, mul, div, rem and other support
|
||||
// and longs.
|
||||
//
|
||||
// Special Information
|
||||
//
|
||||
//
|
||||
// Package Title ratpak
|
||||
// File num.c
|
||||
// Copyright (C) 1995-97 Microsoft
|
||||
// Date 01-16-95
|
||||
//
|
||||
//
|
||||
// Description
|
||||
//
|
||||
// Contains number routines for add, mul, div, rem and other support
|
||||
// and longs.
|
||||
//
|
||||
// Special Information
|
||||
//
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "pch.h"
|
||||
#include "ratpak.h"
|
||||
@@ -76,8 +76,8 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
|
||||
long fcomplb = 0; // fcomplb is a flag to signal b is negative.
|
||||
|
||||
a=*pa;
|
||||
|
||||
|
||||
|
||||
|
||||
// Calculate the overlap of the numbers after alignment, this includes
|
||||
// necessary padding 0's
|
||||
cdigits = max( a->cdigit+a->exp, b->cdigit+b->exp ) -
|
||||
@@ -90,7 +90,7 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
|
||||
pcha = a->mant;
|
||||
pchb = b->mant;
|
||||
pchc = c->mant;
|
||||
|
||||
|
||||
// Figure out the sign of the numbers
|
||||
if ( a->sign != b->sign )
|
||||
{
|
||||
@@ -98,21 +98,21 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
|
||||
fcompla = ( a->sign == -1 );
|
||||
fcomplb = ( b->sign == -1 );
|
||||
}
|
||||
|
||||
|
||||
// Loop over all the digits, real and 0 padded. Here we know a and b are
|
||||
// aligned
|
||||
// aligned
|
||||
for ( ;cdigits > 0; cdigits--, mexp++ )
|
||||
{
|
||||
|
||||
|
||||
// Get digit from a, taking padding into account.
|
||||
da = ( ( ( mexp >= a->exp ) && ( cdigits + a->exp - c->exp >
|
||||
(c->cdigit - a->cdigit) ) ) ?
|
||||
da = ( ( ( mexp >= a->exp ) && ( cdigits + a->exp - c->exp >
|
||||
(c->cdigit - a->cdigit) ) ) ?
|
||||
*pcha++ : 0 );
|
||||
// Get digit from b, taking padding into account.
|
||||
db = ( ( ( mexp >= b->exp ) && ( cdigits + b->exp - c->exp >
|
||||
(c->cdigit - b->cdigit) ) ) ?
|
||||
db = ( ( ( mexp >= b->exp ) && ( cdigits + b->exp - c->exp >
|
||||
(c->cdigit - b->cdigit) ) ) ?
|
||||
*pchb++ : 0 );
|
||||
|
||||
|
||||
// Handle complementing for a and b digit. Might be a better way, but
|
||||
// haven't found it yet.
|
||||
if ( fcompla )
|
||||
@@ -123,20 +123,20 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
|
||||
{
|
||||
db = (MANTTYPE)(radix) - 1 - db;
|
||||
}
|
||||
|
||||
|
||||
// Update carry as necessary
|
||||
cy = da + db + cy;
|
||||
*pchc++ = (MANTTYPE)(cy % (MANTTYPE)radix);
|
||||
cy /= (MANTTYPE)radix;
|
||||
}
|
||||
|
||||
|
||||
// Handle carry from last sum as extra digit
|
||||
if ( cy && !(fcompla || fcomplb) )
|
||||
{
|
||||
*pchc++ = cy;
|
||||
c->cdigit++;
|
||||
}
|
||||
|
||||
|
||||
// Compute sign of result
|
||||
if ( !(fcompla || fcomplb) )
|
||||
{
|
||||
@@ -150,14 +150,14 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
|
||||
}
|
||||
else
|
||||
{
|
||||
// In this particular case an overflow or underflow has occurred
|
||||
// and all the digits need to be complemented, at one time an
|
||||
// attempt to handle this above was made, it turned out to be much
|
||||
// In this particular case an overflow or underflow has occurred
|
||||
// and all the digits need to be complemented, at one time an
|
||||
// attempt to handle this above was made, it turned out to be much
|
||||
// slower on average.
|
||||
c->sign = -1;
|
||||
cy = 1;
|
||||
for ( ( cdigits = c->cdigit ), (pchc = c->mant);
|
||||
cdigits > 0;
|
||||
cdigits > 0;
|
||||
cdigits-- )
|
||||
{
|
||||
cy = (MANTTYPE)radix - (MANTTYPE)1 - *pchc + cy;
|
||||
@@ -166,7 +166,7 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Remove leading zeros, remember digits are in order of
|
||||
// increasing significance. i.e. 100 would be 0,0,1
|
||||
while ( c->cdigit > 1 && *(--pchc) == 0 )
|
||||
@@ -231,7 +231,7 @@ void _mulnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
|
||||
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
|
||||
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.
|
||||
|
||||
@@ -249,8 +249,8 @@ void _mulnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
|
||||
{
|
||||
da = *pcha++;
|
||||
pchb = b->mant;
|
||||
|
||||
// Shift pchc, and pchcoffset, one for each digit
|
||||
|
||||
// Shift pchc, and pchcoffset, one for each digit
|
||||
pchc = pchcoffset++;
|
||||
|
||||
for ( ibdigit = b->cdigit; ibdigit > 0; ibdigit-- )
|
||||
@@ -268,23 +268,23 @@ void _mulnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
|
||||
// If result is nonzero, or while result of carry is nonzero...
|
||||
while ( mcy || cy )
|
||||
{
|
||||
|
||||
|
||||
// update carry from addition(s) and multiply.
|
||||
cy += (TWO_MANTTYPE)pchc[icdigit]+(mcy%(TWO_MANTTYPE)radix);
|
||||
|
||||
// update result digit from
|
||||
|
||||
// update result digit from
|
||||
pchc[icdigit++]=(MANTTYPE)(cy%(TWO_MANTTYPE)radix);
|
||||
|
||||
|
||||
// update carries from
|
||||
mcy /= (TWO_MANTTYPE)radix;
|
||||
cy /= (TWO_MANTTYPE)radix;
|
||||
}
|
||||
|
||||
|
||||
pchb++;
|
||||
pchc++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// prevent different kinds of zeros, by stripping leading duplicate zeros.
|
||||
// digits are in order of increasing significance.
|
||||
while ( c->cdigit > 1 && c->mant[c->cdigit-1] == 0 )
|
||||
@@ -317,7 +317,7 @@ void remnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
|
||||
{
|
||||
PNUMBER tmp = nullptr; // tmp is the working remainder.
|
||||
PNUMBER lasttmp = nullptr; // lasttmp is the last remainder which worked.
|
||||
|
||||
|
||||
// Once *pa is less than b, *pa is the remainder.
|
||||
while ( !lessnum( *pa, b ) )
|
||||
{
|
||||
@@ -336,20 +336,20 @@ void remnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
|
||||
destroynum( lasttmp );
|
||||
lasttmp=longtonum( 0, radix);
|
||||
|
||||
while ( lessnum( tmp, *pa ) )
|
||||
while ( lessnum( tmp, *pa ) )
|
||||
{
|
||||
DUPNUM( lasttmp, tmp );
|
||||
addnum( &tmp, tmp, radix);
|
||||
}
|
||||
|
||||
if ( lessnum( *pa, tmp ) )
|
||||
{
|
||||
{
|
||||
// too far, back up...
|
||||
destroynum( tmp );
|
||||
tmp=lasttmp;
|
||||
lasttmp= nullptr;
|
||||
}
|
||||
|
||||
|
||||
// Subtract the working remainder from the remainder holder.
|
||||
tmp->sign = -1*(*pa)->sign;
|
||||
addnum( pa, tmp, radix);
|
||||
@@ -357,7 +357,7 @@ void remnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
|
||||
destroynum( tmp );
|
||||
destroynum( lasttmp );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -381,7 +381,7 @@ void __inline divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision)
|
||||
|
||||
{
|
||||
if ( b->cdigit > 1 || b->mant[0] != 1 || b->exp != 0 )
|
||||
{
|
||||
{
|
||||
// b is not one
|
||||
_divnum( pa, b, radix, precision);
|
||||
}
|
||||
@@ -418,7 +418,7 @@ void _divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision)
|
||||
tmp->sign = a->sign;
|
||||
rem->exp = b->cdigit + b->exp - rem->cdigit;
|
||||
|
||||
// Build a table of multiplications of the divisor, this is quicker for
|
||||
// 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++)
|
||||
@@ -535,21 +535,21 @@ bool equnum( PNUMBER a, PNUMBER b )
|
||||
pb += b->cdigit - 1;
|
||||
cdigits = max( a->cdigit, b->cdigit );
|
||||
ccdigits = cdigits;
|
||||
|
||||
|
||||
// Loop over all digits until we run out of digits or there is a
|
||||
// difference in the digits.
|
||||
for ( ;cdigits > 0; cdigits-- )
|
||||
{
|
||||
da = ( (cdigits > (ccdigits - a->cdigit) ) ?
|
||||
da = ( (cdigits > (ccdigits - a->cdigit) ) ?
|
||||
*pa-- : 0 );
|
||||
db = ( (cdigits > (ccdigits - b->cdigit) ) ?
|
||||
db = ( (cdigits > (ccdigits - b->cdigit) ) ?
|
||||
*pb-- : 0 );
|
||||
if ( da != db )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// In this case, they are equal.
|
||||
return true;
|
||||
}
|
||||
@@ -604,9 +604,9 @@ bool lessnum( PNUMBER a, PNUMBER b )
|
||||
ccdigits = cdigits;
|
||||
for ( ;cdigits > 0; cdigits-- )
|
||||
{
|
||||
da = ( (cdigits > (ccdigits - a->cdigit) ) ?
|
||||
da = ( (cdigits > (ccdigits - a->cdigit) ) ?
|
||||
*pa-- : 0 );
|
||||
db = ( (cdigits > (ccdigits - b->cdigit) ) ?
|
||||
db = ( (cdigits > (ccdigits - b->cdigit) ) ?
|
||||
*pb-- : 0 );
|
||||
diff = da-db;
|
||||
if ( diff )
|
||||
@@ -639,8 +639,8 @@ bool zernum( PNUMBER a )
|
||||
MANTTYPE *pcha;
|
||||
length = a->cdigit;
|
||||
pcha = a->mant;
|
||||
|
||||
// loop over all the digits until you find a nonzero or until you run
|
||||
|
||||
// loop over all the digits until you find a nonzero or until you run
|
||||
// out of digits
|
||||
while ( length-- > 0 )
|
||||
{
|
||||
|
@@ -56,7 +56,7 @@ void gcdrat( PRAT *pa, int32_t precision)
|
||||
destroynum( pgcd );
|
||||
*pa=a;
|
||||
|
||||
RENORMALIZE(*pa);
|
||||
RENORMALIZE(*pa);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -82,7 +82,7 @@ void fracrat( PRAT *pa , uint32_t radix, int32_t precision)
|
||||
|
||||
remnum( &((*pa)->pp), (*pa)->pq, BASEX );
|
||||
|
||||
//Get *pa back in the integer over integer form.
|
||||
// Get *pa back in the integer over integer form.
|
||||
RENORMALIZE(*pa);
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ void fracrat( PRAT *pa , uint32_t radix, int32_t precision)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void mulrat( PRAT *pa, PRAT b, int32_t precision)
|
||||
|
||||
|
||||
{
|
||||
// Only do the multiply if it isn't zero.
|
||||
if ( !zernum( (*pa)->pp ) )
|
||||
@@ -170,7 +170,7 @@ void divrat( PRAT *pa, PRAT b, int32_t precision)
|
||||
|
||||
#ifdef DIVGCD
|
||||
gcdrat( pa );
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -215,13 +215,13 @@ void addrat( PRAT *pa, PRAT b, int32_t precision)
|
||||
|
||||
if ( equnum( (*pa)->pq, b->pq ) )
|
||||
{
|
||||
// Very special case, q's match.,
|
||||
// Very special case, q's match.,
|
||||
// make sure signs are involved in the calculation
|
||||
// we have to do this since the optimization here is only
|
||||
// we have to do this since the optimization here is only
|
||||
// working with the top half of the rationals.
|
||||
(*pa)->pp->sign *= (*pa)->pq->sign;
|
||||
(*pa)->pp->sign *= (*pa)->pq->sign;
|
||||
(*pa)->pq->sign = 1;
|
||||
b->pp->sign *= b->pq->sign;
|
||||
b->pp->sign *= b->pq->sign;
|
||||
b->pq->sign = 1;
|
||||
addnum( &((*pa)->pp), b->pp, BASEX );
|
||||
}
|
||||
@@ -236,15 +236,15 @@ void addrat( PRAT *pa, PRAT b, int32_t precision)
|
||||
destroynum( (*pa)->pq );
|
||||
(*pa)->pq = bot;
|
||||
trimit(pa, precision);
|
||||
|
||||
|
||||
// Get rid of negative zeros here.
|
||||
(*pa)->pp->sign *= (*pa)->pq->sign;
|
||||
(*pa)->pp->sign *= (*pa)->pq->sign;
|
||||
(*pa)->pq->sign = 1;
|
||||
}
|
||||
|
||||
#ifdef ADDGCD
|
||||
gcdrat( pa );
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ void addrat( PRAT *pa, PRAT b, int32_t precision)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void rootrat( PRAT *py, PRAT n, uint32_t radix, int32_t precision)
|
||||
{
|
||||
{
|
||||
// Initialize 1/n
|
||||
PRAT oneovern= nullptr;
|
||||
DUPRAT(oneovern,rat_one);
|
||||
|
@@ -58,7 +58,7 @@ static int cbitsofprecision = RATIO_FOR_DECIMAL * DECIMAL * CALC_DECIMAL_DIGITS_
|
||||
|
||||
#endif
|
||||
|
||||
bool g_ftrueinfinite = false; // Set to true if you don't want
|
||||
bool g_ftrueinfinite = false; // Set to true if you don't want
|
||||
// chopping internally
|
||||
// precision used internally
|
||||
|
||||
@@ -119,8 +119,8 @@ PRAT rat_max_long= nullptr; // max signed long
|
||||
|
||||
void ChangeConstants(uint32_t radix, int32_t precision)
|
||||
{
|
||||
// ratio is set to the number of digits in the current radix, you can get
|
||||
// in the internal BASEX radix, this is important for length calculations
|
||||
// ratio is set to the number of digits in the current radix, you can get
|
||||
// in the internal BASEX radix, this is important for length calculations
|
||||
// in translating from radix to BASEX and back.
|
||||
|
||||
uint64_t limit = static_cast<uint64_t>(BASEX) / static_cast<uint64_t>(radix);
|
||||
@@ -213,7 +213,7 @@ void ChangeConstants(uint32_t radix, int32_t precision)
|
||||
|
||||
cbitsofprecision = g_ratio * radix * precision;
|
||||
|
||||
// Apparently when dividing 180 by pi, another (internal) digit of
|
||||
// Apparently when dividing 180 by pi, another (internal) digit of
|
||||
// precision is needed.
|
||||
long extraPrecision = precision + g_ratio;
|
||||
DUPRAT(pi, rat_half);
|
||||
@@ -348,7 +348,7 @@ bool rat_ge( PRAT a, PRAT b, int32_t precision)
|
||||
b->pp->sign *= -1;
|
||||
addrat( &rattmp, b, precision);
|
||||
b->pp->sign *= -1;
|
||||
bool bret = ( zernum( rattmp->pp ) ||
|
||||
bool bret = ( zernum( rattmp->pp ) ||
|
||||
rattmp->pp->sign * rattmp->pq->sign == 1 );
|
||||
destroyrat( rattmp );
|
||||
return( bret );
|
||||
@@ -472,10 +472,10 @@ void scale( PRAT *px, PRAT scalefact, uint32_t radix, int32_t precision )
|
||||
{
|
||||
PRAT pret = nullptr;
|
||||
DUPRAT(pret,*px);
|
||||
|
||||
// Logscale is a quick way to tell how much extra precision is needed for
|
||||
|
||||
// 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) -
|
||||
long logscale = g_ratio * ( (pret->pp->cdigit+pret->pp->exp) -
|
||||
(pret->pq->cdigit+pret->pq->exp) );
|
||||
if ( logscale > 0 )
|
||||
{
|
||||
@@ -508,9 +508,9 @@ void scale2pi( PRAT *px, uint32_t radix, int32_t precision )
|
||||
PRAT my_two_pi = nullptr;
|
||||
DUPRAT(pret,*px);
|
||||
|
||||
// Logscale is a quick way to tell how much extra precision is needed for
|
||||
// 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) -
|
||||
long logscale = g_ratio * ( (pret->pp->cdigit+pret->pp->exp) -
|
||||
(pret->pq->cdigit+pret->pq->exp) );
|
||||
if ( logscale > 0 )
|
||||
{
|
||||
@@ -663,16 +663,16 @@ void _readconstants( void )
|
||||
// ARGUMENTS: PRAT *px, long precision
|
||||
//
|
||||
//
|
||||
// DESCRIPTION: Chops off digits from rational numbers to avoid time
|
||||
// explosions in calculations of functions using series.
|
||||
// It can be shown that it is enough to only keep the first n digits
|
||||
// of the largest of p or q in the rational p over q form, and of course
|
||||
// scale the smaller by the same number of digits. This will give you
|
||||
// n-1 digits of accuracy. This dramatically speeds up calculations
|
||||
// DESCRIPTION: Chops off digits from rational numbers to avoid time
|
||||
// explosions in calculations of functions using series.
|
||||
// It can be shown that it is enough to only keep the first n digits
|
||||
// of the largest of p or q in the rational p over q form, and of course
|
||||
// scale the smaller by the same number of digits. This will give you
|
||||
// n-1 digits of accuracy. This dramatically speeds up calculations
|
||||
// involving hundreds of digits or more.
|
||||
// The last part of this trim dealing with exponents never affects accuracy
|
||||
//
|
||||
// RETURN: none, modifies the pointed to PRAT
|
||||
// RETURN: none, modifies the pointed to PRAT
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -680,7 +680,7 @@ void trimit( PRAT *px, int32_t precision)
|
||||
|
||||
{
|
||||
if ( !g_ftrueinfinite )
|
||||
{
|
||||
{
|
||||
long trim;
|
||||
PNUMBER pp=(*px)->pp;
|
||||
PNUMBER pq=(*px)->pq;
|
||||
|
@@ -47,8 +47,8 @@ void scalerat( _Inout_ PRAT *pa, ANGLE_TYPE angletype, uint32_t radix, int32_t p
|
||||
// EXPLANATION: This uses Taylor series
|
||||
//
|
||||
// n
|
||||
// ___ 2j+1
|
||||
// \ ] j X
|
||||
// ___ 2j+1
|
||||
// \ ] j X
|
||||
// \ -1 * ---------
|
||||
// / (2j+1)!
|
||||
// /__]
|
||||
@@ -73,7 +73,7 @@ void _sinrat( PRAT *px, int32_t precision)
|
||||
{
|
||||
CREATETAYLOR();
|
||||
|
||||
DUPRAT(pret,*px);
|
||||
DUPRAT(pret,*px);
|
||||
DUPRAT(thisterm,*px);
|
||||
|
||||
DUPNUM(n2,num_one);
|
||||
@@ -84,11 +84,11 @@ void _sinrat( PRAT *px, int32_t precision)
|
||||
} while ( !SMALL_ENOUGH_RAT( thisterm, precision) );
|
||||
|
||||
DESTROYTAYLOR();
|
||||
|
||||
// Since *px might be epsilon above 1 or below -1, due to TRIMIT we need
|
||||
|
||||
// Since *px might be epsilon above 1 or below -1, due to TRIMIT we need
|
||||
// this trick here.
|
||||
inbetween(px, rat_one, precision);
|
||||
|
||||
|
||||
// Since *px might be epsilon near zero we must set it to zero.
|
||||
if ( rat_le(*px, rat_smallest, precision) && rat_ge(*px, rat_negsmallest, precision) )
|
||||
{
|
||||
@@ -166,13 +166,13 @@ void _cosrat( PRAT *px, uint32_t radix, int32_t precision)
|
||||
CREATETAYLOR();
|
||||
|
||||
destroynum(pret->pp);
|
||||
destroynum(pret->pq);
|
||||
destroynum(pret->pq);
|
||||
|
||||
pret->pp=longtonum( 1L, radix);
|
||||
pret->pq=longtonum( 1L, radix);
|
||||
|
||||
DUPRAT(thisterm,pret)
|
||||
|
||||
|
||||
n2=longtonum(0L, radix);
|
||||
xx->pp->sign *= -1;
|
||||
|
||||
@@ -181,7 +181,7 @@ void _cosrat( PRAT *px, uint32_t radix, int32_t precision)
|
||||
} while ( !SMALL_ENOUGH_RAT( thisterm, precision) );
|
||||
|
||||
DESTROYTAYLOR();
|
||||
// Since *px might be epsilon above 1 or below -1, due to TRIMIT we need
|
||||
// Since *px might be epsilon above 1 or below -1, due to TRIMIT we need
|
||||
// this trick here.
|
||||
inbetween(px, rat_one, precision);
|
||||
// Since *px might be epsilon near zero we must set it to zero.
|
||||
|
@@ -80,7 +80,7 @@ void _sinhrat( PRAT *px, int32_t precision)
|
||||
|
||||
CREATETAYLOR();
|
||||
|
||||
DUPRAT(pret,*px);
|
||||
DUPRAT(pret,*px);
|
||||
DUPRAT(thisterm,pret);
|
||||
|
||||
DUPNUM(n2,num_one);
|
||||
@@ -194,7 +194,7 @@ void coshrat( PRAT *px, uint32_t radix, int32_t precision)
|
||||
{
|
||||
_coshrat( px, radix, precision);
|
||||
}
|
||||
// Since *px might be epsilon below 1 due to TRIMIT
|
||||
// Since *px might be epsilon below 1 due to TRIMIT
|
||||
// we need this trick here.
|
||||
if ( rat_lt(*px, rat_one, precision) )
|
||||
{
|
||||
|
@@ -46,7 +46,7 @@ UnitConverter::UnitConverter(_In_ const shared_ptr<IConverterDataLoader>& dataLo
|
||||
{
|
||||
m_dataLoader = dataLoader;
|
||||
m_currencyDataLoader = currencyDataLoader;
|
||||
//declaring the delimiter character conversion map
|
||||
// declaring the delimiter character conversion map
|
||||
quoteConversions[L'|'] = L"{p}";
|
||||
quoteConversions[L'['] = L"{lc}";
|
||||
quoteConversions[L']'] = L"{rc}";
|
||||
@@ -90,7 +90,7 @@ vector<Category> UnitConverter::GetCategories()
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current category in use by this converter,
|
||||
/// Sets the current category in use by this converter,
|
||||
/// and returns a list of unit types that exist under the given category.
|
||||
/// </summary>
|
||||
/// <param name="input">Category struct which we are setting</param>
|
||||
@@ -170,7 +170,7 @@ void UnitConverter::SetCurrentUnitTypes(const Unit& fromType, const Unit& toType
|
||||
/// <summary>
|
||||
/// Switches the active field, indicating that we are now entering data into
|
||||
/// what was originally the return field, and storing results into what was
|
||||
/// originally the current field. We swap appropriate values,
|
||||
/// originally the current field. We swap appropriate values,
|
||||
/// but do not callback, as values have not changed.
|
||||
/// </summary>
|
||||
/// <param name="newValue">
|
||||
@@ -420,7 +420,7 @@ void UnitConverter::RestoreUserPreferences(const wstring& userPreferences)
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the Category and Associated Units in the converter and returns it as a string
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
wstring UnitConverter::SaveUserPreferences()
|
||||
{
|
||||
wstringstream out(wstringstream::out);
|
||||
@@ -441,7 +441,7 @@ wstring UnitConverter::Quote(const wstring& s)
|
||||
{
|
||||
wstringstream quotedString(wstringstream::out);
|
||||
|
||||
//Iterate over the delimiter characters we need to quote
|
||||
// Iterate over the delimiter characters we need to quote
|
||||
wstring::const_iterator cursor = s.begin();
|
||||
while(cursor != s.end())
|
||||
{
|
||||
@@ -479,7 +479,7 @@ wstring UnitConverter::Unquote(const wstring& s)
|
||||
}
|
||||
if (cursor == s.end())
|
||||
{
|
||||
//badly formatted
|
||||
// Badly formatted
|
||||
break;
|
||||
}
|
||||
else
|
||||
@@ -505,7 +505,7 @@ void UnitConverter::SendCommand(Command command)
|
||||
{
|
||||
if (CheckLoad())
|
||||
{
|
||||
//TODO: Localization of characters
|
||||
// TODO: Localization of characters
|
||||
bool clearFront = false;
|
||||
if (m_currentDisplay == L"0")
|
||||
{
|
||||
@@ -625,7 +625,7 @@ void UnitConverter::SendCommand(Command command)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (clearFront)
|
||||
{
|
||||
@@ -728,7 +728,7 @@ vector<tuple<wstring, Unit>> UnitConverter::CalculateSuggested()
|
||||
vector<SuggestedValueIntermediate> intermediateVector;
|
||||
vector<SuggestedValueIntermediate> intermediateWhimsicalVector;
|
||||
unordered_map<Unit, ConversionData, UnitHash> ratios = m_ratioMap[m_fromType];
|
||||
//Calculate converted values for every other unit type in this category, along with their magnitude
|
||||
// Calculate converted values for every other unit type in this category, along with their magnitude
|
||||
for (const auto& cur : ratios)
|
||||
{
|
||||
if (cur.first != m_fromType && cur.first != m_toType)
|
||||
@@ -745,21 +745,21 @@ vector<tuple<wstring, Unit>> UnitConverter::CalculateSuggested()
|
||||
}
|
||||
}
|
||||
|
||||
//Sort the resulting list by absolute magnitude, breaking ties by choosing the positive value
|
||||
// Sort the resulting list by absolute magnitude, breaking ties by choosing the positive value
|
||||
sort(intermediateVector.begin(), intermediateVector.end(), []
|
||||
(SuggestedValueIntermediate first, SuggestedValueIntermediate second)
|
||||
{
|
||||
if (abs(first.magnitude) == abs(second.magnitude))
|
||||
{
|
||||
return first.magnitude > second.magnitude;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
if (abs(first.magnitude) == abs(second.magnitude))
|
||||
{
|
||||
return first.magnitude > second.magnitude;
|
||||
}
|
||||
else
|
||||
{
|
||||
return abs(first.magnitude) < abs(second.magnitude);
|
||||
}
|
||||
});
|
||||
|
||||
//Now that the list is sorted, iterate over it and populate the return vector with properly rounded and formatted return strings
|
||||
// Now that the list is sorted, iterate over it and populate the return vector with properly rounded and formatted return strings
|
||||
for (const auto& entry : intermediateVector)
|
||||
{
|
||||
wstring roundedString;
|
||||
@@ -783,7 +783,7 @@ vector<tuple<wstring, Unit>> UnitConverter::CalculateSuggested()
|
||||
}
|
||||
|
||||
// The Whimsicals are determined differently
|
||||
//Sort the resulting list by absolute magnitude, breaking ties by choosing the positive value
|
||||
// Sort the resulting list by absolute magnitude, breaking ties by choosing the positive value
|
||||
sort(intermediateWhimsicalVector.begin(), intermediateWhimsicalVector.end(), []
|
||||
(SuggestedValueIntermediate first, SuggestedValueIntermediate second)
|
||||
{
|
||||
@@ -797,7 +797,7 @@ vector<tuple<wstring, Unit>> UnitConverter::CalculateSuggested()
|
||||
}
|
||||
});
|
||||
|
||||
//Now that the list is sorted, iterate over it and populate the return vector with properly rounded and formatted return strings
|
||||
// Now that the list is sorted, iterate over it and populate the return vector with properly rounded and formatted return strings
|
||||
vector<tuple<wstring, Unit>> whimsicalReturnVector;
|
||||
|
||||
for (const auto& entry : intermediateWhimsicalVector)
|
||||
|
Reference in New Issue
Block a user