mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 14:13:30 -07:00
Update implementation of basex to use the new std::vector mantissa
This commit is contained in:
parent
c09525471a
commit
fc64731c66
1 changed files with 21 additions and 19 deletions
|
@ -17,6 +17,8 @@
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "ratpak.h"
|
#include "ratpak.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
void _mulnumx( PNUMBER *pa, PNUMBER b );
|
void _mulnumx( PNUMBER *pa, PNUMBER b );
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
@ -79,20 +81,20 @@ void __inline mulnumx( PNUMBER *pa, PNUMBER b )
|
||||||
void _mulnumx( PNUMBER *pa, PNUMBER b )
|
void _mulnumx( PNUMBER *pa, PNUMBER b )
|
||||||
|
|
||||||
{
|
{
|
||||||
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 *ptra; // ptra is a pointer to the mantissa of a.
|
vector<MANTTYPE>::iterator ptra; // ptra is an iterator pointing to the mantissa of a.
|
||||||
MANTTYPE *ptrb; // ptrb is a pointer to the mantissa of b.
|
vector<MANTTYPE>::iterator ptrb; // ptrb is an iterator pointing to the mantissa of b.
|
||||||
MANTTYPE *ptrc; // ptrc is a pointer to the mantissa of c.
|
vector<MANTTYPE>::iterator ptrc; // ptrc is an iterator pointing to the mantissa of c.
|
||||||
MANTTYPE *ptrcoffset; // ptrcoffset, is the anchor location of the next
|
vector<MANTTYPE>::iterator ptrcoffset; // ptrcoffset, 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.
|
||||||
MANTTYPE da=0; // da is the digit from the fist 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
|
TWO_MANTTYPE cy=0; // cy is the carry resulting from the addition of
|
||||||
// a multiplied row into the result.
|
// a multiplied row into the result.
|
||||||
TWO_MANTTYPE mcy=0; // mcy is the resultant from a single
|
TWO_MANTTYPE mcy=0; // mcy is the resultant from a single
|
||||||
// multiply, AND the carry of that multiply.
|
// multiply, AND the carry of that multiply.
|
||||||
int32_t icdigit=0; // Index of digit being calculated in final result.
|
int32_t icdigit=0; // Index of digit being calculated in final result.
|
||||||
|
|
||||||
a=*pa;
|
a=*pa;
|
||||||
|
@ -103,13 +105,13 @@ void _mulnumx( PNUMBER *pa, PNUMBER b )
|
||||||
c->sign = a->sign * b->sign;
|
c->sign = a->sign * b->sign;
|
||||||
|
|
||||||
c->exp = a->exp + b->exp;
|
c->exp = a->exp + b->exp;
|
||||||
ptra = a->mant;
|
ptra = a->mant.begin();
|
||||||
ptrcoffset = c->mant;
|
ptrcoffset = c->mant.begin();
|
||||||
|
|
||||||
for ( iadigit = a->cdigit; iadigit > 0; iadigit-- )
|
for ( iadigit = a->cdigit; iadigit > 0; iadigit-- )
|
||||||
{
|
{
|
||||||
da = *ptra++;
|
da = *ptra++;
|
||||||
ptrb = b->mant;
|
ptrb = b->mant.begin();
|
||||||
|
|
||||||
// Shift ptrc, and ptrcoffset, one for each digit
|
// Shift ptrc, and ptrcoffset, one for each digit
|
||||||
ptrc = ptrcoffset++;
|
ptrc = ptrcoffset++;
|
||||||
|
@ -267,7 +269,7 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
|
||||||
PNUMBER tmp = nullptr; // current guess being worked on for divide.
|
PNUMBER tmp = nullptr; // current guess being worked on for divide.
|
||||||
PNUMBER rem = nullptr; // remainder after applying guess.
|
PNUMBER rem = nullptr; // remainder after applying guess.
|
||||||
int32_t 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.
|
vector<MANTTYPE>::iterator ptrc; // ptrc is an iterator pointing to the mantissa of c.
|
||||||
|
|
||||||
int32_t 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.
|
// to shoot for in the divide.
|
||||||
|
@ -292,7 +294,7 @@ void _divnumx( PNUMBER *pa, PNUMBER b, 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;
|
||||||
|
|
||||||
ptrc = c->mant + thismax;
|
ptrc = c->mant.begin() + thismax;
|
||||||
cdigits = 0;
|
cdigits = 0;
|
||||||
|
|
||||||
DUPNUM( rem, a );
|
DUPNUM( rem, a );
|
||||||
|
@ -335,9 +337,9 @@ void _divnumx( PNUMBER *pa, PNUMBER b, int32_t precision)
|
||||||
ptrc--;
|
ptrc--;
|
||||||
}
|
}
|
||||||
cdigits--;
|
cdigits--;
|
||||||
if ( c->mant != ++ptrc )
|
if ( c->mant.begin() != ++ptrc )
|
||||||
{
|
{
|
||||||
memmove( c->mant, ptrc, (int)(cdigits*sizeof(MANTTYPE)) );
|
copy(ptrc, ptrc + cdigits, c->mant.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !cdigits )
|
if ( !cdigits )
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue