fixed rounding on ties to round to even, and fixed extend bug (test for 0
was wrong)
This commit is contained in:
parent
1758da9285
commit
b91af798bc
2 changed files with 22 additions and 12 deletions
|
@ -63,12 +63,15 @@ dbl_over: trap(EFOVFL);
|
||||||
DBL->_s.p2 |= (f->m1 << DBL_LUNPACK); /* plus 10 == 32 */
|
DBL->_s.p2 |= (f->m1 << DBL_LUNPACK); /* plus 10 == 32 */
|
||||||
|
|
||||||
/* if not exact then round to nearest */
|
/* if not exact then round to nearest */
|
||||||
|
/* on a tie, round to even */
|
||||||
|
|
||||||
#ifdef EXCEPTION_INEXACT
|
#ifdef EXCEPTION_INEXACT
|
||||||
if ((f->m2 & DBL_EXACT) != 0) {
|
if ((f->m2 & DBL_EXACT) != 0) {
|
||||||
INEXACT();
|
INEXACT();
|
||||||
#endif
|
#endif
|
||||||
if (f->m2 & DBL_ROUNDUP) {
|
if (((f->m2 & DBL_EXACT) > DBL_ROUNDUP)
|
||||||
|
|| ((f->m2 & DBL_EXACT) == DBL_ROUNDUP
|
||||||
|
&& (f->m2 & (DBL_ROUNDUP << 1)))) {
|
||||||
DBL->_s.p2++; /* rounding up */
|
DBL->_s.p2++; /* rounding up */
|
||||||
if (DBL->_s.p2 == 0L) { /* carry out */
|
if (DBL->_s.p2 == 0L) { /* carry out */
|
||||||
DBL->_s.p1.fract++;
|
DBL->_s.p1.fract++;
|
||||||
|
@ -153,12 +156,15 @@ sgl_over: trap(EFOVFL);
|
||||||
SGL->fract = (f->m1 >> SGL_RUNPACK);
|
SGL->fract = (f->m1 >> SGL_RUNPACK);
|
||||||
|
|
||||||
/* check for rounding to nearest */
|
/* check for rounding to nearest */
|
||||||
|
/* on a tie, round to even */
|
||||||
#ifdef EXCEPTION_INEXACT
|
#ifdef EXCEPTION_INEXACT
|
||||||
if (f->m2 != 0 ||
|
if (f->m2 != 0 ||
|
||||||
(f->m1 & SGL_EXACT) != 0L) {
|
(f->m1 & SGL_EXACT) != 0L) {
|
||||||
INEXACT();
|
INEXACT();
|
||||||
#endif
|
#endif
|
||||||
if (f->m1 & SGL_ROUNDUP) {
|
if (((f->m1 & SGL_EXACT) > SGL_ROUNDUP)
|
||||||
|
|| ((f->m1 & SGL_EXACT) == SGL_ROUNDUP
|
||||||
|
&& (f->m1 & (SGL_ROUNDUP << 1)))) {
|
||||||
SGL->fract++;
|
SGL->fract++;
|
||||||
if (f->exp == 0 && (f->m1 & ~SGL_MASK)) {
|
if (f->exp == 0 && (f->m1 & ~SGL_MASK)) {
|
||||||
f->exp++;
|
f->exp++;
|
||||||
|
|
|
@ -42,16 +42,6 @@ int size;
|
||||||
int leadbit = 0;
|
int leadbit = 0;
|
||||||
|
|
||||||
cpt1 = (char *) from;
|
cpt1 = (char *) from;
|
||||||
if (((DOUBLE *) cpt1)->_s.p1.fract == 0L ||
|
|
||||||
((DOUBLE *) cpt1)->_s.p1.fract == 0x80000000) {
|
|
||||||
if (size == sizeof(SINGLE)) {
|
|
||||||
zero: zrf_ext(to);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (((DOUBLE *) cpt1)->_s.p2 == 0L)
|
|
||||||
goto zero;
|
|
||||||
}
|
|
||||||
/* there is a number to convert so lets get started */
|
|
||||||
|
|
||||||
#if FL_MSL_AT_LOW_ADDRESS
|
#if FL_MSL_AT_LOW_ADDRESS
|
||||||
#if FL_MSW_AT_LOW_ADDRESS
|
#if FL_MSW_AT_LOW_ADDRESS
|
||||||
|
@ -86,6 +76,13 @@ zero: zrf_ext(to);
|
||||||
cpt1 += 4;
|
cpt1 += 4;
|
||||||
to->m1 = get4(cpt1);
|
to->m1 = get4(cpt1);
|
||||||
#endif
|
#endif
|
||||||
|
if (to->exp == 1 && to->m1 == 0 && tmp == 0) {
|
||||||
|
to->exp = 0;
|
||||||
|
to->sign = 0;
|
||||||
|
to->m1 = 0;
|
||||||
|
to->m2 = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
to->m1 <<= DBL_M1LEFT; /* shift */
|
to->m1 <<= DBL_M1LEFT; /* shift */
|
||||||
to->exp -= DBL_BIAS; /* remove bias */
|
to->exp -= DBL_BIAS; /* remove bias */
|
||||||
to->m1 |= (tmp>>DBL_RPACK); /* plus 10 == 32 */
|
to->m1 |= (tmp>>DBL_RPACK); /* plus 10 == 32 */
|
||||||
|
@ -94,6 +91,13 @@ zero: zrf_ext(to);
|
||||||
else { /* size == sizeof(SINGLE) */
|
else { /* size == sizeof(SINGLE) */
|
||||||
to->m1 = get4(cpt1);
|
to->m1 = get4(cpt1);
|
||||||
to->m1 <<= SGL_M1LEFT; /* shift */
|
to->m1 <<= SGL_M1LEFT; /* shift */
|
||||||
|
if (to->exp == 1 && to->m1 == 0) {
|
||||||
|
to->exp = 0;
|
||||||
|
to->sign = 0;
|
||||||
|
to->m1 = 0;
|
||||||
|
to->m2 = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
to->exp -= SGL_BIAS; /* remove bias */
|
to->exp -= SGL_BIAS; /* remove bias */
|
||||||
to->m2 = 0L;
|
to->m2 = 0L;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue