Replace (unsigned) long -> (u)int32_t

This commit is contained in:
Michał Janiszewski 2019-03-16 21:25:25 +01:00 committed by Michał Janiszewski
commit 17c74b9527
15 changed files with 136 additions and 134 deletions

View file

@ -56,7 +56,7 @@ bool CalcInput::TryToggleSign(bool isIntegerMode, wstring_view maxNumStr)
return true;
}
bool CalcInput::TryAddDigit(unsigned int value, uint32_t radix, bool isIntegerMode, wstring_view maxNumStr, long wordBitWidth, int maxDigits)
bool CalcInput::TryAddDigit(unsigned int value, uint32_t radix, bool isIntegerMode, wstring_view maxNumStr, int32_t wordBitWidth, int maxDigits)
{
// Convert from an integer into a character
// This includes both normal digits and alpha 'digits' for radixes > 10

View file

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

View file

@ -31,7 +31,7 @@ namespace CalcEngine
Rational::Rational(int32_t i)
{
PRAT pr = longtorat(static_cast<long>(i));
PRAT pr = longtorat(static_cast<int32_t>(i));
m_p = Number{ pr->pp };
m_q = Number{ pr->pq };
@ -41,7 +41,7 @@ namespace CalcEngine
Rational::Rational(uint32_t ui)
{
PRAT pr = Ulongtorat(static_cast<unsigned long>(ui));
PRAT pr = Ulongtorat(static_cast<uint32_t>(ui));
m_p = Number{ pr->pp };
m_q = Number{ pr->pq };

View file

@ -15,7 +15,7 @@ using namespace CalcEngine;
static constexpr int DEFAULT_MAX_DIGITS = 32;
static constexpr int DEFAULT_PRECISION = 32;
static constexpr long DEFAULT_RADIX = 10;
static constexpr int32_t DEFAULT_RADIX = 10;
static constexpr wchar_t DEFAULT_DEC_SEPARATOR = L'.';
static constexpr wchar_t DEFAULT_GRP_SEPARATOR = L',';

View file

@ -3,6 +3,8 @@
#pragma once
#include "Ratpack/CalcErr.h"
template <typename TType>
class CalculatorVector
{

View file

@ -47,7 +47,7 @@ namespace CalcEngine
void Clear();
bool TryToggleSign(bool isIntegerMode, std::wstring_view maxNumStr);
bool TryAddDigit(unsigned int value, uint32_t radix, bool isIntegerMode, std::wstring_view maxNumStr, long wordBitWidth, int maxDigits);
bool TryAddDigit(unsigned int value, uint32_t radix, bool isIntegerMode, std::wstring_view maxNumStr, int32_t wordBitWidth, int maxDigits);
bool TryAddDecimalPt();
bool HasDecimalPt();
bool TryBeginExponent();

View file

@ -48,7 +48,7 @@ void __inline mulnumx( PNUMBER *pa, PNUMBER b )
else
{
// if pa is one and b isn't just copy b. and adjust the sign.
long sign = (*pa)->sign;
int32_t sign = (*pa)->sign;
DUPNUM(*pa,b);
(*pa)->sign *= sign;
}
@ -86,14 +86,14 @@ void _mulnumx( PNUMBER *pa, PNUMBER b )
MANTTYPE *ptrc; // ptrc is a pointer to the mantissa of c.
MANTTYPE *ptrcoffset; // ptrcoffset, is the anchor location of the next
// single digit multiply partial result.
long iadigit=0; // Index of digit being used in the first number.
long ibdigit=0; // Index of digit being used in the second number.
int32_t iadigit=0; // Index of digit being used in the first number.
int32_t ibdigit=0; // Index of digit being used in the second number.
MANTTYPE da=0; // da is the digit from the fist number.
TWO_MANTTYPE cy=0; // cy is the carry resulting from the addition of
// a multiplied row into the result.
TWO_MANTTYPE mcy=0; // mcy is the resultant from a single
// multiply, AND the carry of that multiply.
long icdigit=0; // Index of digit being calculated in final result.
int32_t icdigit=0; // Index of digit being calculated in final result.
a=*pa;
@ -162,7 +162,7 @@ void _mulnumx( PNUMBER *pa, PNUMBER b )
//
// FUNCTION: numpowlongx
//
// ARGUMENTS: root as number power as long
// ARGUMENTS: root as number power as int32_t
// number.
//
// 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 );
@ -232,7 +232,7 @@ void __inline divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
else
{
// if pa is one and b is not one, just copy b, and adjust the sign.
long sign = (*pa)->sign;
int32_t sign = (*pa)->sign;
DUPNUM(*pa,b);
(*pa)->sign *= sign;
}
@ -266,10 +266,10 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
// guesses one bit too far.
PNUMBER tmp = nullptr; // current guess being worked on for divide.
PNUMBER rem = nullptr; // remainder after applying guess.
long cdigits; // count of digits for answer.
int32_t cdigits; // count of digits for answer.
MANTTYPE *ptrc; // ptrc is a pointer to the mantissa of c.
long thismax = precision + g_ratio; // set a maximum number of internal digits
int32_t thismax = precision + g_ratio; // set a maximum number of internal digits
// to shoot for in the divide.
a=*pa;
@ -301,7 +301,7 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
while ( cdigits++ < thismax && !zernum(rem) )
{
long digit = 0;
int32_t digit = 0;
*ptrc = 0;
while ( !lessnum( rem, b ) )
{

View file

@ -29,12 +29,12 @@ static constexpr wstring_view DIGITS = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabc
// ratio of internal 'digits' to output 'digits'
// Calculated elsewhere as part of initialization and when base is changed
long g_ratio; // int(log(2L^BASEXPWR)/log(radix))
int32_t g_ratio; // int(log(2L^BASEXPWR)/log(radix))
// Default decimal separator
wchar_t g_decimalSeparator = L'.';
// 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)
{
@ -245,8 +245,8 @@ PRAT numtorat( _In_ PNUMBER pin, uint32_t radix)
PNUMBER nRadixxtonum( _In_ PNUMBER a, uint32_t radix, int32_t precision)
{
unsigned long bitmask;
unsigned long cdigits;
uint32_t bitmask;
uint32_t cdigits;
MANTTYPE *ptr;
PNUMBER sum = longtonum( 0, radix );
@ -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
// requested precision.
cdigits = precision + 1;
if ( cdigits > (unsigned long)a->cdigit )
if ( cdigits > (uint32_t)a->cdigit )
{
cdigits = (unsigned long)a->cdigit;
cdigits = (uint32_t)a->cdigit;
}
// scale by the internal base to the internal exponent offset of the LSD
@ -312,7 +312,7 @@ PNUMBER numtonRadixx(_In_ PNUMBER a, uint32_t radix)
PNUMBER thisdigit = nullptr; // thisdigit holds the current digit of a
// being summed into result.
long idigit; // idigit is the iterate of digits in a.
int32_t idigit; // idigit is the iterate of digits in a.
for ( idigit = 0; idigit < a->cdigit; idigit++ )
{
mulnumx( &pnumret, num_radix);
@ -391,7 +391,7 @@ PRAT StringToRat(bool mantissaIsNegative, wstring_view mantissa, bool exponentIs
}
// Deal with exponent
long expt = 0;
int32_t expt = 0;
if (!exponent.empty())
{
// Exponent specified, convert to number form.
@ -574,8 +574,8 @@ wchar_t NormalizeCharDigit(wchar_t c, uint32_t radix)
PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precision)
{
long expSign = 1L; // expSign is exponent sign ( +/- 1 )
long expValue = 0L; // expValue is exponent mantissa, should be unsigned
int32_t expSign = 1L; // expSign is exponent sign ( +/- 1 )
int32_t expValue = 0L; // expValue is exponent mantissa, should be unsigned
PNUMBER pnumret = nullptr;
createnum(pnumret, static_cast<uint32_t>(numberString.length()));
@ -637,7 +637,7 @@ PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precis
if (pos != wstring_view::npos)
{
expValue *= radix;
expValue += static_cast<long>(pos);
expValue += static_cast<int32_t>(pos);
}
else
{
@ -683,7 +683,7 @@ PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precis
}
else
{
while (pnumret->cdigit < static_cast<long>(numberString.length()))
while (pnumret->cdigit < static_cast<int32_t>(numberString.length()))
{
pnumret->cdigit++;
pnumret->exp--;
@ -708,16 +708,16 @@ PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precis
//
// 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)
// form, where q is 1 and p is the long.
// DESCRIPTION: Converts int32_t input to rational (p over q)
// form, where q is 1 and p is the int32_t.
//
//-----------------------------------------------------------------------------
PRAT longtorat( _In_ long inlong )
PRAT longtorat( _In_ int32_t inlong )
{
PRAT pratret= nullptr;
@ -733,15 +733,15 @@ PRAT longtorat( _In_ long inlong )
//
// 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)
// form, where q is 1 and p is the unsigned long. Being unsigned cant take negative
// DESCRIPTION: Converts uint32_t input to rational (p over q)
// form, where q is 1 and p is the uint32_t. Being unsigned cant take negative
// numbers, but the full range of unsigned numbers
//
//-----------------------------------------------------------------------------
PRAT Ulongtorat( _In_ unsigned long inulong )
PRAT Ulongtorat( _In_ uint32_t inulong )
{
PRAT pratret= nullptr;
@ -755,16 +755,16 @@ PRAT Ulongtorat( _In_ unsigned long inulong )
//
// FUNCTION: longtonum
//
// ARGUMENTS: long input and radix requested.
// ARGUMENTS: int32_t input and radix requested.
//
// RETURN: number
//
// DESCRIPTION: Returns a number representation in the
// base requested of the long value passed in.
// base requested of the int32_t value passed in.
//
//-----------------------------------------------------------------------------
PNUMBER longtonum( long inlong, uint32_t radix)
PNUMBER longtonum( int32_t inlong, uint32_t radix)
{
MANTTYPE *pmant;
@ -802,13 +802,13 @@ 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 uint32_t value passed in. Being unsigned number it has no
// negative number and takes the full range of unsigned number
//
//-----------------------------------------------------------------------------
PNUMBER Ulongtonum(unsigned long inlong, uint32_t radix)
PNUMBER Ulongtonum(uint32_t inlong, uint32_t radix)
{
MANTTYPE *pmant;
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.
//
// RETURN: long
// RETURN: int32_t
//
// DESCRIPTION: returns the long representation of the
// DESCRIPTION: returns the int32_t representation of the
// number input. Assumes that the number is in the internal
// base.
//
//-----------------------------------------------------------------------------
long rattolong( _In_ PRAT prat , uint32_t radix, int32_t precision)
int32_t 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) )
{
@ -858,7 +858,7 @@ long rattolong( _In_ PRAT prat , uint32_t radix, int32_t precision)
divnumx( &(pint->pp), pint->pq, precision);
DUPNUM( pint->pq, num_one );
long lret = numtolong( pint->pp, BASEX );
int32_t lret = numtolong( pint->pp, BASEX );
destroyrat(pint);
@ -878,7 +878,7 @@ long rattolong( _In_ PRAT prat , uint32_t radix, int32_t precision)
// 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) )
{
@ -893,7 +893,7 @@ unsigned long rattoUlong( _In_ PRAT prat, uint32_t radix, int32_t precision)
divnumx( &(pint->pp), pint->pq, precision);
DUPNUM( pint->pq, num_one );
unsigned long lret = numtolong( pint->pp, BASEX ); // This happens to work even if it is only signed
uint32_t lret = numtolong( pint->pp, BASEX ); // This happens to work even if it is only signed
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
DUPRAT(pint, prat);
andrat(&pint, rat_dword, radix, precision); // & 0xFFFFFFFF (2 ^ 32 -1)
unsigned long lo = rattoUlong(pint, radix, precision); // wont throw exception because already hi-dword chopped off
uint32_t lo = 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
PRAT prat32 = longtorat(32);
rshrat(&pint, prat32, radix, precision);
intrat( &pint, radix, precision);
andrat(&pint, rat_dword, radix, precision); // & 0xFFFFFFFF (2 ^ 32 -1)
unsigned long hi = rattoUlong(pint, radix, precision);
uint32_t hi = rattoUlong(pint, radix, precision);
destroyrat(prat32);
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.
//
// RETURN: long
// RETURN: int32_t
//
// DESCRIPTION: returns the long representation of the
// DESCRIPTION: returns the int32_t representation of the
// number input. Assumes that the number is really in the
// base claimed.
//
//-----------------------------------------------------------------------------
long numtolong( _In_ PNUMBER pnum, uint32_t radix )
int32_t numtolong( _In_ PNUMBER pnum, uint32_t radix )
{
long lret = 0;
int32_t lret = 0;
MANTTYPE *pmant = pnum->mant;
pmant += pnum->cdigit - 1;
long expt = pnum->exp;
for (long length = pnum->cdigit; length > 0 && length + expt > 0; length--)
int32_t expt = pnum->exp;
for (int32_t length = pnum->cdigit; length > 0 && length + expt > 0; length--)
{
lret *= radix;
lret += *(pmant--);
@ -986,10 +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;
long cdigits;
int32_t cdigits;
bool fstrip = false;
// 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)
{
stripzeroesnum(pnum, precision + 2);
long length = pnum->cdigit;
long exponent = pnum->exp + length; // Actual number of digits to the left of decimal
int32_t length = pnum->cdigit;
int32_t exponent = pnum->exp + length; // Actual number of digits to the left of decimal
long oldFormat = format;
int32_t oldFormat = format;
if (exponent > precision && format == FMT_FLOAT)
{
// Force scientific mode to prevent user from assuming 33rd digit is exact.
@ -1110,7 +1110,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
if (round != nullptr)
{
addnum(&pnum, round, radix);
long offset = (pnum->cdigit + pnum->exp) - (round->cdigit + round->exp);
int32_t offset = (pnum->cdigit + pnum->exp) - (round->cdigit + round->exp);
destroynum(round);
if (stripzeroesnum(pnum, offset))
{
@ -1126,7 +1126,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
// Set up all the post rounding stuff.
bool useSciForm = false;
long eout = exponent - 1; // Displayed exponent.
int32_t eout = exponent - 1; // Displayed exponent.
MANTTYPE *pmant = pnum->mant + pnum->cdigit - 1;
// Case where too many digits are to the left of the decimal or
// FMT_SCIENTIFIC or FMT_ENGINEERING was specified.
@ -1270,8 +1270,8 @@ PNUMBER RatToNumber(_In_ PRAT prat, uint32_t radix, int32_t precision)
DUPRAT(temprat, prat);
// Convert p and q of rational form from internal base to requested base.
// Scale by largest power of BASEX possible.
long scaleby = min(temprat->pp->exp, temprat->pq->exp);
scaleby = max(scaleby, 0l);
int32_t scaleby = min(temprat->pp->exp, temprat->pq->exp);
scaleby = max<int32_t>(scaleby, 0);
temprat->pp->exp -= scaleby;
temprat->pq->exp -= scaleby;
@ -1362,9 +1362,9 @@ PNUMBER gcd( _In_ PNUMBER a, _In_ PNUMBER b)
// FUNCTION: longfactnum
//
// ARGUMENTS:
// long integer to factorialize.
// long integer representing base of answer.
// unsigned long integer for radix
// int32_t integer to factorialize.
// int32_t integer representing base of answer.
// uint32_t integer for radix
//
// RETURN: Factorial of input in radix PNUMBER form.
//
@ -1372,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;
@ -1394,15 +1394,15 @@ PNUMBER longfactnum(long inlong, uint32_t radix)
// FUNCTION: longprodnum
//
// ARGUMENTS:
// long integer to factorialize.
// long integer representing base of answer.
// unsigned long integer for radix
// int32_t integer to factorialize.
// int32_t integer representing base of answer.
// uint32_t integer for radix
//
// RETURN: Factorial of input in base PNUMBER form.
//
//-----------------------------------------------------------------------------
PNUMBER longprodnum(long start, long stop, uint32_t radix)
PNUMBER longprodnum(int32_t start, int32_t stop, uint32_t radix)
{
PNUMBER lret= nullptr;
@ -1427,8 +1427,8 @@ PNUMBER longprodnum(long start, long stop, uint32_t radix)
//
// FUNCTION: numpowlong
//
// ARGUMENTS: root as number power as long and radix of
// number along with the precision value in long.
// ARGUMENTS: root as number power as int32_t and radix of
// number along with the precision value in int32_t.
//
// RETURN: None root is changed.
//
@ -1437,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 );
@ -1460,7 +1460,7 @@ void numpowlong( _Inout_ PNUMBER *proot, long power, uint32_t radix, int32_t pre
//
// 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.
//
@ -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 )

View file

@ -64,7 +64,7 @@ void exprat( PRAT *px, uint32_t radix, int32_t precision)
{
PRAT pwr= nullptr;
PRAT pint= nullptr;
long intpwr;
int32_t intpwr;
if ( rat_gt( *px, rat_max_exp, precision) || rat_lt( *px, rat_min_exp, precision) )
{
@ -183,7 +183,7 @@ void lograt( PRAT *px, int32_t precision)
{
// Take advantage of px's base BASEX to scale quickly down to
// a reasonable range.
long intpwr;
int32_t intpwr;
intpwr=LOGRAT2(*px)-1;
(*px)->pq->exp += intpwr;
pwr=longtorat(intpwr*BASEXPWR);
@ -408,7 +408,7 @@ void powratNumeratorDenominator(PRAT *px, PRAT y, uint32_t radix, int32_t precis
//---------------------------------------------------------------------------
void powratcomp(PRAT *px, PRAT y, uint32_t radix, int32_t precision)
{
long sign = ((*px)->pp->sign * (*px)->pq->sign);
int32_t sign = ((*px)->pp->sign * (*px)->pq->sign);
// Take the absolute value
(*px)->pp->sign = 1;
@ -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.
PRAT iy = nullptr;
long inty;
int32_t inty;
DUPRAT(iy,y);
subrat(&iy, podd, precision);
inty = rattolong(iy, radix, precision);

View file

@ -72,7 +72,7 @@ void _gamma( PRAT *pn, uint32_t radix, int32_t precision)
PRAT mpy= nullptr;
PRAT ratprec = nullptr;
PRAT ratRadix = nullptr;
long oldprec;
int32_t oldprec;
// Set up constants and initial conditions
oldprec = precision;

View file

@ -92,7 +92,7 @@ void asinanglerat( _Inout_ PRAT *pa, ANGLE_TYPE angletype, uint32_t radix, int32
void asinrat( PRAT *px, uint32_t radix, int32_t precision)
{
long sgn;
int32_t sgn;
PRAT pret= nullptr;
PRAT phack= nullptr;
@ -204,7 +204,7 @@ void _acosrat( PRAT *px, int32_t precision)
void acosrat( PRAT *px, uint32_t radix, int32_t precision)
{
long sgn;
int32_t sgn;
sgn = (*px)->pp->sign*(*px)->pq->sign;
@ -291,7 +291,7 @@ void _atanrat( PRAT *px, int32_t precision)
void atanrat( PRAT *px, uint32_t radix, int32_t precision)
{
long sgn;
int32_t sgn;
PRAT tmpx= nullptr;
sgn = (*px)->pp->sign * (*px)->pq->sign;

View file

@ -22,7 +22,7 @@ void lshrat( PRAT *pa, PRAT b, uint32_t radix, int32_t precision)
{
PRAT pwr= nullptr;
long intb;
int32_t intb;
intrat(pa, radix, precision);
if ( !zernum( (*pa)->pp ) )
@ -45,7 +45,7 @@ void rshrat( PRAT *pa, PRAT b, uint32_t radix, int32_t precision)
{
PRAT pwr= nullptr;
long intb;
int32_t intb;
intrat(pa, radix, precision);
if ( !zernum( (*pa)->pp ) )
@ -138,8 +138,8 @@ void boolnum( PNUMBER *pa, PNUMBER b, int func )
MANTTYPE *pcha;
MANTTYPE *pchb;
MANTTYPE *pchc;
long cdigits;
long mexp;
int32_t cdigits;
int32_t mexp;
MANTTYPE da;
MANTTYPE db;

View file

@ -66,14 +66,14 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
MANTTYPE *pcha; // pcha is a pointer to the mantissa of a.
MANTTYPE *pchb; // pchb is a pointer to the mantissa of b.
MANTTYPE *pchc; // pchc is a pointer to the mantissa of c.
long cdigits; // cdigits is the max count of the digits results
int32_t cdigits; // cdigits is the max count of the digits results
// used as a counter.
long mexp; // mexp is the exponent of the result.
int32_t mexp; // mexp is the exponent of the result.
MANTTYPE da; // da is a single 'digit' after possible padding.
MANTTYPE db; // db is a single 'digit' after possible padding.
MANTTYPE cy=0; // cy is the value of a carry after adding two 'digits'
long fcompla = 0; // fcompla is a flag to signal a is negative.
long fcomplb = 0; // fcomplb is a flag to signal b is negative.
int32_t fcompla = 0; // fcompla is a flag to signal a is negative.
int32_t fcomplb = 0; // fcomplb is a flag to signal b is negative.
a=*pa;
@ -205,7 +205,7 @@ void __inline mulnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
}
else
{ // if pa is one and b isn't just copy b, and adjust the sign.
long sign = (*pa)->sign;
int32_t sign = (*pa)->sign;
DUPNUM(*pa,b);
(*pa)->sign *= sign;
}
@ -226,14 +226,14 @@ void _mulnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
MANTTYPE *pchc; // pchc is a pointer to the mantissa of c.
MANTTYPE *pchcoffset; // pchcoffset, is the anchor location of the next
// single digit multiply partial result.
long iadigit = 0; // Index of digit being used in the first number.
long ibdigit = 0; // Index of digit being used in the second number.
int32_t iadigit = 0; // Index of digit being used in the first number.
int32_t ibdigit = 0; // Index of digit being used in the second number.
MANTTYPE da = 0; // da is the digit from the fist number.
TWO_MANTTYPE cy = 0; // cy is the carry resulting from the addition of
// a multiplied row into the result.
TWO_MANTTYPE mcy = 0; // mcy is the resultant from a single
// multiply, AND the carry of that multiply.
long icdigit = 0; // Index of digit being calculated in final result.
int32_t icdigit = 0; // Index of digit being calculated in final result.
a=*pa;
ibdigit = a->cdigit + b->cdigit - 1;
@ -394,7 +394,7 @@ void __inline divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision)
void _divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision)
{
PNUMBER a = *pa;
long thismax = precision + 2;
int32_t thismax = precision + 2;
if (thismax < a->cdigit)
{
thismax = a->cdigit;
@ -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
// more than radix 'digits'
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;
DUPNUM(newValue, numberList.front());
@ -431,8 +431,8 @@ void _divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision)
}
destroynum(tmp);
long digit;
long cdigits = 0;
int32_t digit;
int32_t cdigits = 0;
while (cdigits++ < thismax && !zernum(rem))
{
digit = radix - 1;
@ -505,11 +505,11 @@ void _divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision)
bool equnum( PNUMBER a, PNUMBER b )
{
long diff;
int32_t diff;
MANTTYPE *pa;
MANTTYPE *pb;
long cdigits;
long ccdigits;
int32_t cdigits;
int32_t ccdigits;
MANTTYPE da;
MANTTYPE db;
@ -573,11 +573,11 @@ bool equnum( PNUMBER a, PNUMBER b )
bool lessnum( PNUMBER a, PNUMBER b )
{
long diff;
int32_t diff;
MANTTYPE *pa;
MANTTYPE *pb;
long cdigits;
long ccdigits;
int32_t cdigits;
int32_t ccdigits;
MANTTYPE da;
MANTTYPE db;
@ -635,7 +635,7 @@ bool lessnum( PNUMBER a, PNUMBER b )
bool zernum( PNUMBER a )
{
long length;
int32_t length;
MANTTYPE *pcha;
length = a->cdigit;
pcha = a->mant;

View file

@ -54,10 +54,10 @@ typedef enum eANGLE_TYPE ANGLE_TYPE;
#pragma warning(disable:4200) // nonstandard extension used : zero-sized array in struct/union
typedef struct _number
{
long sign; // The sign of the mantissa, +1, or -1
long cdigit; // The number of digits, or what passes for digits in the
int32_t sign; // The sign of the mantissa, +1, or -1
int32_t cdigit; // The number of digits, or what passes for digits in the
// radix being used.
long exp; // The offset of digits from the radix point
int32_t exp; // The offset of digits from the radix point
// (decimal point in radix 10)
MANTTYPE mant[];
// This is actually allocated as a continuation of the
@ -208,7 +208,7 @@ _destroynum(x),(x)=nullptr
// TRIMNUM ASSUMES the number is in radix form NOT INTERNAL BASEX!!!
#define TRIMNUM(x, precision) if ( !g_ftrueinfinite ) { \
long trim = (x)->cdigit - precision-g_ratio;\
int32_t trim = (x)->cdigit - precision-g_ratio;\
if ( trim > 1 ) \
{ \
memmove( (x)->mant, &((x)->mant[trim]), sizeof(MANTTYPE)*((x)->cdigit-trim) ); \
@ -218,7 +218,7 @@ memmove( (x)->mant, &((x)->mant[trim]), sizeof(MANTTYPE)*((x)->cdigit-trim) ); \
}
// TRIMTOP ASSUMES the number is in INTERNAL BASEX!!!
#define TRIMTOP(x, precision) if ( !g_ftrueinfinite ) { \
long trim = (x)->pp->cdigit - (precision/g_ratio) - 2;\
int32_t trim = (x)->pp->cdigit - (precision/g_ratio) - 2;\
if ( trim > 1 ) \
{ \
memmove( (x)->pp->mant, &((x)->pp->mant[trim]), sizeof(MANTTYPE)*((x)->pp->cdigit-trim) ); \
@ -294,7 +294,7 @@ extern bool g_ftrueinfinite; // set to true to allow infinite precision
// don't use unless you know what you are doing
// used to help decide when to stop calculating.
extern long g_ratio; // Internally calculated ratio of internal radix
extern int32_t g_ratio; // Internally calculated ratio of internal radix
//-----------------------------------------------------------------------------
//
@ -321,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
extern void flatrat(_Inout_ PRAT& prat, uint32_t radix, int32_t precision);
extern long numtolong(_In_ PNUMBER pnum, uint32_t radix );
extern long rattolong(_In_ PRAT prat, uint32_t radix, int32_t precision);
extern int32_t numtolong(_In_ PNUMBER pnum, uint32_t radix );
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);
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);
@ -332,10 +332,10 @@ extern PNUMBER StringToNumber(std::wstring_view numberString, uint32_t radix, in
// takes a text representation of a number as a mantissa with sign and an exponent with sign.
extern PRAT StringToRat(bool mantissaIsNegative, std::wstring_view mantissa, bool exponentIsNegative, std::wstring_view exponent, uint32_t radix, int32_t precision);
extern PNUMBER longfactnum(long inlong, uint32_t radix);
extern PNUMBER longprodnum(long start, long stop, uint32_t radix);
extern PNUMBER longtonum(long inlong, uint32_t radix);
extern PNUMBER Ulongtonum(unsigned long inlong, uint32_t radix);
extern PNUMBER longfactnum(int32_t inlong, uint32_t radix);
extern PNUMBER longprodnum(int32_t start, int32_t stop, uint32_t radix);
extern PNUMBER longtonum(int32_t inlong, uint32_t radix);
extern PNUMBER Ulongtonum(uint32_t inlong, uint32_t radix);
extern PNUMBER numtonRadixx(PNUMBER a, uint32_t radix);
// creates a empty/undefined rational representation (p/q)
@ -393,8 +393,8 @@ extern void log10rat( _Inout_ PRAT *px, int32_t precision);
// returns a new rat structure with the natural log of x->p/x->q
extern void lograt( _Inout_ PRAT *px, int32_t precision);
extern PRAT longtorat( long inlong );
extern PRAT Ulongtorat( unsigned long inulong );
extern PRAT longtorat( int32_t inlong );
extern PRAT Ulongtorat( uint32_t inulong );
extern PRAT numtorat( _In_ PNUMBER pin, uint32_t radix);
extern void sinhrat( _Inout_ PRAT *px, uint32_t radix, int32_t precision);
@ -429,13 +429,13 @@ extern void intrat( _Inout_ PRAT *px, uint32_t radix, int32_t precision);
extern void mulnum( _Inout_ PNUMBER *pa, _In_ PNUMBER b, uint32_t radix);
extern void mulnumx( _Inout_ PNUMBER *pa, _In_ PNUMBER b );
extern void mulrat( _Inout_ PRAT *pa, _In_ PRAT b, int32_t precision);
extern void numpowlong( _Inout_ PNUMBER *proot, long power, uint32_t radix, int32_t precision);
extern void numpowlongx( _Inout_ PNUMBER *proot, long power );
extern void numpowlong( _Inout_ PNUMBER *proot, int32_t power, uint32_t radix, int32_t precision);
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 powrat( _Inout_ PRAT *pa, _In_ PRAT b , uint32_t radix, int32_t precision);
extern void powratNumeratorDenominator(_Inout_ PRAT *pa, _In_ PRAT b, uint32_t radix, int32_t precision);
extern void powratcomp(_Inout_ PRAT *pa, _In_ PRAT b, uint32_t radix, int32_t precision);
extern void ratpowlong( _Inout_ PRAT *proot, long power, int32_t precision);
extern void ratpowlong( _Inout_ PRAT *proot, int32_t power, int32_t precision);
extern void remnum( _Inout_ PNUMBER *pa, _In_ PNUMBER b, uint32_t radix);
extern void rootrat( _Inout_ PRAT *pa, _In_ PRAT b , uint32_t radix, int32_t precision);
extern void scale2pi( _Inout_ PRAT *px, uint32_t radix, int32_t precision);

View file

@ -215,7 +215,7 @@ void ChangeConstants(uint32_t radix, int32_t precision)
// Apparently when dividing 180 by pi, another (internal) digit of
// precision is needed.
long extraPrecision = precision + g_ratio;
int32_t extraPrecision = precision + g_ratio;
DUPRAT(pi, rat_half);
asinrat(&pi, radix, extraPrecision);
mulrat(&pi, rat_six, extraPrecision);
@ -333,7 +333,7 @@ bool rat_equ( PRAT a, PRAT b, int32_t precision)
//
// FUNCTION: rat_ge
//
// ARGUMENTS: PRAT a, PRAT b and long precision
// ARGUMENTS: PRAT a, PRAT b and int32_t precision
//
// RETURN: true if a is greater than or equal to b
//
@ -384,7 +384,7 @@ bool rat_gt( PRAT a, PRAT b, int32_t precision)
//
// FUNCTION: rat_le
//
// ARGUMENTS: PRAT a, PRAT b and long precision
// ARGUMENTS: PRAT a, PRAT b and int32_t precision
//
// RETURN: true if a is less than or equal to b
//
@ -411,7 +411,7 @@ bool rat_le( PRAT a, PRAT b, int32_t precision)
//
// FUNCTION: rat_lt
//
// ARGUMENTS: PRAT a, PRAT b and long precision
// ARGUMENTS: PRAT a, PRAT b and int32_t precision
//
// RETURN: true if a is less than b
//
@ -475,7 +475,7 @@ void scale( PRAT *px, PRAT scalefact, uint32_t radix, int32_t precision )
// Logscale is a quick way to tell how much extra precision is needed for
// scaling by scalefact.
long logscale = g_ratio * ( (pret->pp->cdigit+pret->pp->exp) -
int32_t logscale = g_ratio * ( (pret->pp->cdigit+pret->pp->exp) -
(pret->pq->cdigit+pret->pq->exp) );
if ( logscale > 0 )
{
@ -510,7 +510,7 @@ void scale2pi( PRAT *px, uint32_t radix, int32_t precision )
// Logscale is a quick way to tell how much extra precision is needed for
// scaling by 2 pi.
long logscale = g_ratio * ( (pret->pp->cdigit+pret->pp->exp) -
int32_t logscale = g_ratio * ( (pret->pp->cdigit+pret->pp->exp) -
(pret->pq->cdigit+pret->pq->exp) );
if ( logscale > 0 )
{
@ -660,7 +660,7 @@ void _readconstants( void )
//
// FUNCTION: trimit
//
// ARGUMENTS: PRAT *px, long precision
// ARGUMENTS: PRAT *px, int32_t precision
//
//
// DESCRIPTION: Chops off digits from rational numbers to avoid time
@ -681,7 +681,7 @@ void trimit( PRAT *px, int32_t precision)
{
if ( !g_ftrueinfinite )
{
long trim;
int32_t trim;
PNUMBER pp=(*px)->pp;
PNUMBER pq=(*px)->pq;
trim = g_ratio * (min((pp->cdigit+pp->exp),(pq->cdigit+pq->exp))-1) - precision;