avoid use of modf; not portable

This commit is contained in:
ceriel 1988-04-22 14:11:55 +00:00
parent b948e4b59d
commit b68e30f6ff
8 changed files with 134 additions and 68 deletions

View file

@ -64,8 +64,7 @@ con_float() {
double atof(); double atof();
int i; int i;
#ifndef OWNFLOAT #ifndef OWNFLOAT
double f1; double frexp();
double frexp(), modf();
int j; int j;
int sign = 0; int sign = 0;
int fraction[4] ; int fraction[4] ;
@ -107,15 +106,18 @@ con_float() {
f += f; f += f;
i --; i --;
} }
f = modf(2 * f, &f1); /* hidden bit */ f = 2*f - 1.0; /* hidden bit */
#ifdef IEEEFLOAT #ifdef IEEEFLOAT
if (argval == 4) { if (argval == 4) {
#endif IEEEFLOAT #endif IEEEFLOAT
i = (i + 128) & 0377; i = (i + 128) & 0377;
fraction[0] = (sign << 15) | (i << 7); fraction[0] = (sign << 15) | (i << 7);
for (j = 6; j>= 0; j--) { for (j = 6; j>= 0; j--) {
if (f >= 0.5) fraction[0] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
f -= 1.0;
fraction[0] |= (1 << j);
}
} }
#ifdef IEEEFLOAT #ifdef IEEEFLOAT
} }
@ -123,16 +125,22 @@ con_float() {
i = (i + 1024) & 03777; i = (i + 1024) & 03777;
fraction[0] = (sign << 15) | (i << 4); fraction[0] = (sign << 15) | (i << 4);
for (j = 3; j>= 0; j--) { for (j = 3; j>= 0; j--) {
if (f >= 0.5) fraction[0] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
fraction[0] |= (1 << j);
f -= 1.0;
}
} }
} }
#endif IEEEFLOAT #endif IEEEFLOAT
for (i = 1; i < argval / 2; i++) { for (i = 1; i < argval / 2; i++) {
fraction[i] = 0; fraction[i] = 0;
for (j = 15; j>= 0; j--) { for (j = 15; j>= 0; j--) {
if (f >= 0.5) fraction[i] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
fraction[i] |= (1 << j);
f -= 1.0;
}
} }
} }
if (f >= 0.5) { if (f >= 0.5) {
@ -159,6 +167,7 @@ con_float() {
putc('\n', codefile); putc('\n', codefile);
} }
#endif #endif
/* /*
string holstr(n) word n; { string holstr(n) word n; {

View file

@ -63,8 +63,7 @@ con_float() {
double atof(); double atof();
int i; int i;
#ifndef OWNFLOAT #ifndef OWNFLOAT
double f1; double frexp();
double frexp(), modf();
int j; int j;
int sign = 0; int sign = 0;
int fraction[4] ; int fraction[4] ;
@ -106,15 +105,18 @@ con_float() {
f += f; f += f;
i --; i --;
} }
f = modf(2 * f, &f1); /* hidden bit */ f = 2*f - 1.0; /* hidden bit */
#ifdef IEEEFLOAT #ifdef IEEEFLOAT
if (argval == 4) { if (argval == 4) {
#endif IEEEFLOAT #endif IEEEFLOAT
i = (i + 128) & 0377; i = (i + 128) & 0377;
fraction[0] = (sign << 15) | (i << 7); fraction[0] = (sign << 15) | (i << 7);
for (j = 6; j>= 0; j--) { for (j = 6; j>= 0; j--) {
if (f >= 0.5) fraction[0] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
f -= 1.0;
fraction[0] |= (1 << j);
}
} }
#ifdef IEEEFLOAT #ifdef IEEEFLOAT
} }
@ -122,16 +124,22 @@ con_float() {
i = (i + 1024) & 03777; i = (i + 1024) & 03777;
fraction[0] = (sign << 15) | (i << 4); fraction[0] = (sign << 15) | (i << 4);
for (j = 3; j>= 0; j--) { for (j = 3; j>= 0; j--) {
if (f >= 0.5) fraction[0] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
fraction[0] |= (1 << j);
f -= 1.0;
}
} }
} }
#endif IEEEFLOAT #endif IEEEFLOAT
for (i = 1; i < argval / 2; i++) { for (i = 1; i < argval / 2; i++) {
fraction[i] = 0; fraction[i] = 0;
for (j = 15; j>= 0; j--) { for (j = 15; j>= 0; j--) {
if (f >= 0.5) fraction[i] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
fraction[i] |= (1 << j);
f -= 1.0;
}
} }
} }
if (f >= 0.5) { if (f >= 0.5) {

View file

@ -62,8 +62,7 @@ con_float() {
double atof(); double atof();
int i; int i;
#ifndef OWNFLOAT #ifndef OWNFLOAT
double f1; double frexp();
double frexp(), modf();
int j; int j;
int sign = 0; int sign = 0;
int fraction[4] ; int fraction[4] ;
@ -105,15 +104,18 @@ con_float() {
f += f; f += f;
i --; i --;
} }
f = modf(2 * f, &f1); /* hidden bit */ f = 2*f - 1.0; /* hidden bit */
#ifdef IEEEFLOAT #ifdef IEEEFLOAT
if (argval == 4) { if (argval == 4) {
#endif IEEEFLOAT #endif IEEEFLOAT
i = (i + 128) & 0377; i = (i + 128) & 0377;
fraction[0] = (sign << 15) | (i << 7); fraction[0] = (sign << 15) | (i << 7);
for (j = 6; j>= 0; j--) { for (j = 6; j>= 0; j--) {
if (f >= 0.5) fraction[0] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
f -= 1.0;
fraction[0] |= (1 << j);
}
} }
#ifdef IEEEFLOAT #ifdef IEEEFLOAT
} }
@ -121,16 +123,22 @@ con_float() {
i = (i + 1024) & 03777; i = (i + 1024) & 03777;
fraction[0] = (sign << 15) | (i << 4); fraction[0] = (sign << 15) | (i << 4);
for (j = 3; j>= 0; j--) { for (j = 3; j>= 0; j--) {
if (f >= 0.5) fraction[0] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
fraction[0] |= (1 << j);
f -= 1.0;
}
} }
} }
#endif IEEEFLOAT #endif IEEEFLOAT
for (i = 1; i < argval / 2; i++) { for (i = 1; i < argval / 2; i++) {
fraction[i] = 0; fraction[i] = 0;
for (j = 15; j>= 0; j--) { for (j = 15; j>= 0; j--) {
if (f >= 0.5) fraction[i] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
fraction[i] |= (1 << j);
f -= 1.0;
}
} }
} }
if (f >= 0.5) { if (f >= 0.5) {

View file

@ -63,8 +63,7 @@ con_float() {
double atof(); double atof();
int i; int i;
#ifndef OWNFLOAT #ifndef OWNFLOAT
double f1; double frexp();
double frexp(), modf();
int j; int j;
int sign = 0; int sign = 0;
int fraction[4] ; int fraction[4] ;
@ -106,15 +105,18 @@ con_float() {
f += f; f += f;
i --; i --;
} }
f = modf(2 * f, &f1); /* hidden bit */ f = 2*f - 1.0; /* hidden bit */
#ifdef IEEEFLOAT #ifdef IEEEFLOAT
if (argval == 4) { if (argval == 4) {
#endif IEEEFLOAT #endif IEEEFLOAT
i = (i + 128) & 0377; i = (i + 128) & 0377;
fraction[0] = (sign << 15) | (i << 7); fraction[0] = (sign << 15) | (i << 7);
for (j = 6; j>= 0; j--) { for (j = 6; j>= 0; j--) {
if (f >= 0.5) fraction[0] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
f -= 1.0;
fraction[0] |= (1 << j);
}
} }
#ifdef IEEEFLOAT #ifdef IEEEFLOAT
} }
@ -122,16 +124,22 @@ con_float() {
i = (i + 1024) & 03777; i = (i + 1024) & 03777;
fraction[0] = (sign << 15) | (i << 4); fraction[0] = (sign << 15) | (i << 4);
for (j = 3; j>= 0; j--) { for (j = 3; j>= 0; j--) {
if (f >= 0.5) fraction[0] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
fraction[0] |= (1 << j);
f -= 1.0;
}
} }
} }
#endif IEEEFLOAT #endif IEEEFLOAT
for (i = 1; i < argval / 2; i++) { for (i = 1; i < argval / 2; i++) {
fraction[i] = 0; fraction[i] = 0;
for (j = 15; j>= 0; j--) { for (j = 15; j>= 0; j--) {
if (f >= 0.5) fraction[i] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
fraction[i] |= (1 << j);
f -= 1.0;
}
} }
} }
if (f >= 0.5) { if (f >= 0.5) {

View file

@ -63,8 +63,7 @@ con_float() {
double atof(); double atof();
int i; int i;
#ifndef OWNFLOAT #ifndef OWNFLOAT
double f1; double frexp();
double frexp(), modf();
int j; int j;
int sign = 0; int sign = 0;
int fraction[4] ; int fraction[4] ;
@ -106,15 +105,18 @@ con_float() {
f += f; f += f;
i --; i --;
} }
f = modf(2 * f, &f1); /* hidden bit */ f = 2*f - 1.0; /* hidden bit */
#ifdef IEEEFLOAT #ifdef IEEEFLOAT
if (argval == 4) { if (argval == 4) {
#endif IEEEFLOAT #endif IEEEFLOAT
i = (i + 128) & 0377; i = (i + 128) & 0377;
fraction[0] = (sign << 15) | (i << 7); fraction[0] = (sign << 15) | (i << 7);
for (j = 6; j>= 0; j--) { for (j = 6; j>= 0; j--) {
if (f >= 0.5) fraction[0] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
f -= 1.0;
fraction[0] |= (1 << j);
}
} }
#ifdef IEEEFLOAT #ifdef IEEEFLOAT
} }
@ -122,16 +124,22 @@ con_float() {
i = (i + 1024) & 03777; i = (i + 1024) & 03777;
fraction[0] = (sign << 15) | (i << 4); fraction[0] = (sign << 15) | (i << 4);
for (j = 3; j>= 0; j--) { for (j = 3; j>= 0; j--) {
if (f >= 0.5) fraction[0] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
fraction[0] |= (1 << j);
f -= 1.0;
}
} }
} }
#endif IEEEFLOAT #endif IEEEFLOAT
for (i = 1; i < argval / 2; i++) { for (i = 1; i < argval / 2; i++) {
fraction[i] = 0; fraction[i] = 0;
for (j = 15; j>= 0; j--) { for (j = 15; j>= 0; j--) {
if (f >= 0.5) fraction[i] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
fraction[i] |= (1 << j);
f -= 1.0;
}
} }
} }
if (f >= 0.5) { if (f >= 0.5) {

View file

@ -63,8 +63,7 @@ con_float() {
double atof(); double atof();
int i; int i;
#ifndef OWNFLOAT #ifndef OWNFLOAT
double f1; double frexp();
double frexp(), modf();
int j; int j;
int sign = 0; int sign = 0;
int fraction[4] ; int fraction[4] ;
@ -106,15 +105,18 @@ con_float() {
f += f; f += f;
i --; i --;
} }
f = modf(2 * f, &f1); /* hidden bit */ f = 2*f - 1.0; /* hidden bit */
#ifdef IEEEFLOAT #ifdef IEEEFLOAT
if (argval == 4) { if (argval == 4) {
#endif IEEEFLOAT #endif IEEEFLOAT
i = (i + 128) & 0377; i = (i + 128) & 0377;
fraction[0] = (sign << 15) | (i << 7); fraction[0] = (sign << 15) | (i << 7);
for (j = 6; j>= 0; j--) { for (j = 6; j>= 0; j--) {
if (f >= 0.5) fraction[0] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
f -= 1.0;
fraction[0] |= (1 << j);
}
} }
#ifdef IEEEFLOAT #ifdef IEEEFLOAT
} }
@ -122,16 +124,22 @@ con_float() {
i = (i + 1024) & 03777; i = (i + 1024) & 03777;
fraction[0] = (sign << 15) | (i << 4); fraction[0] = (sign << 15) | (i << 4);
for (j = 3; j>= 0; j--) { for (j = 3; j>= 0; j--) {
if (f >= 0.5) fraction[0] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
fraction[0] |= (1 << j);
f -= 1.0;
}
} }
} }
#endif IEEEFLOAT #endif IEEEFLOAT
for (i = 1; i < argval / 2; i++) { for (i = 1; i < argval / 2; i++) {
fraction[i] = 0; fraction[i] = 0;
for (j = 15; j>= 0; j--) { for (j = 15; j>= 0; j--) {
if (f >= 0.5) fraction[i] |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
fraction[i] |= (1 << j);
f -= 1.0;
}
} }
} }
if (f >= 0.5) { if (f >= 0.5) {

View file

@ -54,8 +54,8 @@ con_mult(sz) word sz; {
con_float() { con_float() {
#ifdef ACK_ASS #ifdef ACK_ASS
double f, f1; double f;
double atof(), frexp(), modf(); double atof(), frexp();
int i, j; int i, j;
int sign = 0; int sign = 0;
int fraction ; int fraction ;
@ -77,19 +77,25 @@ con_float() {
f += f; f += f;
i --; i --;
} }
f = modf(2 * f, &f1); /* hidden bit */ f = 2*f - 1.0; /* hidden bit */
i = (i + 128) & 0377; i = (i + 128) & 0377;
fraction = (sign << 15) | (i << 7); fraction = (sign << 15) | (i << 7);
for (j = 6; j>= 0; j--) { for (j = 6; j>= 0; j--) {
if (f >= 0.5) fraction |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
fraction |= (1 << j);
f -= 1.0;
}
} }
fprintf(codefile, ".data2 0%o", fraction); fprintf(codefile, ".data2 0%o", fraction);
for (i = argval / 2 - 1; i; i--) { for (i = argval / 2 - 1; i; i--) {
fraction = 0; fraction = 0;
for (j = 15; j>= 0; j--) { for (j = 15; j>= 0; j--) {
if (f >= 0.5) fraction |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
fraction |= (1 << j);
f -= 1.0;
}
} }
fprintf(codefile, ", 0%o", fraction); fprintf(codefile, ", 0%o", fraction);
} }

View file

@ -54,8 +54,8 @@ con_mult(sz) word sz; {
con_float() { con_float() {
#ifdef ACK_ASS #ifdef ACK_ASS
double f, f1; double f;
double atof(), frexp(), modf(); double atof(), frexp();
int i, j; int i, j;
int sign = 0; int sign = 0;
int fraction ; int fraction ;
@ -63,6 +63,11 @@ con_float() {
if (argval != 4 && argval != 8) if (argval != 4 && argval != 8)
fatal("bad fcon size"); fatal("bad fcon size");
f = atof(str); f = atof(str);
if (f == 0) {
if (argval == 8) fprintf(codefile, ".data2 0, 0\n");
fprintf(codefile, ".data2 0, 0\n");
return;
}
f = frexp(f, &i); f = frexp(f, &i);
if (f < 0) { if (f < 0) {
f = -f; f = -f;
@ -72,19 +77,25 @@ con_float() {
f += f; f += f;
i --; i --;
} }
f = modf(2 * f, &f1); /* hidden bit */ f = 2*f - 1.0; /* hidden bit */
i = (i + 128) & 0377; i = (i + 128) & 0377;
fraction = (sign << 15) | (i << 7); fraction = (sign << 15) | (i << 7);
for (j = 6; j>= 0; j--) { for (j = 6; j>= 0; j--) {
if (f >= 0.5) fraction |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
fraction |= (1 << j);
f -= 1.0;
}
} }
fprintf(codefile, ".data2 0%o", fraction); fprintf(codefile, ".data2 0%o", fraction);
for (i = argval / 2 - 1; i; i--) { for (i = argval / 2 - 1; i; i--) {
fraction = 0; fraction = 0;
for (j = 15; j>= 0; j--) { for (j = 15; j>= 0; j--) {
if (f >= 0.5) fraction |= (1 << j); f *= 2;
f = modf(2*f, &f1); if (f >= 1.0) {
fraction |= (1 << j);
f -= 1.0;
}
} }
fprintf(codefile, ", 0%o", fraction); fprintf(codefile, ", 0%o", fraction);
} }