mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 06:13:14 -07:00
Replace (unsigned) long -> (u)int32_t
This commit is contained in:
parent
15e7e8d0aa
commit
17c74b9527
15 changed files with 136 additions and 134 deletions
|
@ -56,7 +56,7 @@ bool CalcInput::TryToggleSign(bool isIntegerMode, wstring_view maxNumStr)
|
||||||
return true;
|
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
|
// Convert from an integer into a character
|
||||||
// This includes both normal digits and alpha 'digits' for radixes > 10
|
// This includes both normal digits and alpha 'digits' for radixes > 10
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace CalcEngine
|
||||||
PNUMBER ret = _createnum(static_cast<uint32_t>(this->Mantissa().size()) + 1);
|
PNUMBER ret = _createnum(static_cast<uint32_t>(this->Mantissa().size()) + 1);
|
||||||
ret->sign = this->Sign();
|
ret->sign = this->Sign();
|
||||||
ret->exp = this->Exp();
|
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;
|
MANTTYPE *ptrRet = ret->mant;
|
||||||
for (auto const& digit : this->Mantissa())
|
for (auto const& digit : this->Mantissa())
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace CalcEngine
|
||||||
|
|
||||||
Rational::Rational(int32_t i)
|
Rational::Rational(int32_t i)
|
||||||
{
|
{
|
||||||
PRAT pr = longtorat(static_cast<long>(i));
|
PRAT pr = longtorat(static_cast<int32_t>(i));
|
||||||
|
|
||||||
m_p = Number{ pr->pp };
|
m_p = Number{ pr->pp };
|
||||||
m_q = Number{ pr->pq };
|
m_q = Number{ pr->pq };
|
||||||
|
@ -41,7 +41,7 @@ namespace CalcEngine
|
||||||
|
|
||||||
Rational::Rational(uint32_t ui)
|
Rational::Rational(uint32_t ui)
|
||||||
{
|
{
|
||||||
PRAT pr = Ulongtorat(static_cast<unsigned long>(ui));
|
PRAT pr = Ulongtorat(static_cast<uint32_t>(ui));
|
||||||
|
|
||||||
m_p = Number{ pr->pp };
|
m_p = Number{ pr->pp };
|
||||||
m_q = Number{ pr->pq };
|
m_q = Number{ pr->pq };
|
||||||
|
|
|
@ -15,7 +15,7 @@ using namespace CalcEngine;
|
||||||
|
|
||||||
static constexpr int DEFAULT_MAX_DIGITS = 32;
|
static constexpr int DEFAULT_MAX_DIGITS = 32;
|
||||||
static constexpr int DEFAULT_PRECISION = 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_DEC_SEPARATOR = L'.';
|
||||||
static constexpr wchar_t DEFAULT_GRP_SEPARATOR = L',';
|
static constexpr wchar_t DEFAULT_GRP_SEPARATOR = L',';
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Ratpack/CalcErr.h"
|
||||||
|
|
||||||
template <typename TType>
|
template <typename TType>
|
||||||
class CalculatorVector
|
class CalculatorVector
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace CalcEngine
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
bool TryToggleSign(bool isIntegerMode, std::wstring_view maxNumStr);
|
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 TryAddDecimalPt();
|
||||||
bool HasDecimalPt();
|
bool HasDecimalPt();
|
||||||
bool TryBeginExponent();
|
bool TryBeginExponent();
|
||||||
|
|
|
@ -48,7 +48,7 @@ void __inline mulnumx( PNUMBER *pa, PNUMBER b )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// if pa is one and b isn't just copy b. and adjust the sign.
|
// 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);
|
DUPNUM(*pa,b);
|
||||||
(*pa)->sign *= sign;
|
(*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 *ptrc; // ptrc is a pointer to the mantissa of c.
|
||||||
MANTTYPE *ptrcoffset; // ptrcoffset, is the anchor location of the next
|
MANTTYPE *ptrcoffset; // ptrcoffset, is the anchor location of the next
|
||||||
// single digit multiply partial result.
|
// single digit multiply partial result.
|
||||||
long iadigit=0; // Index of digit being used in the first number.
|
int32_t 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 ibdigit=0; // Index of digit being used in the second number.
|
||||||
MANTTYPE da=0; // da is the digit from the fist 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
|
TWO_MANTTYPE cy=0; // cy is the carry resulting from the addition of
|
||||||
// a multiplied row into the result.
|
// 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.
|
// 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;
|
a=*pa;
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ void _mulnumx( PNUMBER *pa, PNUMBER b )
|
||||||
//
|
//
|
||||||
// FUNCTION: numpowlongx
|
// FUNCTION: numpowlongx
|
||||||
//
|
//
|
||||||
// ARGUMENTS: root as number power as long
|
// ARGUMENTS: root as number power as int32_t
|
||||||
// number.
|
// number.
|
||||||
//
|
//
|
||||||
// RETURN: None root is changed.
|
// RETURN: None root is changed.
|
||||||
|
@ -174,7 +174,7 @@ void _mulnumx( PNUMBER *pa, PNUMBER b )
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void numpowlongx( _Inout_ PNUMBER *proot, _In_ long power )
|
void numpowlongx( _Inout_ PNUMBER *proot, _In_ int32_t power )
|
||||||
|
|
||||||
{
|
{
|
||||||
PNUMBER lret = longtonum( 1, BASEX );
|
PNUMBER lret = longtonum( 1, BASEX );
|
||||||
|
@ -232,7 +232,7 @@ void __inline divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// if pa is one and b is not one, just copy b, and adjust the sign.
|
// 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);
|
DUPNUM(*pa,b);
|
||||||
(*pa)->sign *= sign;
|
(*pa)->sign *= sign;
|
||||||
}
|
}
|
||||||
|
@ -266,10 +266,10 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
|
||||||
// guesses one bit too far.
|
// guesses one bit too far.
|
||||||
PNUMBER tmp = nullptr; // current guess being worked on for divide.
|
PNUMBER tmp = nullptr; // current guess being worked on for divide.
|
||||||
PNUMBER rem = nullptr; // remainder after applying guess.
|
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.
|
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.
|
// to shoot for in the divide.
|
||||||
|
|
||||||
a=*pa;
|
a=*pa;
|
||||||
|
@ -301,7 +301,7 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
|
||||||
|
|
||||||
while ( cdigits++ < thismax && !zernum(rem) )
|
while ( cdigits++ < thismax && !zernum(rem) )
|
||||||
{
|
{
|
||||||
long digit = 0;
|
int32_t digit = 0;
|
||||||
*ptrc = 0;
|
*ptrc = 0;
|
||||||
while ( !lessnum( rem, b ) )
|
while ( !lessnum( rem, b ) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,12 +29,12 @@ static constexpr wstring_view DIGITS = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabc
|
||||||
|
|
||||||
// ratio of internal 'digits' to output 'digits'
|
// ratio of internal 'digits' to output 'digits'
|
||||||
// Calculated elsewhere as part of initialization and when base is changed
|
// 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
|
// Default decimal separator
|
||||||
wchar_t g_decimalSeparator = L'.';
|
wchar_t g_decimalSeparator = L'.';
|
||||||
|
|
||||||
// Used to strip trailing zeros, and prevent combinatorial explosions
|
// 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)
|
void SetDecimalSeparator(wchar_t decimalSeparator)
|
||||||
{
|
{
|
||||||
|
@ -245,8 +245,8 @@ PRAT numtorat( _In_ PNUMBER pin, uint32_t radix)
|
||||||
PNUMBER nRadixxtonum( _In_ PNUMBER a, uint32_t radix, int32_t precision)
|
PNUMBER nRadixxtonum( _In_ PNUMBER a, uint32_t radix, int32_t precision)
|
||||||
|
|
||||||
{
|
{
|
||||||
unsigned long bitmask;
|
uint32_t bitmask;
|
||||||
unsigned long cdigits;
|
uint32_t cdigits;
|
||||||
MANTTYPE *ptr;
|
MANTTYPE *ptr;
|
||||||
|
|
||||||
PNUMBER sum = longtonum( 0, radix );
|
PNUMBER sum = longtonum( 0, radix );
|
||||||
|
@ -256,9 +256,9 @@ PNUMBER nRadixxtonum( _In_ PNUMBER a, uint32_t radix, int32_t precision)
|
||||||
// limit the digits to the minimum of the existing precision or the
|
// limit the digits to the minimum of the existing precision or the
|
||||||
// requested precision.
|
// requested precision.
|
||||||
cdigits = precision + 1;
|
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
|
// scale by the internal base to the internal exponent offset of the LSD
|
||||||
|
@ -312,7 +312,7 @@ PNUMBER numtonRadixx(_In_ PNUMBER a, uint32_t radix)
|
||||||
|
|
||||||
PNUMBER thisdigit = nullptr; // thisdigit holds the current digit of a
|
PNUMBER thisdigit = nullptr; // thisdigit holds the current digit of a
|
||||||
// being summed into result.
|
// 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++ )
|
for ( idigit = 0; idigit < a->cdigit; idigit++ )
|
||||||
{
|
{
|
||||||
mulnumx( &pnumret, num_radix);
|
mulnumx( &pnumret, num_radix);
|
||||||
|
@ -391,7 +391,7 @@ PRAT StringToRat(bool mantissaIsNegative, wstring_view mantissa, bool exponentIs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deal with exponent
|
// Deal with exponent
|
||||||
long expt = 0;
|
int32_t expt = 0;
|
||||||
if (!exponent.empty())
|
if (!exponent.empty())
|
||||||
{
|
{
|
||||||
// Exponent specified, convert to number form.
|
// Exponent specified, convert to number form.
|
||||||
|
@ -574,8 +574,8 @@ wchar_t NormalizeCharDigit(wchar_t c, uint32_t radix)
|
||||||
|
|
||||||
PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precision)
|
PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precision)
|
||||||
{
|
{
|
||||||
long expSign = 1L; // expSign is exponent sign ( +/- 1 )
|
int32_t expSign = 1L; // expSign is exponent sign ( +/- 1 )
|
||||||
long expValue = 0L; // expValue is exponent mantissa, should be unsigned
|
int32_t expValue = 0L; // expValue is exponent mantissa, should be unsigned
|
||||||
|
|
||||||
PNUMBER pnumret = nullptr;
|
PNUMBER pnumret = nullptr;
|
||||||
createnum(pnumret, static_cast<uint32_t>(numberString.length()));
|
createnum(pnumret, static_cast<uint32_t>(numberString.length()));
|
||||||
|
@ -637,7 +637,7 @@ PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precis
|
||||||
if (pos != wstring_view::npos)
|
if (pos != wstring_view::npos)
|
||||||
{
|
{
|
||||||
expValue *= radix;
|
expValue *= radix;
|
||||||
expValue += static_cast<long>(pos);
|
expValue += static_cast<int32_t>(pos);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -683,7 +683,7 @@ PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precis
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while (pnumret->cdigit < static_cast<long>(numberString.length()))
|
while (pnumret->cdigit < static_cast<int32_t>(numberString.length()))
|
||||||
{
|
{
|
||||||
pnumret->cdigit++;
|
pnumret->cdigit++;
|
||||||
pnumret->exp--;
|
pnumret->exp--;
|
||||||
|
@ -708,16 +708,16 @@ PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precis
|
||||||
//
|
//
|
||||||
// FUNCTION: longtorat
|
// FUNCTION: longtorat
|
||||||
//
|
//
|
||||||
// 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)
|
// DESCRIPTION: Converts int32_t input to rational (p over q)
|
||||||
// form, where q is 1 and p is the long.
|
// form, where q is 1 and p is the int32_t.
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
PRAT longtorat( _In_ long inlong )
|
PRAT longtorat( _In_ int32_t inlong )
|
||||||
|
|
||||||
{
|
{
|
||||||
PRAT pratret= nullptr;
|
PRAT pratret= nullptr;
|
||||||
|
@ -733,15 +733,15 @@ PRAT longtorat( _In_ long inlong )
|
||||||
//
|
//
|
||||||
// ARGUMENTS: ulong
|
// ARGUMENTS: ulong
|
||||||
//
|
//
|
||||||
// RETURN: Rational representation of unsigned long input.
|
// RETURN: Rational representation of uint32_t input.
|
||||||
//
|
//
|
||||||
// DESCRIPTION: Converts unsigned long input to rational (p over q)
|
// DESCRIPTION: Converts uint32_t input to rational (p over q)
|
||||||
// form, where q is 1 and p is the unsigned long. Being unsigned cant take negative
|
// form, where q is 1 and p is the uint32_t. Being unsigned cant take negative
|
||||||
// numbers, but the full range of unsigned numbers
|
// numbers, but the full range of unsigned numbers
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
PRAT Ulongtorat( _In_ unsigned long inulong )
|
PRAT Ulongtorat( _In_ uint32_t inulong )
|
||||||
|
|
||||||
{
|
{
|
||||||
PRAT pratret= nullptr;
|
PRAT pratret= nullptr;
|
||||||
|
@ -755,16 +755,16 @@ PRAT Ulongtorat( _In_ unsigned long inulong )
|
||||||
//
|
//
|
||||||
// FUNCTION: longtonum
|
// FUNCTION: longtonum
|
||||||
//
|
//
|
||||||
// ARGUMENTS: long input and radix requested.
|
// ARGUMENTS: int32_t input and radix requested.
|
||||||
//
|
//
|
||||||
// RETURN: number
|
// RETURN: number
|
||||||
//
|
//
|
||||||
// DESCRIPTION: Returns a number representation in the
|
// 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 longtonum( int32_t inlong, uint32_t radix)
|
||||||
|
|
||||||
{
|
{
|
||||||
MANTTYPE *pmant;
|
MANTTYPE *pmant;
|
||||||
|
@ -802,13 +802,13 @@ PNUMBER longtonum( long inlong, uint32_t radix)
|
||||||
// RETURN: number
|
// RETURN: number
|
||||||
//
|
//
|
||||||
// DESCRIPTION: Returns a number representation in the
|
// 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
|
// negative number and takes the full range of unsigned number
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
PNUMBER Ulongtonum(unsigned long inlong, uint32_t radix)
|
PNUMBER Ulongtonum(uint32_t inlong, uint32_t radix)
|
||||||
{
|
{
|
||||||
MANTTYPE *pmant;
|
MANTTYPE *pmant;
|
||||||
PNUMBER pnumret= nullptr;
|
PNUMBER pnumret= nullptr;
|
||||||
|
@ -835,15 +835,15 @@ PNUMBER Ulongtonum(unsigned long inlong, uint32_t radix)
|
||||||
//
|
//
|
||||||
// ARGUMENTS: rational number in internal base, integer radix and int32_t precision.
|
// 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
|
// number input. Assumes that the number is in the internal
|
||||||
// base.
|
// base.
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
long rattolong( _In_ PRAT prat , uint32_t radix, int32_t precision)
|
int32_t rattolong( _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_long, precision) || rat_lt( prat, rat_min_long, precision) )
|
||||||
{
|
{
|
||||||
|
@ -858,7 +858,7 @@ long rattolong( _In_ PRAT prat , uint32_t radix, int32_t precision)
|
||||||
divnumx( &(pint->pp), pint->pq, precision);
|
divnumx( &(pint->pp), pint->pq, precision);
|
||||||
DUPNUM( pint->pq, num_one );
|
DUPNUM( pint->pq, num_one );
|
||||||
|
|
||||||
long lret = numtolong( pint->pp, BASEX );
|
int32_t lret = numtolong( pint->pp, BASEX );
|
||||||
|
|
||||||
destroyrat(pint);
|
destroyrat(pint);
|
||||||
|
|
||||||
|
@ -878,7 +878,7 @@ long rattolong( _In_ PRAT prat , uint32_t radix, int32_t precision)
|
||||||
// base.
|
// base.
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
unsigned long rattoUlong( _In_ PRAT prat, uint32_t radix, int32_t precision)
|
uint32_t rattoUlong( _In_ PRAT prat, uint32_t radix, int32_t precision)
|
||||||
{
|
{
|
||||||
if ( rat_gt( prat, rat_dword, precision) || rat_lt( prat, rat_zero, precision) )
|
if ( rat_gt( prat, rat_dword, precision) || rat_lt( prat, rat_zero, precision) )
|
||||||
{
|
{
|
||||||
|
@ -893,7 +893,7 @@ unsigned long rattoUlong( _In_ PRAT prat, uint32_t radix, int32_t precision)
|
||||||
divnumx( &(pint->pp), pint->pq, precision);
|
divnumx( &(pint->pp), pint->pq, precision);
|
||||||
DUPNUM( pint->pq, num_one );
|
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 = numtolong( pint->pp, BASEX ); // This happens to work even if it is only signed
|
||||||
|
|
||||||
destroyrat(pint);
|
destroyrat(pint);
|
||||||
|
|
||||||
|
@ -923,14 +923,14 @@ uint64_t rattoUlonglong( _In_ PRAT prat, uint32_t radix, int32_t precision)
|
||||||
// first get the LO 32 bit word
|
// first get the LO 32 bit word
|
||||||
DUPRAT(pint, prat);
|
DUPRAT(pint, prat);
|
||||||
andrat(&pint, rat_dword, radix, precision); // & 0xFFFFFFFF (2 ^ 32 -1)
|
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 = rattoUlong(pint, radix, precision); // wont throw exception because already hi-dword chopped off
|
||||||
|
|
||||||
DUPRAT(pint, prat); // previous pint will get freed by this as well
|
DUPRAT(pint, prat); // previous pint will get freed by this as well
|
||||||
PRAT prat32 = longtorat(32);
|
PRAT prat32 = longtorat(32);
|
||||||
rshrat(&pint, prat32, radix, precision);
|
rshrat(&pint, prat32, radix, precision);
|
||||||
intrat( &pint, radix, precision);
|
intrat( &pint, radix, precision);
|
||||||
andrat(&pint, rat_dword, radix, precision); // & 0xFFFFFFFF (2 ^ 32 -1)
|
andrat(&pint, rat_dword, radix, precision); // & 0xFFFFFFFF (2 ^ 32 -1)
|
||||||
unsigned long hi = rattoUlong(pint, radix, precision);
|
uint32_t hi = rattoUlong(pint, radix, precision);
|
||||||
|
|
||||||
destroyrat(prat32);
|
destroyrat(prat32);
|
||||||
destroyrat(pint);
|
destroyrat(pint);
|
||||||
|
@ -944,22 +944,22 @@ uint64_t rattoUlonglong( _In_ PRAT prat, uint32_t radix, int32_t precision)
|
||||||
//
|
//
|
||||||
// ARGUMENTS: number input and base of that number.
|
// 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
|
// number input. Assumes that the number is really in the
|
||||||
// base claimed.
|
// base claimed.
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
long numtolong( _In_ PNUMBER pnum, uint32_t radix )
|
int32_t numtolong( _In_ PNUMBER pnum, uint32_t radix )
|
||||||
{
|
{
|
||||||
long lret = 0;
|
int32_t lret = 0;
|
||||||
|
|
||||||
MANTTYPE *pmant = pnum->mant;
|
MANTTYPE *pmant = pnum->mant;
|
||||||
pmant += pnum->cdigit - 1;
|
pmant += pnum->cdigit - 1;
|
||||||
|
|
||||||
long expt = pnum->exp;
|
int32_t expt = pnum->exp;
|
||||||
for (long length = pnum->cdigit; length > 0 && length + expt > 0; length--)
|
for (int32_t length = pnum->cdigit; length > 0 && length + expt > 0; length--)
|
||||||
{
|
{
|
||||||
lret *= radix;
|
lret *= radix;
|
||||||
lret += *(pmant--);
|
lret += *(pmant--);
|
||||||
|
@ -986,10 +986,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;
|
MANTTYPE *pmant;
|
||||||
long cdigits;
|
int32_t cdigits;
|
||||||
bool fstrip = false;
|
bool fstrip = false;
|
||||||
|
|
||||||
// point pmant to the LeastCalculatedDigit
|
// point pmant to the LeastCalculatedDigit
|
||||||
|
@ -1042,10 +1042,10 @@ bool stripzeroesnum(_Inout_ PNUMBER pnum, long starting)
|
||||||
wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_t precision)
|
wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_t precision)
|
||||||
{
|
{
|
||||||
stripzeroesnum(pnum, precision + 2);
|
stripzeroesnum(pnum, precision + 2);
|
||||||
long length = pnum->cdigit;
|
int32_t length = pnum->cdigit;
|
||||||
long exponent = pnum->exp + length; // Actual number of digits to the left of decimal
|
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)
|
if (exponent > precision && format == FMT_FLOAT)
|
||||||
{
|
{
|
||||||
// Force scientific mode to prevent user from assuming 33rd digit is exact.
|
// Force scientific mode to prevent user from assuming 33rd digit is exact.
|
||||||
|
@ -1110,7 +1110,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
|
||||||
if (round != nullptr)
|
if (round != nullptr)
|
||||||
{
|
{
|
||||||
addnum(&pnum, round, radix);
|
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);
|
destroynum(round);
|
||||||
if (stripzeroesnum(pnum, offset))
|
if (stripzeroesnum(pnum, offset))
|
||||||
{
|
{
|
||||||
|
@ -1126,7 +1126,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
|
||||||
|
|
||||||
// Set up all the post rounding stuff.
|
// Set up all the post rounding stuff.
|
||||||
bool useSciForm = false;
|
bool useSciForm = false;
|
||||||
long eout = exponent - 1; // Displayed exponent.
|
int32_t eout = exponent - 1; // Displayed exponent.
|
||||||
MANTTYPE *pmant = pnum->mant + pnum->cdigit - 1;
|
MANTTYPE *pmant = pnum->mant + pnum->cdigit - 1;
|
||||||
// Case where too many digits are to the left of the decimal or
|
// Case where too many digits are to the left of the decimal or
|
||||||
// FMT_SCIENTIFIC or FMT_ENGINEERING was specified.
|
// FMT_SCIENTIFIC or FMT_ENGINEERING was specified.
|
||||||
|
@ -1270,8 +1270,8 @@ PNUMBER RatToNumber(_In_ PRAT prat, uint32_t radix, int32_t precision)
|
||||||
DUPRAT(temprat, prat);
|
DUPRAT(temprat, prat);
|
||||||
// Convert p and q of rational form from internal base to requested base.
|
// Convert p and q of rational form from internal base to requested base.
|
||||||
// Scale by largest power of BASEX possible.
|
// Scale by largest power of BASEX possible.
|
||||||
long scaleby = min(temprat->pp->exp, temprat->pq->exp);
|
int32_t scaleby = min(temprat->pp->exp, temprat->pq->exp);
|
||||||
scaleby = max(scaleby, 0l);
|
scaleby = max<int32_t>(scaleby, 0);
|
||||||
|
|
||||||
temprat->pp->exp -= scaleby;
|
temprat->pp->exp -= scaleby;
|
||||||
temprat->pq->exp -= scaleby;
|
temprat->pq->exp -= scaleby;
|
||||||
|
@ -1362,9 +1362,9 @@ PNUMBER gcd( _In_ PNUMBER a, _In_ PNUMBER b)
|
||||||
// FUNCTION: longfactnum
|
// FUNCTION: longfactnum
|
||||||
//
|
//
|
||||||
// ARGUMENTS:
|
// ARGUMENTS:
|
||||||
// long integer to factorialize.
|
// int32_t integer to factorialize.
|
||||||
// long integer representing base of answer.
|
// int32_t integer representing base of answer.
|
||||||
// unsigned long integer for radix
|
// uint32_t integer for radix
|
||||||
//
|
//
|
||||||
// RETURN: Factorial of input in radix PNUMBER form.
|
// RETURN: Factorial of input in radix PNUMBER form.
|
||||||
//
|
//
|
||||||
|
@ -1372,7 +1372,7 @@ PNUMBER gcd( _In_ PNUMBER a, _In_ PNUMBER b)
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
PNUMBER longfactnum(long inlong, uint32_t radix)
|
PNUMBER longfactnum(int32_t inlong, uint32_t radix)
|
||||||
|
|
||||||
{
|
{
|
||||||
PNUMBER lret= nullptr;
|
PNUMBER lret= nullptr;
|
||||||
|
@ -1394,15 +1394,15 @@ PNUMBER longfactnum(long inlong, uint32_t radix)
|
||||||
// FUNCTION: longprodnum
|
// FUNCTION: longprodnum
|
||||||
//
|
//
|
||||||
// ARGUMENTS:
|
// ARGUMENTS:
|
||||||
// long integer to factorialize.
|
// int32_t integer to factorialize.
|
||||||
// long integer representing base of answer.
|
// int32_t integer representing base of answer.
|
||||||
// unsigned long integer for radix
|
// uint32_t integer for radix
|
||||||
//
|
//
|
||||||
// RETURN: Factorial of input in base PNUMBER form.
|
// RETURN: Factorial of input in base PNUMBER form.
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
PNUMBER longprodnum(long start, long stop, uint32_t radix)
|
PNUMBER longprodnum(int32_t start, int32_t stop, uint32_t radix)
|
||||||
|
|
||||||
{
|
{
|
||||||
PNUMBER lret= nullptr;
|
PNUMBER lret= nullptr;
|
||||||
|
@ -1427,8 +1427,8 @@ PNUMBER longprodnum(long start, long stop, uint32_t radix)
|
||||||
//
|
//
|
||||||
// FUNCTION: numpowlong
|
// FUNCTION: numpowlong
|
||||||
//
|
//
|
||||||
// ARGUMENTS: root as number power as long and radix of
|
// ARGUMENTS: root as number power as int32_t and radix of
|
||||||
// number along with the precision value in long.
|
// number along with the precision value in int32_t.
|
||||||
//
|
//
|
||||||
// RETURN: None root is changed.
|
// RETURN: None root is changed.
|
||||||
//
|
//
|
||||||
|
@ -1437,7 +1437,7 @@ PNUMBER longprodnum(long start, long stop, uint32_t radix)
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void numpowlong( _Inout_ PNUMBER *proot, long power, uint32_t radix, int32_t precision)
|
void numpowlong( _Inout_ PNUMBER *proot, int32_t power, uint32_t radix, int32_t precision)
|
||||||
{
|
{
|
||||||
PNUMBER lret = longtonum( 1, radix );
|
PNUMBER lret = longtonum( 1, radix );
|
||||||
|
|
||||||
|
@ -1460,7 +1460,7 @@ void numpowlong( _Inout_ PNUMBER *proot, long power, uint32_t radix, int32_t pre
|
||||||
//
|
//
|
||||||
// FUNCTION: ratpowlong
|
// FUNCTION: ratpowlong
|
||||||
//
|
//
|
||||||
// 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.
|
// RETURN: None root is changed.
|
||||||
//
|
//
|
||||||
|
@ -1469,7 +1469,7 @@ void numpowlong( _Inout_ PNUMBER *proot, long power, uint32_t radix, int32_t pre
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void ratpowlong( _Inout_ PRAT *proot, long power, int32_t precision)
|
void ratpowlong( _Inout_ PRAT *proot, int32_t power, int32_t precision)
|
||||||
|
|
||||||
{
|
{
|
||||||
if ( power < 0 )
|
if ( power < 0 )
|
||||||
|
|
|
@ -64,7 +64,7 @@ void exprat( PRAT *px, uint32_t radix, int32_t precision)
|
||||||
{
|
{
|
||||||
PRAT pwr= nullptr;
|
PRAT pwr= nullptr;
|
||||||
PRAT pint= nullptr;
|
PRAT pint= nullptr;
|
||||||
long intpwr;
|
int32_t intpwr;
|
||||||
|
|
||||||
if ( rat_gt( *px, rat_max_exp, precision) || rat_lt( *px, rat_min_exp, precision) )
|
if ( rat_gt( *px, rat_max_exp, precision) || rat_lt( *px, rat_min_exp, precision) )
|
||||||
{
|
{
|
||||||
|
@ -183,7 +183,7 @@ void lograt( PRAT *px, int32_t precision)
|
||||||
{
|
{
|
||||||
// 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.
|
// a reasonable range.
|
||||||
long intpwr;
|
int32_t intpwr;
|
||||||
intpwr=LOGRAT2(*px)-1;
|
intpwr=LOGRAT2(*px)-1;
|
||||||
(*px)->pq->exp += intpwr;
|
(*px)->pq->exp += intpwr;
|
||||||
pwr=longtorat(intpwr*BASEXPWR);
|
pwr=longtorat(intpwr*BASEXPWR);
|
||||||
|
@ -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)
|
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
|
// Take the absolute value
|
||||||
(*px)->pp->sign = 1;
|
(*px)->pp->sign = 1;
|
||||||
|
@ -453,7 +453,7 @@ void powratcomp(PRAT *px, PRAT y, uint32_t radix, int32_t precision)
|
||||||
{
|
{
|
||||||
// If power is an integer let ratpowlong deal with it.
|
// If power is an integer let ratpowlong deal with it.
|
||||||
PRAT iy = nullptr;
|
PRAT iy = nullptr;
|
||||||
long inty;
|
int32_t inty;
|
||||||
DUPRAT(iy,y);
|
DUPRAT(iy,y);
|
||||||
subrat(&iy, podd, precision);
|
subrat(&iy, podd, precision);
|
||||||
inty = rattolong(iy, radix, precision);
|
inty = rattolong(iy, radix, precision);
|
||||||
|
|
|
@ -72,7 +72,7 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
|
||||||
PRAT mpy= nullptr;
|
PRAT mpy= nullptr;
|
||||||
PRAT ratprec = nullptr;
|
PRAT ratprec = nullptr;
|
||||||
PRAT ratRadix = nullptr;
|
PRAT ratRadix = nullptr;
|
||||||
long oldprec;
|
int32_t oldprec;
|
||||||
|
|
||||||
// Set up constants and initial conditions
|
// Set up constants and initial conditions
|
||||||
oldprec = precision;
|
oldprec = precision;
|
||||||
|
|
|
@ -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)
|
void asinrat( PRAT *px, uint32_t radix, int32_t precision)
|
||||||
|
|
||||||
{
|
{
|
||||||
long sgn;
|
int32_t sgn;
|
||||||
PRAT pret= nullptr;
|
PRAT pret= nullptr;
|
||||||
PRAT phack= nullptr;
|
PRAT phack= nullptr;
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ void _acosrat( PRAT *px, int32_t precision)
|
||||||
void acosrat( PRAT *px, uint32_t radix, 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;
|
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)
|
void atanrat( PRAT *px, uint32_t radix, int32_t precision)
|
||||||
|
|
||||||
{
|
{
|
||||||
long sgn;
|
int32_t sgn;
|
||||||
PRAT tmpx= nullptr;
|
PRAT tmpx= nullptr;
|
||||||
|
|
||||||
sgn = (*px)->pp->sign * (*px)->pq->sign;
|
sgn = (*px)->pp->sign * (*px)->pq->sign;
|
||||||
|
|
|
@ -22,7 +22,7 @@ void lshrat( PRAT *pa, PRAT b, uint32_t radix, int32_t precision)
|
||||||
|
|
||||||
{
|
{
|
||||||
PRAT pwr= nullptr;
|
PRAT pwr= nullptr;
|
||||||
long intb;
|
int32_t intb;
|
||||||
|
|
||||||
intrat(pa, radix, precision);
|
intrat(pa, radix, precision);
|
||||||
if ( !zernum( (*pa)->pp ) )
|
if ( !zernum( (*pa)->pp ) )
|
||||||
|
@ -45,7 +45,7 @@ void rshrat( PRAT *pa, PRAT b, uint32_t radix, int32_t precision)
|
||||||
|
|
||||||
{
|
{
|
||||||
PRAT pwr= nullptr;
|
PRAT pwr= nullptr;
|
||||||
long intb;
|
int32_t intb;
|
||||||
|
|
||||||
intrat(pa, radix, precision);
|
intrat(pa, radix, precision);
|
||||||
if ( !zernum( (*pa)->pp ) )
|
if ( !zernum( (*pa)->pp ) )
|
||||||
|
@ -138,8 +138,8 @@ void boolnum( PNUMBER *pa, PNUMBER b, int func )
|
||||||
MANTTYPE *pcha;
|
MANTTYPE *pcha;
|
||||||
MANTTYPE *pchb;
|
MANTTYPE *pchb;
|
||||||
MANTTYPE *pchc;
|
MANTTYPE *pchc;
|
||||||
long cdigits;
|
int32_t cdigits;
|
||||||
long mexp;
|
int32_t mexp;
|
||||||
MANTTYPE da;
|
MANTTYPE da;
|
||||||
MANTTYPE db;
|
MANTTYPE db;
|
||||||
|
|
||||||
|
|
|
@ -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 *pcha; // pcha is a pointer to the mantissa of a.
|
||||||
MANTTYPE *pchb; // pchb is a pointer to the mantissa of b.
|
MANTTYPE *pchb; // pchb is a pointer to the mantissa of b.
|
||||||
MANTTYPE *pchc; // pchc is a pointer to the mantissa of c.
|
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.
|
// 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 da; // da is a single 'digit' after possible padding.
|
||||||
MANTTYPE db; // db 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'
|
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.
|
int32_t 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 fcomplb = 0; // fcomplb is a flag to signal b is negative.
|
||||||
|
|
||||||
a=*pa;
|
a=*pa;
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ void __inline mulnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // if pa is one and b isn't just copy b, and adjust the sign.
|
{ // 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);
|
DUPNUM(*pa,b);
|
||||||
(*pa)->sign *= sign;
|
(*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 *pchc; // pchc is a pointer to the mantissa of c.
|
||||||
MANTTYPE *pchcoffset; // pchcoffset, is the anchor location of the next
|
MANTTYPE *pchcoffset; // pchcoffset, is the anchor location of the next
|
||||||
// single digit multiply partial result.
|
// single digit multiply partial result.
|
||||||
long iadigit = 0; // Index of digit being used in the first number.
|
int32_t 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 ibdigit = 0; // Index of digit being used in the second number.
|
||||||
MANTTYPE da = 0; // da is the digit from the fist 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
|
TWO_MANTTYPE cy = 0; // cy is the carry resulting from the addition of
|
||||||
// a multiplied row into the result.
|
// 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.
|
// 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;
|
a=*pa;
|
||||||
ibdigit = a->cdigit + b->cdigit - 1;
|
ibdigit = a->cdigit + b->cdigit - 1;
|
||||||
|
@ -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)
|
void _divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision)
|
||||||
{
|
{
|
||||||
PNUMBER a = *pa;
|
PNUMBER a = *pa;
|
||||||
long thismax = precision + 2;
|
int32_t thismax = precision + 2;
|
||||||
if (thismax < a->cdigit)
|
if (thismax < a->cdigit)
|
||||||
{
|
{
|
||||||
thismax = a->cdigit;
|
thismax = a->cdigit;
|
||||||
|
@ -421,7 +421,7 @@ void _divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision)
|
||||||
// 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'
|
// more than radix 'digits'
|
||||||
list<PNUMBER> numberList{ longtonum(0L, radix) };
|
list<PNUMBER> numberList{ longtonum(0L, radix) };
|
||||||
for (unsigned long i = 1; i < radix; i++)
|
for (uint32_t i = 1; i < radix; i++)
|
||||||
{
|
{
|
||||||
PNUMBER newValue = nullptr;
|
PNUMBER newValue = nullptr;
|
||||||
DUPNUM(newValue, numberList.front());
|
DUPNUM(newValue, numberList.front());
|
||||||
|
@ -431,8 +431,8 @@ void _divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision)
|
||||||
}
|
}
|
||||||
destroynum(tmp);
|
destroynum(tmp);
|
||||||
|
|
||||||
long digit;
|
int32_t digit;
|
||||||
long cdigits = 0;
|
int32_t cdigits = 0;
|
||||||
while (cdigits++ < thismax && !zernum(rem))
|
while (cdigits++ < thismax && !zernum(rem))
|
||||||
{
|
{
|
||||||
digit = radix - 1;
|
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 )
|
bool equnum( PNUMBER a, PNUMBER b )
|
||||||
|
|
||||||
{
|
{
|
||||||
long diff;
|
int32_t diff;
|
||||||
MANTTYPE *pa;
|
MANTTYPE *pa;
|
||||||
MANTTYPE *pb;
|
MANTTYPE *pb;
|
||||||
long cdigits;
|
int32_t cdigits;
|
||||||
long ccdigits;
|
int32_t ccdigits;
|
||||||
MANTTYPE da;
|
MANTTYPE da;
|
||||||
MANTTYPE db;
|
MANTTYPE db;
|
||||||
|
|
||||||
|
@ -573,11 +573,11 @@ bool equnum( PNUMBER a, PNUMBER b )
|
||||||
bool lessnum( PNUMBER a, PNUMBER b )
|
bool lessnum( PNUMBER a, PNUMBER b )
|
||||||
|
|
||||||
{
|
{
|
||||||
long diff;
|
int32_t diff;
|
||||||
MANTTYPE *pa;
|
MANTTYPE *pa;
|
||||||
MANTTYPE *pb;
|
MANTTYPE *pb;
|
||||||
long cdigits;
|
int32_t cdigits;
|
||||||
long ccdigits;
|
int32_t ccdigits;
|
||||||
MANTTYPE da;
|
MANTTYPE da;
|
||||||
MANTTYPE db;
|
MANTTYPE db;
|
||||||
|
|
||||||
|
@ -635,7 +635,7 @@ bool lessnum( PNUMBER a, PNUMBER b )
|
||||||
bool zernum( PNUMBER a )
|
bool zernum( PNUMBER a )
|
||||||
|
|
||||||
{
|
{
|
||||||
long length;
|
int32_t length;
|
||||||
MANTTYPE *pcha;
|
MANTTYPE *pcha;
|
||||||
length = a->cdigit;
|
length = a->cdigit;
|
||||||
pcha = a->mant;
|
pcha = a->mant;
|
||||||
|
|
|
@ -54,10 +54,10 @@ typedef enum eANGLE_TYPE ANGLE_TYPE;
|
||||||
#pragma warning(disable:4200) // nonstandard extension used : zero-sized array in struct/union
|
#pragma warning(disable:4200) // nonstandard extension used : zero-sized array in struct/union
|
||||||
typedef struct _number
|
typedef struct _number
|
||||||
{
|
{
|
||||||
long sign; // The sign of the mantissa, +1, or -1
|
int32_t sign; // The sign of the mantissa, +1, or -1
|
||||||
long cdigit; // The number of digits, or what passes for digits in the
|
int32_t cdigit; // The number of digits, or what passes for digits in the
|
||||||
// radix being used.
|
// 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)
|
// (decimal point in radix 10)
|
||||||
MANTTYPE mant[];
|
MANTTYPE mant[];
|
||||||
// This is actually allocated as a continuation of the
|
// This is actually allocated as a continuation of the
|
||||||
|
@ -208,7 +208,7 @@ _destroynum(x),(x)=nullptr
|
||||||
|
|
||||||
// TRIMNUM ASSUMES the number is in radix form NOT INTERNAL BASEX!!!
|
// TRIMNUM ASSUMES the number is in radix form NOT INTERNAL BASEX!!!
|
||||||
#define TRIMNUM(x, precision) if ( !g_ftrueinfinite ) { \
|
#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 ) \
|
if ( trim > 1 ) \
|
||||||
{ \
|
{ \
|
||||||
memmove( (x)->mant, &((x)->mant[trim]), sizeof(MANTTYPE)*((x)->cdigit-trim) ); \
|
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!!!
|
// TRIMTOP ASSUMES the number is in INTERNAL BASEX!!!
|
||||||
#define TRIMTOP(x, precision) if ( !g_ftrueinfinite ) { \
|
#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 ) \
|
if ( trim > 1 ) \
|
||||||
{ \
|
{ \
|
||||||
memmove( (x)->pp->mant, &((x)->pp->mant[trim]), sizeof(MANTTYPE)*((x)->pp->cdigit-trim) ); \
|
memmove( (x)->pp->mant, &((x)->pp->mant[trim]), sizeof(MANTTYPE)*((x)->pp->cdigit-trim) ); \
|
||||||
|
@ -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
|
// don't use unless you know what you are doing
|
||||||
// used to help decide when to stop calculating.
|
// 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,8 +321,8 @@ extern PNUMBER RatToNumber(_In_ PRAT prat, uint32_t radix, int32_t precision);
|
||||||
// flattens a PRAT by converting it to a PNUMBER and back to a PRAT
|
// flattens a PRAT by converting it to a PNUMBER and back to a PRAT
|
||||||
extern void flatrat(_Inout_ PRAT& prat, uint32_t radix, int32_t precision);
|
extern void flatrat(_Inout_ PRAT& prat, uint32_t radix, int32_t precision);
|
||||||
|
|
||||||
extern long numtolong(_In_ PNUMBER pnum, uint32_t radix );
|
extern int32_t numtolong(_In_ PNUMBER pnum, uint32_t radix );
|
||||||
extern long rattolong(_In_ PRAT prat, uint32_t radix, int32_t precision);
|
extern int32_t rattolong(_In_ PRAT prat, uint32_t radix, int32_t precision);
|
||||||
uint64_t rattoUlonglong(_In_ PRAT prat, uint32_t radix, int32_t precision);
|
uint64_t rattoUlonglong(_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 _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 nRadixxtonum(_In_ PNUMBER a, uint32_t radix, int32_t precision);
|
||||||
|
@ -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.
|
// 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 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 longfactnum(int32_t inlong, uint32_t radix);
|
||||||
extern PNUMBER longprodnum(long start, long stop, uint32_t radix);
|
extern PNUMBER longprodnum(int32_t start, int32_t stop, uint32_t radix);
|
||||||
extern PNUMBER longtonum(long inlong, uint32_t radix);
|
extern PNUMBER longtonum(int32_t inlong, uint32_t radix);
|
||||||
extern PNUMBER Ulongtonum(unsigned long inlong, uint32_t radix);
|
extern PNUMBER Ulongtonum(uint32_t inlong, uint32_t radix);
|
||||||
extern PNUMBER numtonRadixx(PNUMBER a, uint32_t radix);
|
extern PNUMBER numtonRadixx(PNUMBER a, uint32_t radix);
|
||||||
|
|
||||||
// creates a empty/undefined rational representation (p/q)
|
// 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
|
// returns a new rat structure with the natural log of x->p/x->q
|
||||||
extern void lograt( _Inout_ PRAT *px, int32_t precision);
|
extern void lograt( _Inout_ PRAT *px, int32_t precision);
|
||||||
|
|
||||||
extern PRAT longtorat( long inlong );
|
extern PRAT longtorat( int32_t inlong );
|
||||||
extern PRAT Ulongtorat( unsigned long inulong );
|
extern PRAT Ulongtorat( uint32_t inulong );
|
||||||
extern PRAT numtorat( _In_ PNUMBER pin, uint32_t radix);
|
extern PRAT numtorat( _In_ PNUMBER pin, uint32_t radix);
|
||||||
|
|
||||||
extern void sinhrat( _Inout_ PRAT *px, uint32_t radix, int32_t precision);
|
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 mulnum( _Inout_ PNUMBER *pa, _In_ PNUMBER b, uint32_t radix);
|
||||||
extern void mulnumx( _Inout_ PNUMBER *pa, _In_ PNUMBER b );
|
extern void mulnumx( _Inout_ PNUMBER *pa, _In_ PNUMBER b );
|
||||||
extern void mulrat( _Inout_ PRAT *pa, _In_ PRAT b, int32_t precision);
|
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 numpowlong( _Inout_ PNUMBER *proot, int32_t power, uint32_t radix, int32_t precision);
|
||||||
extern void numpowlongx( _Inout_ PNUMBER *proot, long power );
|
extern void numpowlongx( _Inout_ PNUMBER *proot, int32_t power );
|
||||||
extern void orrat( _Inout_ PRAT *pa, _In_ PRAT b, uint32_t radix, int32_t precision);
|
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 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 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 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 ratpowlong( _Inout_ PRAT *proot, int32_t power, int32_t precision);
|
||||||
extern void remnum( _Inout_ PNUMBER *pa, _In_ PNUMBER b, uint32_t radix);
|
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 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);
|
extern void scale2pi( _Inout_ PRAT *px, uint32_t radix, int32_t precision);
|
||||||
|
|
|
@ -215,7 +215,7 @@ void ChangeConstants(uint32_t radix, int32_t precision)
|
||||||
|
|
||||||
// Apparently when dividing 180 by pi, another (internal) digit of
|
// Apparently when dividing 180 by pi, another (internal) digit of
|
||||||
// precision is needed.
|
// precision is needed.
|
||||||
long extraPrecision = precision + g_ratio;
|
int32_t extraPrecision = precision + g_ratio;
|
||||||
DUPRAT(pi, rat_half);
|
DUPRAT(pi, rat_half);
|
||||||
asinrat(&pi, radix, extraPrecision);
|
asinrat(&pi, radix, extraPrecision);
|
||||||
mulrat(&pi, rat_six, extraPrecision);
|
mulrat(&pi, rat_six, extraPrecision);
|
||||||
|
@ -333,7 +333,7 @@ bool rat_equ( PRAT a, PRAT b, int32_t precision)
|
||||||
//
|
//
|
||||||
// FUNCTION: rat_ge
|
// 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
|
// 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
|
// 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
|
// 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
|
// 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
|
// 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
|
// Logscale is a quick way to tell how much extra precision is needed for
|
||||||
// scaling by scalefact.
|
// 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) );
|
(pret->pq->cdigit+pret->pq->exp) );
|
||||||
if ( logscale > 0 )
|
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
|
// Logscale is a quick way to tell how much extra precision is needed for
|
||||||
// scaling by 2 pi.
|
// 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) );
|
(pret->pq->cdigit+pret->pq->exp) );
|
||||||
if ( logscale > 0 )
|
if ( logscale > 0 )
|
||||||
{
|
{
|
||||||
|
@ -660,7 +660,7 @@ void _readconstants( void )
|
||||||
//
|
//
|
||||||
// FUNCTION: trimit
|
// FUNCTION: trimit
|
||||||
//
|
//
|
||||||
// ARGUMENTS: PRAT *px, long precision
|
// ARGUMENTS: PRAT *px, int32_t precision
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// DESCRIPTION: Chops off digits from rational numbers to avoid time
|
// DESCRIPTION: Chops off digits from rational numbers to avoid time
|
||||||
|
@ -681,7 +681,7 @@ void trimit( PRAT *px, int32_t precision)
|
||||||
{
|
{
|
||||||
if ( !g_ftrueinfinite )
|
if ( !g_ftrueinfinite )
|
||||||
{
|
{
|
||||||
long trim;
|
int32_t trim;
|
||||||
PNUMBER pp=(*px)->pp;
|
PNUMBER pp=(*px)->pp;
|
||||||
PNUMBER pq=(*px)->pq;
|
PNUMBER pq=(*px)->pq;
|
||||||
trim = g_ratio * (min((pp->cdigit+pp->exp),(pq->cdigit+pq->exp))-1) - precision;
|
trim = g_ratio * (min((pp->cdigit+pp->exp),(pq->cdigit+pq->exp))-1) - precision;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue