From 556da247bae2d967151cbfb059c633c14c007885 Mon Sep 17 00:00:00 2001 From: fwcd Date: Sat, 6 Apr 2019 17:45:58 +0200 Subject: [PATCH] Update implementation of conv.cpp and ratpack.h to use the new std::vector mantissa --- src/CalcManager/Ratpack/conv.cpp | 22 +++++++++++----------- src/CalcManager/Ratpack/ratpak.h | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/CalcManager/Ratpack/conv.cpp b/src/CalcManager/Ratpack/conv.cpp index c25d4481..10f67c17 100644 --- a/src/CalcManager/Ratpack/conv.cpp +++ b/src/CalcManager/Ratpack/conv.cpp @@ -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 num_radix = i32tonum(radix, BASEX); - MANTTYPE *ptrdigit = a->mant; // pointer to digit being worked on. + vector::iterator ptrdigit = a->mant.begin(); // iterator pointing to digit being worked on. // Digits are in reverse order, back over them LSD first. ptrdigit += a->cdigit-1; @@ -657,7 +657,7 @@ PNUMBER StringToNumber(wstring_view numberString, uint32_t radix, int32_t precis pnumret->sign = 1L; pnumret->cdigit = 0; pnumret->exp = 0; - MANTTYPE *pmant = pnumret->mant + numberString.length() - 1; + vector::iterator pmant = pnumret->mant.begin() + numberString.length() - 1; uint8_t state = START; // state is the state of the input state machine. wchar_t curChar; @@ -842,11 +842,11 @@ PRAT Ui32torat( _In_ uint32_t inui32 ) PNUMBER i32tonum( int32_t ini32, uint32_t radix) { - MANTTYPE *pmant; + vector::iterator pmant; PNUMBER pnumret= nullptr; createnum( pnumret, MAX_LONG_SIZE ); - pmant = pnumret->mant; + pmant = pnumret->mant.begin(); pnumret->cdigit = 0; pnumret->exp = 0; if ( ini32 < 0 ) @@ -885,11 +885,11 @@ PNUMBER i32tonum( int32_t ini32, uint32_t radix) PNUMBER Ui32tonum(uint32_t ini32, uint32_t radix) { - MANTTYPE *pmant; + vector::iterator pmant; PNUMBER pnumret= nullptr; createnum( pnumret, MAX_LONG_SIZE ); - pmant = pnumret->mant; + pmant = pnumret->mant.begin(); pnumret->cdigit = 0; pnumret->exp = 0; pnumret->sign = 1; @@ -1030,7 +1030,7 @@ int32_t numtoi32( _In_ PNUMBER pnum, uint32_t radix ) { int32_t lret = 0; - MANTTYPE *pmant = pnum->mant; + vector::iterator pmant = pnum->mant.begin(); pmant += pnum->cdigit - 1; 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) { - MANTTYPE *pmant; + vector::iterator pmant; int32_t cdigits; bool fstrip = false; // point pmant to the LeastCalculatedDigit - pmant=pnum->mant; + pmant=pnum->mant.begin(); cdigits=pnum->cdigit; // point pmant to the LSD if ( cdigits > starting ) @@ -1091,7 +1091,7 @@ bool stripzeroesnum(_Inout_ PNUMBER pnum, int32_t starting) if ( fstrip ) { // Remove them. - memmove( pnum->mant, pmant, (int)(cdigits*sizeof(MANTTYPE)) ); + copy(pmant, pnum->mant.begin(), cdigits); // And adjust exponent and digit count accordingly. pnum->exp += ( 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. bool useSciForm = false; int32_t eout = exponent - 1; // Displayed exponent. - MANTTYPE *pmant = pnum->mant + pnum->cdigit - 1; + vector::iterator pmant = pnum->mant.begin() + pnum->cdigit - 1; // Case where too many digits are to the left of the decimal or // FMT_SCIENTIFIC or FMT_ENGINEERING was specified. if ((format == FMT_SCIENTIFIC) || (format == FMT_ENGINEERING)) diff --git a/src/CalcManager/Ratpack/ratpak.h b/src/CalcManager/Ratpack/ratpak.h index c3d98bb1..bc627376 100644 --- a/src/CalcManager/Ratpack/ratpak.h +++ b/src/CalcManager/Ratpack/ratpak.h @@ -211,7 +211,7 @@ _destroynum(x),(x)=nullptr int32_t trim = (x)->cdigit - precision-g_ratio;\ 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)->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;\ 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->exp += trim; \ } \