Update implementation of num.cpp to use the new std::vector mantissa

This commit is contained in:
fwcd 2019-04-06 17:52:07 +02:00
commit 270905a962

View file

@ -61,11 +61,11 @@ void __inline addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix) void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
{ {
PNUMBER c= nullptr; // c will contain the result. PNUMBER c= nullptr; // c will contain the result.
PNUMBER a= nullptr; // a is the dereferenced number pointer from *pa PNUMBER a= nullptr; // a is the dereferenced number pointer from *pa
MANTTYPE *pcha; // pcha is a pointer to the mantissa of a. vector<MANTTYPE>::iterator pcha; // pcha is an iterator pointing to the mantissa of a.
MANTTYPE *pchb; // pchb is a pointer to the mantissa of b. vector<MANTTYPE>::iterator pchb; // pchb is an iterator pointing to the mantissa of b.
MANTTYPE *pchc; // pchc is a pointer to the mantissa of c. vector<MANTTYPE>::iterator pchc; // pchc is an iterator pointing to the mantissa of c.
int32_t 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.
int32_t mexp; // mexp is the exponent of the result. int32_t mexp; // mexp is the exponent of the result.
@ -87,9 +87,9 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
c->exp = min( a->exp, b->exp ); c->exp = min( a->exp, b->exp );
mexp = c->exp; mexp = c->exp;
c->cdigit = cdigits; c->cdigit = cdigits;
pcha = a->mant; pcha = a->mant.begin();
pchb = b->mant; pchb = b->mant.begin();
pchc = c->mant; pchc = c->mant.begin();
// Figure out the sign of the numbers // Figure out the sign of the numbers
if ( a->sign != b->sign ) if ( a->sign != b->sign )
@ -156,7 +156,7 @@ void _addnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
// slower on average. // slower on average.
c->sign = -1; c->sign = -1;
cy = 1; cy = 1;
for ( ( cdigits = c->cdigit ), (pchc = c->mant); for ( ( cdigits = c->cdigit ), (pchc = c->mant.begin());
cdigits > 0; cdigits > 0;
cdigits-- ) cdigits-- )
{ {
@ -219,12 +219,12 @@ void __inline mulnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
void _mulnum( PNUMBER *pa, PNUMBER b, uint32_t radix) void _mulnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
{ {
PNUMBER c= nullptr; // c will contain the result. PNUMBER c= nullptr; // c will contain the result.
PNUMBER a= nullptr; // a is the dereferenced number pointer from *pa PNUMBER a= nullptr; // a is the dereferenced number pointer from *pa
MANTTYPE *pcha; // pcha is a pointer to the mantissa of a. vector<MANTTYPE>::iterator pcha; // pcha is an iterator pointing to the mantissa of a.
MANTTYPE *pchb; // pchb is a pointer to the mantissa of b. vector<MANTTYPE>::iterator pchb; // pchb is an iterator pointing to the mantissa of b.
MANTTYPE *pchc; // pchc is a pointer to the mantissa of c. vector<MANTTYPE>::iterator pchc; // pchc is an iterator pointing to the mantissa of c.
MANTTYPE *pchcoffset; // pchcoffset, is the anchor location of the next vector<MANTTYPE>::iterator pchcoffset; // pchcoffset, is the anchor location of the next
// single digit multiply partial result. // single digit multiply partial result.
int32_t iadigit = 0; // Index of digit being used in the first 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. int32_t ibdigit = 0; // Index of digit being used in the second number.
@ -242,13 +242,13 @@ void _mulnum( PNUMBER *pa, PNUMBER b, uint32_t radix)
c->sign = a->sign * b->sign; c->sign = a->sign * b->sign;
c->exp = a->exp + b->exp; c->exp = a->exp + b->exp;
pcha = a->mant; pcha = a->mant.begin();
pchcoffset = c->mant; pchcoffset = c->mant.begin();
for ( iadigit = a->cdigit; iadigit > 0; iadigit-- ) for ( iadigit = a->cdigit; iadigit > 0; iadigit-- )
{ {
da = *pcha++; da = *pcha++;
pchb = b->mant; pchb = b->mant.begin();
// Shift pchc, and pchcoffset, one for each digit // Shift pchc, and pchcoffset, one for each digit
pchc = pchcoffset++; pchc = pchcoffset++;
@ -410,7 +410,7 @@ void _divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision)
c->exp = (a->cdigit + a->exp) - (b->cdigit + b->exp) + 1; c->exp = (a->cdigit + a->exp) - (b->cdigit + b->exp) + 1;
c->sign = a->sign * b->sign; c->sign = a->sign * b->sign;
MANTTYPE *ptrc = c->mant + thismax; vector<MANTTYPE>::iterator ptrc = c->mant.begin() + thismax;
PNUMBER rem = nullptr; PNUMBER rem = nullptr;
PNUMBER tmp = nullptr; PNUMBER tmp = nullptr;
DUPNUM(rem, a); DUPNUM(rem, a);
@ -457,9 +457,9 @@ void _divnum( PNUMBER *pa, PNUMBER b, uint32_t radix, int32_t precision)
} }
cdigits--; cdigits--;
if (c->mant != ++ptrc) if (c->mant.begin() != ++ptrc)
{ {
memmove(c->mant, ptrc, (int)(cdigits * sizeof(MANTTYPE))); copy(ptrc, c->mant.begin(), cdigits);
} }
// Cleanup table structure // Cleanup table structure
@ -506,8 +506,8 @@ bool equnum( PNUMBER a, PNUMBER b )
{ {
int32_t diff; int32_t diff;
MANTTYPE *pa; vector<MANTTYPE>::iterator pa;
MANTTYPE *pb; vector<MANTTYPE>::iterator pb;
int32_t cdigits; int32_t cdigits;
int32_t ccdigits; int32_t ccdigits;
MANTTYPE da; MANTTYPE da;
@ -529,8 +529,8 @@ bool equnum( PNUMBER a, PNUMBER b )
else else
{ {
// OK the exponents match. // OK the exponents match.
pa = a->mant; pa = a->mant.begin();
pb = b->mant; pb = b->mant.begin();
pa += a->cdigit - 1; pa += a->cdigit - 1;
pb += b->cdigit - 1; pb += b->cdigit - 1;
cdigits = max( a->cdigit, b->cdigit ); cdigits = max( a->cdigit, b->cdigit );
@ -574,8 +574,8 @@ bool lessnum( PNUMBER a, PNUMBER b )
{ {
int32_t diff; int32_t diff;
MANTTYPE *pa; vector<MANTTYPE>::iterator pa;
MANTTYPE *pb; vector<MANTTYPE>::iterator pb;
int32_t cdigits; int32_t cdigits;
int32_t ccdigits; int32_t ccdigits;
MANTTYPE da; MANTTYPE da;
@ -596,8 +596,8 @@ bool lessnum( PNUMBER a, PNUMBER b )
} }
else else
{ {
pa = a->mant; pa = a->mant.begin();
pb = b->mant; pb = b->mant.begin();
pa += a->cdigit - 1; pa += a->cdigit - 1;
pb += b->cdigit - 1; pb += b->cdigit - 1;
cdigits = max( a->cdigit, b->cdigit ); cdigits = max( a->cdigit, b->cdigit );
@ -636,9 +636,9 @@ bool zernum( PNUMBER a )
{ {
int32_t length; int32_t length;
MANTTYPE *pcha; vector<MANTTYPE>::iterator pcha;
length = a->cdigit; length = a->cdigit;
pcha = a->mant; pcha = a->mant.begin();
// loop over all the digits until you find a nonzero or until you run // loop over all the digits until you find a nonzero or until you run
// out of digits // out of digits