From 45cc974257864286d71ae4ff9846e32d70d730e2 Mon Sep 17 00:00:00 2001 From: fwcd Date: Sat, 6 Apr 2019 22:22:04 +0200 Subject: [PATCH] Use vector.end and pre-increment in lessnum (num.cpp) and numtonRadixx (conv.cpp) --- src/CalcManager/Ratpack/conv.cpp | 7 +++---- src/CalcManager/Ratpack/num.cpp | 10 ++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/CalcManager/Ratpack/conv.cpp b/src/CalcManager/Ratpack/conv.cpp index 031e6e44..c0d6a6cb 100644 --- a/src/CalcManager/Ratpack/conv.cpp +++ b/src/CalcManager/Ratpack/conv.cpp @@ -377,10 +377,9 @@ 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); - 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; + vector::iterator ptrdigit = a->mant.end(); // iterator pointing to digit being worked on. PNUMBER thisdigit = nullptr; // thisdigit holds the current digit of a // being summed into result. @@ -391,7 +390,7 @@ PNUMBER numtonRadixx(_In_ PNUMBER a, uint32_t radix) // WARNING: // This should just smack in each digit into a 'special' thisdigit. // and not do the overhead of recreating the number type each time. - thisdigit = i32tonum( *ptrdigit--, BASEX ); + thisdigit = i32tonum( *(--ptrdigit), BASEX ); addnum( &pnumret, thisdigit, BASEX ); destroynum( thisdigit ); } diff --git a/src/CalcManager/Ratpack/num.cpp b/src/CalcManager/Ratpack/num.cpp index d56757fe..1db8d869 100644 --- a/src/CalcManager/Ratpack/num.cpp +++ b/src/CalcManager/Ratpack/num.cpp @@ -596,18 +596,16 @@ bool lessnum( PNUMBER a, PNUMBER b ) } else { - pa = a->mant.begin(); - pb = b->mant.begin(); - pa += a->cdigit - 1; - pb += b->cdigit - 1; + pa = a->mant.end(); + pb = b->mant.end(); cdigits = max( a->cdigit, b->cdigit ); ccdigits = cdigits; for ( ;cdigits > 0; cdigits-- ) { da = ( (cdigits > (ccdigits - a->cdigit) ) ? - *pa-- : 0 ); + *(--pa) : 0 ); db = ( (cdigits > (ccdigits - b->cdigit) ) ? - *pb-- : 0 ); + *(--pb) : 0 ); diff = da-db; if ( diff ) {