((prodlo >> 62) == 0x3) ) { /* normalization followed by round
* would cause carry to create
* extra bit, so don't normalize
*/
p = _Stl_HIBITULL;
return;
}
p = (prodhi<<1) | (prodlo>>63); /* normalize */
norm=1;
prodlo <<= 1;
}
else {
p = prodhi;
}
if( (prodlo & _Stl_HIBITULL) != 0 ) { /* first guard bit a one */ //*TY 03/25/2000 - added explicit comparison to zero to avoid reliance to the implicit conversion from uint64 to bool
#if !defined(__SC__) //*TY 03/25/2000 -
if( ((p & 0x1) != 0) ||
prodlo != _Stl_HIBITULL ) { /* not borderline for round to even */
#else //*TY 03/25/2000 - added workaround for SCpp compiler
bool b1 = ((p & 0x1) != 0);
if( b1 || prodlo != _Stl_HIBITULL ) { //*TY 03/25/2000 - SCpp confuses on this particular original boolean expression
#endif //*TY 03/25/2000 -
/* round */
p++;
if(p==0)
p++;
}
}
return;
}
// Convert a 64-bitb fraction * 10^exp to a 64-bit fraction * 2^bexp.
// p: 64-bit fraction
// exp: base-10 exponent
// bexp: base-2 exponent (output parameter)
void _Stl_tenscale(uint64& p, int exp, int& bexp)
{
uint64 prodhi, prodlo; /* 128b product */
int exp_hi, exp_lo; /* exp = exp_hi*32 + exp_lo */
int hi, lo, tlo, thi; /* offsets in power of ten table */
int norm; /* number of bits of normalization */
int num_hi; /* number of high exponent powers */
bexp = 0;
if(exp > 0) { /* split exponent */
exp_lo = exp;
exp_hi = 0;
if(exp_lo>27) {
exp_lo++;
while(exp_lo>27) {
exp_hi++;
exp_lo-=28;
}
}
tlo = TEN_1;
thi = TEN_27;
num_hi = NUM_HI_P;
}
else if(exp < 0) {
exp_lo = exp;
exp_hi = 0;
while(exp_lo<0) {
exp_hi++;
exp_lo+=28;
}
tlo = TEN_1;
thi = TEN_M28;
num_hi = NUM_HI_N;
}
else { /* no scaling needed */
return;
}
while(exp_hi) { /* scale */
hi = (min) (exp_hi,num_hi); /* only a few large powers of 10 */
exp_hi -= hi; /* could iterate in extreme case */
hi += thi-1;
_Stl_mult64(p, _Stl_tenpow[hi], prodhi, prodlo);
_Stl_norm_and_round(p, norm, prodhi, prodlo);
bexp += _Stl_twoexp[hi] - norm;
}
if(exp_lo) {
lo = tlo + exp_lo -1;
_Stl_mult64(p, _Stl_tenpow[lo], prodhi, prodlo);
_Stl_norm_and_round(p, norm, prodhi, prodlo);
bexp += _Stl_twoexp[lo] - norm;
}
return;
}
// First argument is a buffer of values from 0 to 9, NOT ascii.
// Second argument is number of digits in buffer, 1 <= digits <= 17.
// Third argument is base-10 exponent.
#if defined(__SC__) || defined(__MRC__)
//*TY 04/06/2000 - powermac's 68K emulator utilizes apple's SANE floating point, which is not compatible with IEEE format.
_STLP_END_NAMESPACE
# include <fp.h>
_STLP_BEGIN_NAMESPACE
inline double _Stl_atod(char *buffer, int ndigit, int dexp)
{
decimal d; // ref. inside macintosh powerpc numerics p.9-13
d.sgn = 0;
d.exp = dexp;
d.sig.length = ndigit;
for( int i = 0; i < ndigit; ++i )
{
d.sig.text[i] = buffer[i] + '0';
}
return dec2num( &d );
}
#else /* IEEE representation */
#if 0 // def __ICL
// turn off optimization here
# pragma optimize "off"
#endif
double _Stl_atod(char *buffer, int ndigit, int dexp)
{
uint64 value; /* Value develops as follows:
* 1) decimal digits as an integer
* 2) left adjusted fraction
* 3) right adjusted fraction
* 4) exponent and fraction
*/
uint32 guard; /* First guard bit */
uint64 rest; /* Remaining guard bits */
int bexp; /* binary exponent */
int nzero; /* number of non-zero bits */
int sexp; /* scaling exponent */
char *bufferend; /* pointer to char after last digit */
/* Check for zero and treat it as a special case */
if (buffer == 0){
return 0.0;
}
/* Convert the decimal digits to a binary integer. */
bufferend = buffer + ndigit;
value = 0;
while( buffer < bufferend ) {
value *= 10;
value += *buffer++;
}
/* Check for zero and treat it as a special case */
if (value == 0){
return 0.0;
}
/* Normalize value */
bexp = 64; /* convert from 64b int to fraction */
/* Count number of non-zeroes in value */
nzero = 0;
if ( (value >> 32) !=0 ){ nzero = 32; } //*TY 03/25/2000 - added explicit comparison to zero to avoid uint64 to bool conversion operator