mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 14:13:30 -07:00
Update implementation of conv.cpp and ratpack.h to use the new std::vector mantissa
This commit is contained in:
parent
fc64731c66
commit
556da247ba
2 changed files with 13 additions and 13 deletions
|
@ -380,7 +380,7 @@ PNUMBER numtonRadixx(_In_ PNUMBER a, uint32_t radix)
|
||||||
{
|
{
|
||||||
PNUMBER pnumret = i32tonum(0, BASEX); // pnumret is the number in internal form.
|
PNUMBER pnumret = i32tonum(0, BASEX); // pnumret is the number in internal form.
|
||||||
PNUMBER num_radix = i32tonum(radix, BASEX);
|
PNUMBER num_radix = i32tonum(radix, BASEX);
|
||||||
MANTTYPE *ptrdigit = a->mant; // pointer to digit being worked on.
|
vector<MANTTYPE>::iterator ptrdigit = a->mant.begin(); // iterator pointing to digit being worked on.
|
||||||
|
|
||||||
// Digits are in reverse order, back over them LSD first.
|
// Digits are in reverse order, back over them LSD first.
|
||||||
ptrdigit += a->cdigit-1;
|
ptrdigit += a->cdigit-1;
|
||||||
|
@ -657,7 +657,7 @@ PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precis
|
||||||
pnumret->sign = 1L;
|
pnumret->sign = 1L;
|
||||||
pnumret->cdigit = 0;
|
pnumret->cdigit = 0;
|
||||||
pnumret->exp = 0;
|
pnumret->exp = 0;
|
||||||
MANTTYPE *pmant = pnumret->mant + numberString.length() - 1;
|
vector<MANTTYPE>::iterator pmant = pnumret->mant.begin() + numberString.length() - 1;
|
||||||
|
|
||||||
uint8_t state = START; // state is the state of the input state machine.
|
uint8_t state = START; // state is the state of the input state machine.
|
||||||
wchar_t curChar;
|
wchar_t curChar;
|
||||||
|
@ -842,11 +842,11 @@ PRAT Ui32torat( _In_ uint32_t inui32 )
|
||||||
PNUMBER i32tonum( int32_t ini32, uint32_t radix)
|
PNUMBER i32tonum( int32_t ini32, uint32_t radix)
|
||||||
|
|
||||||
{
|
{
|
||||||
MANTTYPE *pmant;
|
vector<MANTTYPE>::iterator pmant;
|
||||||
PNUMBER pnumret= nullptr;
|
PNUMBER pnumret= nullptr;
|
||||||
|
|
||||||
createnum( pnumret, MAX_LONG_SIZE );
|
createnum( pnumret, MAX_LONG_SIZE );
|
||||||
pmant = pnumret->mant;
|
pmant = pnumret->mant.begin();
|
||||||
pnumret->cdigit = 0;
|
pnumret->cdigit = 0;
|
||||||
pnumret->exp = 0;
|
pnumret->exp = 0;
|
||||||
if ( ini32 < 0 )
|
if ( ini32 < 0 )
|
||||||
|
@ -885,11 +885,11 @@ PNUMBER i32tonum( int32_t ini32, uint32_t radix)
|
||||||
|
|
||||||
PNUMBER Ui32tonum(uint32_t ini32, uint32_t radix)
|
PNUMBER Ui32tonum(uint32_t ini32, uint32_t radix)
|
||||||
{
|
{
|
||||||
MANTTYPE *pmant;
|
vector<MANTTYPE>::iterator pmant;
|
||||||
PNUMBER pnumret= nullptr;
|
PNUMBER pnumret= nullptr;
|
||||||
|
|
||||||
createnum( pnumret, MAX_LONG_SIZE );
|
createnum( pnumret, MAX_LONG_SIZE );
|
||||||
pmant = pnumret->mant;
|
pmant = pnumret->mant.begin();
|
||||||
pnumret->cdigit = 0;
|
pnumret->cdigit = 0;
|
||||||
pnumret->exp = 0;
|
pnumret->exp = 0;
|
||||||
pnumret->sign = 1;
|
pnumret->sign = 1;
|
||||||
|
@ -1030,7 +1030,7 @@ int32_t numtoi32( _In_ PNUMBER pnum, uint32_t radix )
|
||||||
{
|
{
|
||||||
int32_t lret = 0;
|
int32_t lret = 0;
|
||||||
|
|
||||||
MANTTYPE *pmant = pnum->mant;
|
vector<MANTTYPE>::iterator pmant = pnum->mant.begin();
|
||||||
pmant += pnum->cdigit - 1;
|
pmant += pnum->cdigit - 1;
|
||||||
|
|
||||||
int32_t expt = pnum->exp;
|
int32_t expt = pnum->exp;
|
||||||
|
@ -1063,12 +1063,12 @@ int32_t numtoi32( _In_ PNUMBER pnum, uint32_t radix )
|
||||||
|
|
||||||
bool stripzeroesnum(_Inout_ PNUMBER pnum, int32_t starting)
|
bool stripzeroesnum(_Inout_ PNUMBER pnum, int32_t starting)
|
||||||
{
|
{
|
||||||
MANTTYPE *pmant;
|
vector<MANTTYPE>::iterator pmant;
|
||||||
int32_t cdigits;
|
int32_t cdigits;
|
||||||
bool fstrip = false;
|
bool fstrip = false;
|
||||||
|
|
||||||
// point pmant to the LeastCalculatedDigit
|
// point pmant to the LeastCalculatedDigit
|
||||||
pmant=pnum->mant;
|
pmant=pnum->mant.begin();
|
||||||
cdigits=pnum->cdigit;
|
cdigits=pnum->cdigit;
|
||||||
// point pmant to the LSD
|
// point pmant to the LSD
|
||||||
if ( cdigits > starting )
|
if ( cdigits > starting )
|
||||||
|
@ -1091,7 +1091,7 @@ bool stripzeroesnum(_Inout_ PNUMBER pnum, int32_t starting)
|
||||||
if ( fstrip )
|
if ( fstrip )
|
||||||
{
|
{
|
||||||
// Remove them.
|
// Remove them.
|
||||||
memmove( pnum->mant, pmant, (int)(cdigits*sizeof(MANTTYPE)) );
|
copy(pmant, pnum->mant.begin(), cdigits);
|
||||||
// And adjust exponent and digit count accordingly.
|
// And adjust exponent and digit count accordingly.
|
||||||
pnum->exp += ( pnum->cdigit - cdigits );
|
pnum->exp += ( pnum->cdigit - cdigits );
|
||||||
pnum->cdigit = cdigits;
|
pnum->cdigit = cdigits;
|
||||||
|
@ -1202,7 +1202,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;
|
||||||
int32_t eout = exponent - 1; // Displayed exponent.
|
int32_t eout = exponent - 1; // Displayed exponent.
|
||||||
MANTTYPE *pmant = pnum->mant + pnum->cdigit - 1;
|
vector<MANTTYPE>::iterator pmant = pnum->mant.begin() + 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.
|
||||||
if ((format == FMT_SCIENTIFIC) || (format == FMT_ENGINEERING))
|
if ((format == FMT_SCIENTIFIC) || (format == FMT_ENGINEERING))
|
||||||
|
|
|
@ -211,7 +211,7 @@ _destroynum(x),(x)=nullptr
|
||||||
int32_t 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) ); \
|
std::copy(&((x)->mant.begin() + trim), (x)->mant.begin(), (x)->cdigit-trim);\
|
||||||
(x)->cdigit -= trim; \
|
(x)->cdigit -= trim; \
|
||||||
(x)->exp += trim; \
|
(x)->exp += trim; \
|
||||||
} \
|
} \
|
||||||
|
@ -221,7 +221,7 @@ memmove( (x)->mant, &((x)->mant[trim]), sizeof(MANTTYPE)*((x)->cdigit-trim) ); \
|
||||||
int32_t 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) ); \
|
std::copy(&((x)->pp->mant[trim]), (x)->pp->mant, ((x)->pp->cdigit-trim)); \
|
||||||
(x)->pp->cdigit -= trim; \
|
(x)->pp->cdigit -= trim; \
|
||||||
(x)->pp->exp += trim; \
|
(x)->pp->exp += trim; \
|
||||||
} \
|
} \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue