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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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