mirror of
https://github.com/SEPPDROID/Digital-Research-Source-Code.git
synced 2025-10-24 17:04:19 +00:00
Upload
Digital Research
This commit is contained in:
BIN
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/al40/fp/libE.a
Normal file
BIN
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/al40/fp/libE.a
Normal file
Binary file not shown.
@@ -0,0 +1,12 @@
|
||||
c68 -c -L -e atof.c
|
||||
c68 -c -L -e ceil.c
|
||||
c68 -c -L -e etoa.c
|
||||
c68 -c -L -e fabs.c
|
||||
c68 -c -L -e floor.c
|
||||
c68 -c -L -e fmod.c
|
||||
c68 -c -L -e fprintf.c
|
||||
c68 -c -L -e ftoa.c
|
||||
c68 -c -L -e ftol.c
|
||||
c68 -c -L -e ieeetof.c
|
||||
c68 -c -L -e ltof.c
|
||||
c68 -c -L -e printf.c
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) atof - dec 29, 1982"; */
|
||||
|
||||
/*
|
||||
* Ascii String to IEEE Floating Point Routine :
|
||||
* IEEE Standard Single Precision Representation Floating Point
|
||||
*
|
||||
* float
|
||||
* atof(buf)
|
||||
* char *buf;
|
||||
*
|
||||
* No more than 9 significant digits are allowed in single precision.
|
||||
* Largest positive number is 3.4 * 10^33 and the smallest positive
|
||||
* number is 1.2 * 10^-38.
|
||||
* Rely's on the fact that a long and a float are both 32 bits.
|
||||
*/
|
||||
|
||||
#define BIAS 127L
|
||||
#define EXPSIZ 4
|
||||
#define FRACSIZ 20
|
||||
|
||||
long fptoieee();
|
||||
float strbin();
|
||||
float power10();
|
||||
|
||||
long
|
||||
atof(buf)
|
||||
char *buf;
|
||||
{
|
||||
char ibuf[FRACSIZ], ebuf[EXPSIZ];
|
||||
register char *ip, *ep;
|
||||
long ieee; /* return value */
|
||||
int dp, esign, isign, ebin, places;
|
||||
float ibin, fp;
|
||||
|
||||
ip = &ibuf; ep = &ebuf; dp = 0; places = 0L;
|
||||
while (*buf == ' ' || *buf == '\t') /* ignore white spaces */
|
||||
buf++;
|
||||
isign = (*buf == '-');
|
||||
if (*buf == '-' || *buf == '+')
|
||||
buf++;
|
||||
while (*buf && *buf != 'e' && *buf != 'E') {
|
||||
if (*buf == '.')
|
||||
dp++;
|
||||
else { /* digit seen */
|
||||
*ip++ = *buf;
|
||||
if (dp)
|
||||
places++;
|
||||
}
|
||||
buf++;
|
||||
}
|
||||
*ip = 0;
|
||||
if (*buf == 'e' || *buf == 'E') { /* exponent string */
|
||||
buf++;
|
||||
esign = (*buf == '-');
|
||||
if (*buf == '-' || *buf == '+')
|
||||
buf++;
|
||||
while (*buf) /* get exponent string */
|
||||
*ep++ = *buf++;
|
||||
}
|
||||
*ep = 0;
|
||||
ibin = strbin(ibuf);
|
||||
ebin = atoi(ebuf);
|
||||
places = (esign) ? -ebin - places : ebin - places;
|
||||
fp = ibin * power10(places);
|
||||
ieee = fptoieee(fp);
|
||||
if (isign) /* negative float */
|
||||
ieee =| 0x80000000;
|
||||
return( ieee );
|
||||
}
|
||||
|
||||
float
|
||||
power10(pwr) /* 10^pwr */
|
||||
int pwr;
|
||||
{
|
||||
float f;
|
||||
|
||||
if (pwr < 0L) /* negative power */
|
||||
for (f = 1.0; pwr < 0; pwr++)
|
||||
f = f / 10.0;
|
||||
else /* positive power */
|
||||
for (f = 1.0; pwr > 0; pwr--)
|
||||
f = f * 10.0;
|
||||
return(f);
|
||||
}
|
||||
|
||||
long
|
||||
fptoieee(f) /* convert current machine float to ieee rep */
|
||||
float f; /* unsigned float... */
|
||||
{
|
||||
register long exp, l;
|
||||
|
||||
if (f == 0.0)
|
||||
return(0L);
|
||||
exp = 0L;
|
||||
for( ; f >= 2.0; f = f / 2.0)
|
||||
exp++;
|
||||
for( ; f < 1.0; f = f * 2.0)
|
||||
exp--;
|
||||
f = f - 1.0; /* implicit 1, eg. 1.F */
|
||||
if (f != 0.0)
|
||||
f = f * 8388608.0; /* 2 ^ 23 */
|
||||
l = f;
|
||||
exp =+ BIAS;
|
||||
l =| ((exp<<23) & 0x7f800000);
|
||||
return(l);
|
||||
}
|
||||
|
||||
float
|
||||
strbin(p) /* decimal string => binary long */
|
||||
char *p;
|
||||
{
|
||||
float f;
|
||||
|
||||
for (f = 0.0; *p >= '0' && *p <= '9'; p++) {
|
||||
f = f * 10.0;
|
||||
f = f + (*p - '0');
|
||||
}
|
||||
return(f);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright 1983
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) ceil - Feb 11, 1983";*/
|
||||
|
||||
/* ceil - returns the smallest integer (as a double precision
|
||||
number) not greater than x. */
|
||||
|
||||
double
|
||||
ceil(x)
|
||||
double x;
|
||||
{
|
||||
register long i;
|
||||
double retval;
|
||||
|
||||
if( x > 0 )
|
||||
x += 0.999999999999;
|
||||
i = x;
|
||||
retval = i;
|
||||
return( retval );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) etoa - jan 24, 1982"; */
|
||||
|
||||
/*
|
||||
* IEEE Floating Point to Ascii String Conversion Routine :
|
||||
* IEEE Standard Single Precision Representation Floating Point
|
||||
*
|
||||
* char *
|
||||
* etoa(f,buf,prec)
|
||||
* float f;
|
||||
* char *buf;
|
||||
* int prec;
|
||||
*
|
||||
* No more than 9 decimal digits are allowed in single precision.
|
||||
* Largest positive number is 3.4 * 10^33 and the smallest positive
|
||||
* number is 1.2 * 10^-38.
|
||||
* Rely's on the fact that a long and a float are both 32 bits.
|
||||
*/
|
||||
|
||||
#define BIAS 127L
|
||||
|
||||
float _ieeetof();
|
||||
|
||||
char *
|
||||
etoa(fl,buf,prec)
|
||||
long fl; /* ieee formatted float */
|
||||
char *buf;
|
||||
int prec;
|
||||
{
|
||||
register char *bp;
|
||||
register int exp, digit;
|
||||
float f;
|
||||
|
||||
prec = (prec <= 0) ? 1 : (prec <= 9) ? prec : 9;
|
||||
bp = buf;
|
||||
f = _ieeetof(fl); /* get floating point value */
|
||||
if (f < 0.0) { /* negative float */
|
||||
*bp++ = '-';
|
||||
f = -f; /* make it positive */
|
||||
}
|
||||
if (f == 0.0) {
|
||||
*bp++ = '0'; *bp++ = '.';
|
||||
while (prec--)
|
||||
*bp++ = '0';
|
||||
*bp++ = 'e'; *bp++ = '0'; *bp++ = '0'; *bp = 0;
|
||||
return(buf);
|
||||
}
|
||||
for (exp=0; f < 1.0; f = f * 10.0) /* get negative exp */
|
||||
exp--;
|
||||
for ( ; f >= 1.0; f = f / 10.0) /* 0.XXXXXXE00 * 10^exp */
|
||||
exp++;
|
||||
|
||||
exp--; /* for one explicit digit */
|
||||
f = f * 10.0;
|
||||
digit = f; /* get one digit */
|
||||
f = f - digit;
|
||||
*bp++ = digit + '0';
|
||||
*bp++ = '.';
|
||||
while(prec-- > 0) { /* get prec. decimal places */
|
||||
f = f * 10.0;
|
||||
digit = f;
|
||||
f = f - digit;
|
||||
*bp++ = digit + '0';
|
||||
}
|
||||
*bp++ = 'e';
|
||||
if (exp < 0) {
|
||||
exp = -exp;
|
||||
*bp++ = '-';
|
||||
}
|
||||
*bp++ = (exp / 10) + '0';
|
||||
*bp++ = (exp % 10) + '0';
|
||||
*bp = 0;
|
||||
return(buf);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) fabs - jan 11, 1983";*/
|
||||
|
||||
/*
|
||||
* Floating Point Absolute :
|
||||
* Fast Floating Point Package
|
||||
*
|
||||
* double
|
||||
* fabs(farg)
|
||||
* double farg;
|
||||
*
|
||||
* Returns : absolute Floating point number
|
||||
*/
|
||||
|
||||
long
|
||||
fabs(f)
|
||||
long f;
|
||||
{
|
||||
f = f & 0x7fffffff; /* turn off sign bit */
|
||||
return(f);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright 1983
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) floor - Feb 11, 1983";
|
||||
|
||||
/* floor - returns the largest integer (as a double precision
|
||||
number) not greater than x. */
|
||||
|
||||
double
|
||||
floor(x)
|
||||
double x;
|
||||
{
|
||||
register long i;
|
||||
double retval;
|
||||
|
||||
if ( x < 0 )
|
||||
x -= 0.99999999999999;
|
||||
i = x;
|
||||
retval = i;
|
||||
return( retval );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Copyright 1983
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) fmod - Feb 11, 1983";
|
||||
|
||||
/* fmod - returns the number f such that x = iy + f, and
|
||||
0 <= f <= y. */
|
||||
|
||||
double
|
||||
fmod(x,y)
|
||||
double x;
|
||||
double y;
|
||||
{
|
||||
double z;
|
||||
double retval;
|
||||
register long i;
|
||||
double fabs();
|
||||
double absx;
|
||||
double absy;
|
||||
|
||||
absx = fabs(x);
|
||||
absy = fabs(y);
|
||||
for(z = absx; z - absy >= 0. ; z -= absy)
|
||||
;
|
||||
i = z;
|
||||
if( x < 0.0 )
|
||||
i *= -1;
|
||||
retval = i;
|
||||
return( retval );
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/**
|
||||
** formated print
|
||||
**/
|
||||
|
||||
/*char *version "@(#)fprintf - jan 24, 1982";*/
|
||||
#include "/usr/regulus/stdio.h"
|
||||
#define BUFSIZ 80
|
||||
|
||||
char *ftoa();
|
||||
char *etoa();
|
||||
char *petoa();
|
||||
char *pftoa();
|
||||
|
||||
static char *__str;
|
||||
FILE *__stream;
|
||||
static char **_p;
|
||||
|
||||
fprintf(fp, plist)
|
||||
FILE *fp;
|
||||
char *plist;
|
||||
{
|
||||
if (!fp->_flag & _WMODE) return;
|
||||
|
||||
__stream = fp;
|
||||
_p = &plist;
|
||||
__doprintf(0);
|
||||
fflush(fp);
|
||||
}
|
||||
|
||||
sprintf(s, plist)
|
||||
char *s, *plist;
|
||||
{
|
||||
__str = s;
|
||||
_p = &plist;
|
||||
__doprint(1);
|
||||
*__str = NULL;
|
||||
}
|
||||
|
||||
__doprint(mode)
|
||||
int mode;
|
||||
{
|
||||
register char *fmt, c;
|
||||
char buf[BUFSIZ];
|
||||
extern char *__prtshort(), *__prtld();
|
||||
register int *pi;
|
||||
int width, prec;
|
||||
int left, longf;
|
||||
char padchar;
|
||||
char *s;
|
||||
int n;
|
||||
auto (*fn)();
|
||||
int len;
|
||||
|
||||
fmt = *_p++;
|
||||
|
||||
pi = _p;
|
||||
while (c = *fmt++)
|
||||
{
|
||||
_p = pi;
|
||||
if (c != '%')
|
||||
{
|
||||
__putch(mode, c);
|
||||
continue;
|
||||
}
|
||||
left = 0;
|
||||
if ((c = *fmt++) == '-')
|
||||
{
|
||||
c = *fmt++;
|
||||
left++;
|
||||
}
|
||||
padchar = ' ';
|
||||
if (c == '0')
|
||||
{
|
||||
padchar = c;
|
||||
c = *fmt++;
|
||||
}
|
||||
width = -1;
|
||||
while (c >= '0' && c <= '9')
|
||||
{
|
||||
if (width < 0)
|
||||
width = 0;
|
||||
width = width * 10 + (c - '0');
|
||||
c = *fmt++;
|
||||
}
|
||||
prec = -1;
|
||||
if (c == '.')
|
||||
{
|
||||
prec = 0;
|
||||
c = *fmt++;
|
||||
}
|
||||
while (c >= '0' && c <= '9')
|
||||
{
|
||||
prec = prec * 10 + (c - '0');
|
||||
c = *fmt++;
|
||||
}
|
||||
longf = 0;
|
||||
if (c == 'l')
|
||||
{
|
||||
longf++;
|
||||
c = *fmt++;
|
||||
}
|
||||
/*
|
||||
* we now have all the prelims out of the way;
|
||||
* let's see what we want to print
|
||||
*/
|
||||
s = buf;
|
||||
switch (c)
|
||||
{
|
||||
|
||||
case 'd': /* decimal signed */
|
||||
case 'D':
|
||||
if (longf)
|
||||
fn = __prtld;
|
||||
else
|
||||
fn = __prtshort;
|
||||
__prtint(pi++, buf, 10, 1, fn, 0);
|
||||
if (longf)
|
||||
pi++;
|
||||
break;
|
||||
|
||||
case 'u': /* decimal unsigned */
|
||||
case 'U':
|
||||
__prtint(pi++, buf, 10, 0, __prtshort, 0);
|
||||
break;
|
||||
|
||||
case 'o': /* octal unsigned */
|
||||
case 'O':
|
||||
if (longf)
|
||||
fn = __prtld;
|
||||
else
|
||||
fn = __prtshort;
|
||||
__prtint(pi++, buf, 8, 0, fn, 0);
|
||||
if (longf)
|
||||
pi++;
|
||||
break;
|
||||
|
||||
case 'x': /* hexadecimal unsigned */
|
||||
case 'X':
|
||||
if (longf)
|
||||
fn = __prtld;
|
||||
else
|
||||
fn = __prtshort;
|
||||
__prtint(pi++, buf, 16, 0, fn, c == 'X');
|
||||
if (longf)
|
||||
pi++;
|
||||
break;
|
||||
|
||||
case 's': /* string */
|
||||
case 'S':
|
||||
s = *_p++;
|
||||
pi = _p;
|
||||
break;
|
||||
|
||||
case 'c': /* character */
|
||||
case 'C':
|
||||
n = *pi++;
|
||||
buf[0] = n;
|
||||
buf[1] = '\0';
|
||||
break;
|
||||
|
||||
case 'e': /* exponential */
|
||||
case 'E':
|
||||
petoa(pi, buf, prec);
|
||||
pi =+ 2;
|
||||
prec = -1;
|
||||
break;
|
||||
|
||||
case 'f': /* floating */
|
||||
case 'F':
|
||||
pftoa(pi, buf, prec);
|
||||
pi =+ 2;
|
||||
prec = -1;
|
||||
break;
|
||||
|
||||
case 'g': /* e or f */
|
||||
case 'G':
|
||||
pftoa(pi, buf, prec);
|
||||
if (strlen(buf) > (7 + prec)) /* smallest fp string */
|
||||
petoa(pi, buf, prec);
|
||||
pi =+ 2;
|
||||
prec = -1;
|
||||
break;
|
||||
|
||||
default: /* just print the character */
|
||||
__putch(mode, c);
|
||||
continue;
|
||||
|
||||
}
|
||||
len = __length(s);
|
||||
if (prec < len && prec >= 0)
|
||||
len = prec;
|
||||
n = width - len;
|
||||
if (!left)
|
||||
{
|
||||
if (padchar != ' ' && *s == '-')
|
||||
{
|
||||
len--;
|
||||
__putch(mode, *s); s++;
|
||||
}
|
||||
while (n-- > 0)
|
||||
__putch(mode, padchar);
|
||||
}
|
||||
while (len--) {
|
||||
__putch(mode, *s); s++;
|
||||
}
|
||||
while (n-- > 0)
|
||||
__putch(mode, padchar);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
__putch(mode, c)
|
||||
int mode;
|
||||
char c;
|
||||
{
|
||||
if (mode)
|
||||
*__str++ = c;
|
||||
else
|
||||
putc(c,__stream);
|
||||
return (c);
|
||||
}
|
||||
|
||||
char *
|
||||
pftoa(addr,buf,prec)
|
||||
float *addr;
|
||||
char *buf;
|
||||
int prec;
|
||||
{
|
||||
float fp;
|
||||
|
||||
if (prec<0)
|
||||
prec = 6;
|
||||
fp = *addr;
|
||||
return( ftoa(fp, buf, prec) );
|
||||
}
|
||||
|
||||
char *
|
||||
petoa(addr,buf,prec)
|
||||
float *addr;
|
||||
char *buf;
|
||||
int prec;
|
||||
{
|
||||
float fp;
|
||||
|
||||
if (prec<0)
|
||||
prec = 6;
|
||||
fp = *addr;
|
||||
return( etoa(fp, buf, prec) );
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) ftoa - jan 24, 1982"; */
|
||||
|
||||
/*
|
||||
* IEEE Floating Point to Ascii String Conversion Routine :
|
||||
* IEEE Standard Single Precision Representation Floating Point
|
||||
*
|
||||
* char *
|
||||
* ftoa(f,buf,prec)
|
||||
* float f;
|
||||
* char *buf;
|
||||
* int prec;
|
||||
*
|
||||
* No more than 9 decimal digits are allowed in single precision.
|
||||
* Largest positive number is 3.4 * 10^33 and the smallest positive
|
||||
* number is 1.2 * 10^-38.
|
||||
* Rely's on the fact that a long and a float are both 32 bits.
|
||||
*/
|
||||
|
||||
#define BIAS 127L
|
||||
|
||||
float _ieeetof();
|
||||
|
||||
char *
|
||||
ftoa(fl,buf,prec)
|
||||
long fl; /* ieee formatted float */
|
||||
char *buf;
|
||||
int prec;
|
||||
{
|
||||
register char *bp;
|
||||
register int exp, digit;
|
||||
float f;
|
||||
|
||||
prec = (prec <= 0) ? 1 : (prec <= 9) ? prec : 9;
|
||||
bp = buf;
|
||||
f = _ieeetof(fl); /* get floating point value */
|
||||
if (f < 0.0) { /* negative float */
|
||||
*bp++ = '-';
|
||||
f = -f; /* make it positive */
|
||||
}
|
||||
if (f == 0.0) {
|
||||
*bp++ = '0'; *bp++ = '.';
|
||||
while (prec--)
|
||||
*bp++ = '0';
|
||||
*bp = 0;
|
||||
return(buf);
|
||||
}
|
||||
for (exp=0; f < 1.0; f = f * 10.0) /* get negative exp */
|
||||
exp--;
|
||||
for ( ; f >= 1.0; f = f / 10.0) /* 0.XXXXXXE00 * 10^exp */
|
||||
exp++;
|
||||
|
||||
if (exp<=0) /* one significant digit */
|
||||
*bp++ = '0';
|
||||
for ( ; exp>0; exp--) { /* get significant digits */
|
||||
f = f * 10.0;
|
||||
digit = f; /* get one digit */
|
||||
f = f - digit;
|
||||
*bp++ = digit + '0';
|
||||
}
|
||||
*bp++ = '.';
|
||||
for( ; exp<0 && prec; prec--, exp++) /* exp < 0 ? */
|
||||
*bp++ = '0';
|
||||
while(prec-- > 0) {
|
||||
f = f * 10.0;
|
||||
digit = f; /* get one digit */
|
||||
f = f - digit;
|
||||
*bp++ = digit + '0';
|
||||
}
|
||||
*bp = 0;
|
||||
return(buf);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/* char *version "@(#) ftol - Jan 28, 1983"; */
|
||||
|
||||
/*
|
||||
* Floating Point Float to Long Routine :
|
||||
* Front End to IEEE Floating Point Package.
|
||||
*
|
||||
* long
|
||||
* fpftol(fparg)
|
||||
* double fparg;
|
||||
*
|
||||
* Return : Fixed Point representation of Floating Point Number
|
||||
*/
|
||||
|
||||
#define BIAS 127L
|
||||
|
||||
long
|
||||
fpftol(f)
|
||||
long f;
|
||||
{
|
||||
register long l;
|
||||
register int exp, sign;
|
||||
|
||||
l = (f & 0x7f800000) >> 23;
|
||||
exp = l - BIAS;
|
||||
if (f == 0L || exp < 0) /* underflow or 0 */
|
||||
return(0L);
|
||||
sign = (f < 0L);
|
||||
if (exp > 31) /* overflow */
|
||||
return( (sign) ? 0x80000000 : 0x7fffffff);
|
||||
exp =- 23;
|
||||
l = (f & 0x7fffff) | 0x800000; /* 1.F */
|
||||
for( ; exp < 0 ; exp++)
|
||||
l =>> 1;
|
||||
for( ; exp > 0; exp--)
|
||||
l =<< 1;
|
||||
if (sign)
|
||||
l = -l;
|
||||
return(l);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) _ieeetof - dec 29, 1982"; */
|
||||
|
||||
/*
|
||||
* IEEE Floating Point Representation to Internal Representation :
|
||||
* IEEE Standard Single Precision Representation Floating Point
|
||||
*
|
||||
* float
|
||||
* _ieeetof(lf)
|
||||
* long lf;
|
||||
*
|
||||
* Largest positive number is 3.4 * 10^33 and the smallest positive
|
||||
* number is 1.2 * 10^-38.
|
||||
* Rely's on the fact that a long and a float are both 32 bits.
|
||||
*/
|
||||
|
||||
#define BIAS 127L
|
||||
|
||||
float
|
||||
_ieeetof(lf)
|
||||
long lf;
|
||||
{
|
||||
register long exp;
|
||||
register int count, fsign;
|
||||
float f;
|
||||
|
||||
if (lf == 0L)
|
||||
return(0.0);
|
||||
if (lf < 0L) {
|
||||
fsign = 1;
|
||||
lf =& 0x7fffffff; /* mask MSB (sign) */
|
||||
}
|
||||
else
|
||||
fsign = 0;
|
||||
exp = (lf >> 23) & 0xff; /* biased ieee exponent */
|
||||
exp =- BIAS;
|
||||
lf =& 0x7fffff; /* 23 bits of fraction */
|
||||
f = lf;
|
||||
if (f != 0.0)
|
||||
f = f / 8388608.0; /* 2 ^ 23 */
|
||||
f = f + 1.0; /* ieee fraction : 1.F */
|
||||
while (exp < 0) { /* negative exp : 2^-? */
|
||||
f = f / 2.0;
|
||||
exp++;
|
||||
}
|
||||
while (exp > 0) { /* positive exp : 2^+? */
|
||||
f = f * 2.0;
|
||||
exp--;
|
||||
}
|
||||
if (fsign)
|
||||
f = -f;
|
||||
return(f);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) fpltof - Jan 7, 1983"; */
|
||||
|
||||
/*
|
||||
* Floating Point Long to Float Routine :
|
||||
* Front End to IEEE Floating Point Package.
|
||||
*
|
||||
* double
|
||||
* fpltof(larg)
|
||||
* long larg;
|
||||
*
|
||||
* Return : Floating Point representation of Long Fixed point integer
|
||||
*/
|
||||
|
||||
#define BIAS 127L
|
||||
|
||||
long
|
||||
fpltof(l)
|
||||
long l;
|
||||
{
|
||||
register long exp;
|
||||
register int sign;
|
||||
|
||||
if (l < 0L) { /* signed ?? */
|
||||
sign = 1;
|
||||
l = -l;
|
||||
}
|
||||
else
|
||||
sign = 0;
|
||||
if (l == 0L)
|
||||
return(0L);
|
||||
exp = 23L;
|
||||
for( ; l & 0x7f000000; exp++) /* something in upper 7 bits */
|
||||
l =>> 1;
|
||||
for( ; !(l & 0x00800000); exp--) /* get mantissa : 1.F */
|
||||
l =<< 1;
|
||||
l =& 0x007fffff; /* reduce to .F in 23 bits */
|
||||
if (sign)
|
||||
l =| 0x80000000;
|
||||
exp = (exp + BIAS)<<23;
|
||||
l =| exp;
|
||||
return(l);
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
//char *version "@(#)printf - jan 24, 1982";
|
||||
|
||||
/**
|
||||
** formated print
|
||||
**/
|
||||
|
||||
#define BUFSIZ 80
|
||||
#define MAXFILES 15
|
||||
|
||||
char *etoa();
|
||||
char *ftoa();
|
||||
char *petoa();
|
||||
char *pftoa();
|
||||
|
||||
printf(arg1,arg2,arg3)
|
||||
char *arg1, *arg2, *arg3;
|
||||
{
|
||||
register char *fmt, c;
|
||||
char buf[BUFSIZ];
|
||||
extern char *__prtshort(), *__pprtld(), *__prtld();
|
||||
int mode;
|
||||
char *fd;
|
||||
register char **p;
|
||||
register int *pi;
|
||||
int width, prec;
|
||||
int left, longf;
|
||||
char padchar;
|
||||
char *s;
|
||||
int n;
|
||||
auto (*fn)();
|
||||
int len;
|
||||
|
||||
if( arg1 == -1 ) {
|
||||
mode = 2;
|
||||
fd = arg2;
|
||||
p = &arg3;
|
||||
}
|
||||
else if( arg1 < MAXFILES ) {
|
||||
mode = 1; /* printf(fd,fmt,...) or printf(-1,str,fmt,...) */
|
||||
fd = arg1;
|
||||
p = &arg2;
|
||||
}
|
||||
else {
|
||||
mode = 0;
|
||||
fd = 0;
|
||||
p = &arg1;
|
||||
}
|
||||
fmt = *p++;
|
||||
|
||||
pi = p;
|
||||
while (c = *fmt++)
|
||||
{
|
||||
p = pi;
|
||||
if (c != '%')
|
||||
{
|
||||
__pputch(mode, &fd, c);
|
||||
continue;
|
||||
}
|
||||
left = 0;
|
||||
if ((c = *fmt++) == '-')
|
||||
{
|
||||
c = *fmt++;
|
||||
left++;
|
||||
}
|
||||
padchar = ' ';
|
||||
if (c == '0')
|
||||
{
|
||||
padchar = c;
|
||||
c = *fmt++;
|
||||
}
|
||||
width = -1;
|
||||
while (c >= '0' && c <= '9')
|
||||
{
|
||||
if (width < 0)
|
||||
width = 0;
|
||||
width = width * 10 + (c - '0');
|
||||
c = *fmt++;
|
||||
}
|
||||
prec = -1;
|
||||
if (c == '.')
|
||||
{
|
||||
prec = 0;
|
||||
c = *fmt++;
|
||||
}
|
||||
while (c >= '0' && c <= '9')
|
||||
{
|
||||
prec = prec * 10 + (c - '0');
|
||||
c = *fmt++;
|
||||
}
|
||||
longf = 0;
|
||||
if (c == 'l')
|
||||
{
|
||||
longf++;
|
||||
c = *fmt++;
|
||||
}
|
||||
/* we now have all the prelims out of the way;
|
||||
let's see what we want to print */
|
||||
|
||||
s = buf;
|
||||
switch (c)
|
||||
{
|
||||
|
||||
case 'd': /* decimal signed */
|
||||
case 'D':
|
||||
if (longf)
|
||||
fn = __prtld;
|
||||
else
|
||||
fn = __prtshort;
|
||||
__prtint(pi++, buf, 10, 1, fn, 0);
|
||||
if (longf)
|
||||
pi++;
|
||||
break;
|
||||
|
||||
case 'u': /* decimal unsigned */
|
||||
case 'U':
|
||||
__prtint(pi++, buf, 10, 0, __prtshort, 0);
|
||||
break;
|
||||
|
||||
case 'o': /* octal unsigned */
|
||||
case 'O':
|
||||
if (longf)
|
||||
fn = __prtld;
|
||||
else
|
||||
fn = __prtshort;
|
||||
__prtint(pi++, buf, 8, 0, fn, 0);
|
||||
if (longf)
|
||||
pi++;
|
||||
break;
|
||||
|
||||
case 'x': /* hexadecimal unsigned */
|
||||
case 'X':
|
||||
if (longf)
|
||||
fn = __prtld;
|
||||
else
|
||||
fn = __prtshort;
|
||||
__prtint(pi++, buf, 16, 0, fn, c == 'X');
|
||||
if (longf)
|
||||
pi++;
|
||||
break;
|
||||
|
||||
case 's': /* string */
|
||||
case 'S':
|
||||
s = *p++;
|
||||
pi = p;
|
||||
break;
|
||||
|
||||
case 'c': /* character */
|
||||
case 'C':
|
||||
n = *pi++;
|
||||
buf[0] = n;
|
||||
buf[1] = '\0';
|
||||
break;
|
||||
|
||||
case 'e': /* exponential */
|
||||
case 'E':
|
||||
petoa(pi, buf, prec);
|
||||
pi =+ 2;
|
||||
prec = -1;
|
||||
break;
|
||||
|
||||
case 'f': /* floating */
|
||||
case 'F':
|
||||
pftoa(pi, buf, prec);
|
||||
pi =+ 2;
|
||||
prec = -1;
|
||||
break;
|
||||
|
||||
case 'g': /* e or f */
|
||||
case 'G':
|
||||
pftoa(pi, buf, prec);
|
||||
if (strlen(buf) > (7 + prec) ) /* smallest fp string */
|
||||
petoa(pi, buf, prec);
|
||||
pi =+ 2;
|
||||
prec = -1;
|
||||
break;
|
||||
|
||||
default: /* just print the character */
|
||||
__pputch(mode, &fd, c);
|
||||
continue;
|
||||
|
||||
}
|
||||
len = __length(s);
|
||||
if (prec < len && prec >= 0)
|
||||
len = prec;
|
||||
n = width - len;
|
||||
if (!left)
|
||||
{
|
||||
if (padchar != ' ' && *s == '-')
|
||||
{
|
||||
len--;
|
||||
__pputch(mode, &fd, *s++);
|
||||
}
|
||||
while (n-- > 0)
|
||||
__pputch(mode, &fd, padchar);
|
||||
}
|
||||
while (len--)
|
||||
__pputch(mode, &fd, *s++);
|
||||
while (n-- > 0)
|
||||
__pputch(mode, &fd, padchar);
|
||||
}
|
||||
if (mode == 2)
|
||||
*fd = '\0';
|
||||
}
|
||||
|
||||
|
||||
__pputch(mode, pfd, c)
|
||||
int mode;
|
||||
char c;
|
||||
char **pfd;
|
||||
{
|
||||
register long fd;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
|
||||
case 0:
|
||||
if (write(1,&c,1) != 1) return(-1);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
fd = *pfd;
|
||||
if (write((int)fd,&c,1) != 1) return(-1);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
*(*pfd)++ = c;
|
||||
break;
|
||||
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
|
||||
char *
|
||||
pftoa(addr,buf,prec)
|
||||
float *addr;
|
||||
char *buf;
|
||||
int prec;
|
||||
{
|
||||
float fp;
|
||||
|
||||
if (prec<0)
|
||||
prec = 6;
|
||||
fp = *addr;
|
||||
return( ftoa(fp, buf, prec) );
|
||||
}
|
||||
|
||||
char *
|
||||
petoa(addr,buf,prec)
|
||||
float *addr;
|
||||
char *buf;
|
||||
int prec;
|
||||
{
|
||||
float fp;
|
||||
|
||||
if (prec<0)
|
||||
prec = 6;
|
||||
fp = *addr;
|
||||
return( etoa(fp, buf, prec) );
|
||||
}
|
||||
BIN
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/al40/fp/libF.a
Normal file
BIN
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/al40/fp/libF.a
Normal file
Binary file not shown.
@@ -0,0 +1,13 @@
|
||||
c68 -L -c -f atof.c
|
||||
c68 -L -c -f ceil.c
|
||||
c68 -L -c -f etoa.c
|
||||
c68 -L -c -f fabs.c
|
||||
c68 -L -c -f ffptof.c
|
||||
c68 -L -c -f floor.c
|
||||
c68 -L -c -f fmod.c
|
||||
c68 -L -c -f fprintf.c
|
||||
c68 -L -c -f ftoa.c
|
||||
c68 -L -c -f ftoffp.c
|
||||
c68 -L -c -f ftol.c
|
||||
c68 -L -c -f ltof.c
|
||||
c68 -L -c -f printf.c
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) atof - dec 29, 1982"; */
|
||||
|
||||
/*
|
||||
* Ascii String to FFP Floating Point Routine :
|
||||
* FFP Standard Single Precision Representation Floating Point
|
||||
*
|
||||
* float
|
||||
* atof(buf)
|
||||
* char *buf;
|
||||
*
|
||||
* No more than 9 significant digits are allowed in single precision.
|
||||
* Largest positive number is 3.4 * 10^18 and the smallest positive
|
||||
* number is 1.2 * 10^-20.
|
||||
* Rely's on the fact that a long and a float are both 32 bits.
|
||||
*/
|
||||
|
||||
#define EXPSIZ 4
|
||||
#define FRACSIZ 20
|
||||
|
||||
long fptoffp();
|
||||
float strbin();
|
||||
float power10();
|
||||
|
||||
long
|
||||
atof(buf)
|
||||
char *buf;
|
||||
{
|
||||
char ibuf[FRACSIZ], ebuf[EXPSIZ];
|
||||
register char *ip, *ep;
|
||||
long ffp;
|
||||
int dp, esign, isign, ebin, places;
|
||||
float ibin, fp;
|
||||
|
||||
ip = &ibuf; ep = &ebuf; dp = 0; places = 0L;
|
||||
while (*buf == ' ' || *buf == '\t') /* ignore white spaces */
|
||||
buf++;
|
||||
isign = (*buf == '-');
|
||||
if (*buf == '-' || *buf == '+')
|
||||
buf++;
|
||||
while (*buf && *buf != 'e' && *buf != 'E') {
|
||||
if (*buf == '.')
|
||||
dp++;
|
||||
else { /* digit seen */
|
||||
*ip++ = *buf;
|
||||
if (dp)
|
||||
places++;
|
||||
}
|
||||
buf++;
|
||||
}
|
||||
*ip = 0;
|
||||
if (*buf == 'e' || *buf == 'E') { /* exponent string */
|
||||
buf++;
|
||||
esign = (*buf == '-');
|
||||
if (*buf == '-' || *buf == '+')
|
||||
buf++;
|
||||
while (*buf) /* get exponent string */
|
||||
*ep++ = *buf++;
|
||||
}
|
||||
*ep = 0;
|
||||
ibin = strbin(ibuf);
|
||||
ebin = atoi(ebuf);
|
||||
places = (esign) ? -ebin - places : ebin - places;
|
||||
fp = ibin * power10(places);
|
||||
ffp = fptoffp(fp);
|
||||
if (isign) /* negative float */
|
||||
ffp =| 0x80;
|
||||
return( ffp );
|
||||
}
|
||||
|
||||
float
|
||||
power10(pwr) /* 10^pwr */
|
||||
int pwr;
|
||||
{
|
||||
float f;
|
||||
|
||||
if (pwr < 0) /* negative power */
|
||||
for (f = 1.0; pwr < 0; pwr++)
|
||||
f = f / 10.0;
|
||||
else /* positive power */
|
||||
for (f = 1.0; pwr > 0; pwr--)
|
||||
f = f * 10.0;
|
||||
return(f);
|
||||
}
|
||||
|
||||
float
|
||||
strbin(p) /* decimal string => binary long */
|
||||
char *p;
|
||||
{
|
||||
float f;
|
||||
|
||||
for (f = 0.0; *p >= '0' && *p <= '9'; p++) {
|
||||
f = f * 10.0;
|
||||
f = f + (*p - '0');
|
||||
}
|
||||
return(f);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright 1983
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) ceil - Feb 11, 1983";*/
|
||||
|
||||
/* ceil - returns the smallest integer (as a double precision
|
||||
number) not greater than x. */
|
||||
|
||||
double
|
||||
ceil(x)
|
||||
double x;
|
||||
{
|
||||
register long i;
|
||||
double retval;
|
||||
|
||||
if( x > 0 )
|
||||
x += 0.999999999999;
|
||||
i = x;
|
||||
retval = i;
|
||||
return( retval );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) etoa - jan 24, 1982"; */
|
||||
|
||||
/*
|
||||
* FFP Floating Point to Ascii String Conversion Routine :
|
||||
* FFP Standard Single Precision Representation Floating Point
|
||||
*
|
||||
* char *
|
||||
* etoa(f,buf,prec)
|
||||
* float f;
|
||||
* char *buf;
|
||||
* int prec;
|
||||
*
|
||||
* No more than 9 decimal digits are allowed in single precision.
|
||||
* Largest positive number is 3.4 * 10^18 and the smallest positive
|
||||
* number is 1.2 * 10^-20.
|
||||
* Rely's on the fact that a long and a float are both 32 bits.
|
||||
*/
|
||||
|
||||
#define BIAS 127L
|
||||
|
||||
float ffptof();
|
||||
|
||||
char *
|
||||
etoa(fl,buf,prec)
|
||||
long fl; /* ffp formatted float */
|
||||
char *buf;
|
||||
int prec;
|
||||
{
|
||||
register char *bp;
|
||||
register int exp, digit;
|
||||
float f;
|
||||
|
||||
prec = (prec <= 0) ? 1 : (prec <= 9) ? prec : 9;
|
||||
bp = buf;
|
||||
f = ffptof(fl); /* get floating point value */
|
||||
if (f < 0.0) { /* negative float */
|
||||
*bp++ = '-';
|
||||
f = -f; /* make it positive */
|
||||
}
|
||||
if (f == 0.0) {
|
||||
*bp++ = '0'; *bp++ = '.';
|
||||
while (prec--)
|
||||
*bp++ = '0';
|
||||
*bp++ = 'e'; *bp++ = '0'; *bp++ = '0'; *bp = 0;
|
||||
return(buf);
|
||||
}
|
||||
for (exp=0; f < 1.0; f = f * 10.0) /* get negative exp */
|
||||
exp--;
|
||||
for ( ; f >= 1.0; f = f / 10.0) /* 0.XXXXXXE00 * 10^exp */
|
||||
exp++;
|
||||
|
||||
exp--; /* for one explicit digit */
|
||||
f = f * 10.0;
|
||||
digit = f; /* get one digit */
|
||||
f = f - digit;
|
||||
*bp++ = digit + '0';
|
||||
*bp++ = '.';
|
||||
while(prec-- > 0) { /* get prec. decimal places */
|
||||
f = f * 10.0;
|
||||
digit = f;
|
||||
f = f - digit;
|
||||
*bp++ = digit + '0';
|
||||
}
|
||||
*bp++ = 'e';
|
||||
if (exp < 0) {
|
||||
exp = -exp;
|
||||
*bp++ = '-';
|
||||
}
|
||||
*bp++ = (exp / 10) + '0';
|
||||
*bp++ = (exp % 10) + '0';
|
||||
*bp = 0;
|
||||
return(buf);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) fabs - jan 11, 1983";*/
|
||||
|
||||
/*
|
||||
* Floating Point Absolute :
|
||||
* Fast Floating Point Package
|
||||
*
|
||||
* double
|
||||
* fabs(farg)
|
||||
* double farg;
|
||||
*
|
||||
* Returns : absolute Floating point number
|
||||
*/
|
||||
|
||||
long
|
||||
fabs(f)
|
||||
long f;
|
||||
{
|
||||
f = f & 0xffffff7f; /* turn off sign bit */
|
||||
return(f);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) _ffptof - Feb 1, 1983"; */
|
||||
|
||||
/*
|
||||
* FFP Floating Point Representation to Internal Representation :
|
||||
* FFP Standard Single Precision Representation Floating Point
|
||||
*
|
||||
* float
|
||||
* ffptof(lf)
|
||||
* long lf;
|
||||
*
|
||||
* Largest positive number is 3.4 * 10^18 and the smallest positive
|
||||
* number is 1.2 * 10^-20.
|
||||
* Rely's on the fact that a long and a float are both 32 bits.
|
||||
*/
|
||||
|
||||
float
|
||||
ffptof(lf)
|
||||
long lf;
|
||||
{
|
||||
register int exp, count, fsign;
|
||||
float f;
|
||||
|
||||
if (lf == 0L)
|
||||
return(0.0);
|
||||
fsign = (lf & 0x80);
|
||||
exp = (lf & 0x7f) - 0x40;
|
||||
lf = (lf>>8) & 0xffffff; /* 24 bits of fraction */
|
||||
f = lf;
|
||||
f = f / 16777216.0; /* 2 ^ 24 */
|
||||
while (exp < 0) { /* negative exp : 2^-? */
|
||||
f = f / 2.0;
|
||||
exp++;
|
||||
}
|
||||
while (exp > 0) { /* positive exp : 2^+? */
|
||||
f = f * 2.0;
|
||||
exp--;
|
||||
}
|
||||
if (fsign)
|
||||
f = -f;
|
||||
return(f);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright 1983
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) floor - Feb 11, 1983";
|
||||
|
||||
/* floor - returns the largest integer (as a double precision
|
||||
number) not greater than x. */
|
||||
|
||||
double
|
||||
floor(x)
|
||||
double x;
|
||||
{
|
||||
register long i;
|
||||
double retval;
|
||||
|
||||
if ( x < 0 )
|
||||
x -= 0.99999999999999;
|
||||
i = x;
|
||||
retval = i;
|
||||
return( retval );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Copyright 1983
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) fmod - Feb 11, 1983";
|
||||
|
||||
/* fmod - returns the number f such that x = iy + f, and
|
||||
0 <= f <= y. */
|
||||
|
||||
double
|
||||
fmod(x,y)
|
||||
double x;
|
||||
double y;
|
||||
{
|
||||
double z;
|
||||
double retval;
|
||||
register long i;
|
||||
double fabs();
|
||||
double absx;
|
||||
double absy;
|
||||
|
||||
absx = fabs(x);
|
||||
absy = fabs(y);
|
||||
for(z = absx; z - absy >= 0. ; z -= absy)
|
||||
;
|
||||
i = z;
|
||||
if( x < 0.0 )
|
||||
i *= -1;
|
||||
retval = i;
|
||||
return( retval );
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/**
|
||||
** formated print
|
||||
**/
|
||||
|
||||
/*char *version "@(#)fprintf - jan 24, 1982";*/
|
||||
#include "/usr/regulus/stdio.h"
|
||||
#define BUFSIZ 80
|
||||
|
||||
char *ftoa();
|
||||
char *etoa();
|
||||
char *petoa();
|
||||
char *pftoa();
|
||||
|
||||
static char *__str;
|
||||
FILE *__stream;
|
||||
static char **_p;
|
||||
|
||||
fprintf(fp, plist)
|
||||
FILE *fp;
|
||||
char *plist;
|
||||
{
|
||||
if (!fp->_flag & _WMODE) return;
|
||||
|
||||
__stream = fp;
|
||||
_p = &plist;
|
||||
__doprintf(0);
|
||||
fflush(fp);
|
||||
}
|
||||
|
||||
sprintf(s, plist)
|
||||
char *s, *plist;
|
||||
{
|
||||
__str = s;
|
||||
_p = &plist;
|
||||
__doprint(1);
|
||||
*__str = NULL;
|
||||
}
|
||||
|
||||
__doprint(mode)
|
||||
int mode;
|
||||
{
|
||||
register char *fmt, c;
|
||||
char buf[BUFSIZ];
|
||||
extern char *__prtshort(), *__prtld();
|
||||
register int *pi;
|
||||
int width, prec;
|
||||
int left, longf;
|
||||
char padchar;
|
||||
char *s;
|
||||
int n;
|
||||
auto (*fn)();
|
||||
int len;
|
||||
|
||||
fmt = *_p++;
|
||||
|
||||
pi = _p;
|
||||
while (c = *fmt++)
|
||||
{
|
||||
_p = pi;
|
||||
if (c != '%')
|
||||
{
|
||||
__putch(mode, c);
|
||||
continue;
|
||||
}
|
||||
left = 0;
|
||||
if ((c = *fmt++) == '-')
|
||||
{
|
||||
c = *fmt++;
|
||||
left++;
|
||||
}
|
||||
padchar = ' ';
|
||||
if (c == '0')
|
||||
{
|
||||
padchar = c;
|
||||
c = *fmt++;
|
||||
}
|
||||
width = -1;
|
||||
while (c >= '0' && c <= '9')
|
||||
{
|
||||
if (width < 0)
|
||||
width = 0;
|
||||
width = width * 10 + (c - '0');
|
||||
c = *fmt++;
|
||||
}
|
||||
prec = -1;
|
||||
if (c == '.')
|
||||
{
|
||||
prec = 0;
|
||||
c = *fmt++;
|
||||
}
|
||||
while (c >= '0' && c <= '9')
|
||||
{
|
||||
prec = prec * 10 + (c - '0');
|
||||
c = *fmt++;
|
||||
}
|
||||
longf = 0;
|
||||
if (c == 'l')
|
||||
{
|
||||
longf++;
|
||||
c = *fmt++;
|
||||
}
|
||||
/*
|
||||
* we now have all the prelims out of the way;
|
||||
* let's see what we want to print
|
||||
*/
|
||||
s = buf;
|
||||
switch (c)
|
||||
{
|
||||
|
||||
case 'd': /* decimal signed */
|
||||
case 'D':
|
||||
if (longf)
|
||||
fn = __prtld;
|
||||
else
|
||||
fn = __prtshort;
|
||||
__prtint(pi++, buf, 10, 1, fn, 0);
|
||||
if (longf)
|
||||
pi++;
|
||||
break;
|
||||
|
||||
case 'u': /* decimal unsigned */
|
||||
case 'U':
|
||||
__prtint(pi++, buf, 10, 0, __prtshort, 0);
|
||||
break;
|
||||
|
||||
case 'o': /* octal unsigned */
|
||||
case 'O':
|
||||
if (longf)
|
||||
fn = __prtld;
|
||||
else
|
||||
fn = __prtshort;
|
||||
__prtint(pi++, buf, 8, 0, fn, 0);
|
||||
if (longf)
|
||||
pi++;
|
||||
break;
|
||||
|
||||
case 'x': /* hexadecimal unsigned */
|
||||
case 'X':
|
||||
if (longf)
|
||||
fn = __prtld;
|
||||
else
|
||||
fn = __prtshort;
|
||||
__prtint(pi++, buf, 16, 0, fn, c == 'X');
|
||||
if (longf)
|
||||
pi++;
|
||||
break;
|
||||
|
||||
case 's': /* string */
|
||||
case 'S':
|
||||
s = *_p++;
|
||||
pi = _p;
|
||||
break;
|
||||
|
||||
case 'c': /* character */
|
||||
case 'C':
|
||||
n = *pi++;
|
||||
buf[0] = n;
|
||||
buf[1] = '\0';
|
||||
break;
|
||||
|
||||
case 'e': /* exponential */
|
||||
case 'E':
|
||||
petoa(pi, buf, prec);
|
||||
pi =+ 2;
|
||||
prec = -1;
|
||||
break;
|
||||
|
||||
case 'f': /* floating */
|
||||
case 'F':
|
||||
fptoa(pi, buf, prec);
|
||||
pi =+ 2;
|
||||
prec = -1;
|
||||
break;
|
||||
|
||||
case 'g': /* e or f */
|
||||
case 'G':
|
||||
pftoa(pi, buf, prec);
|
||||
if (strlen(buf) > (7 + prec)) /* smallest fp string */
|
||||
petoa(pi, buf, prec);
|
||||
pi =+ 2;
|
||||
prec = -1;
|
||||
break;
|
||||
|
||||
default: /* just print the character */
|
||||
__putch(mode, c);
|
||||
continue;
|
||||
|
||||
}
|
||||
len = __length(s);
|
||||
if (prec < len && prec >= 0)
|
||||
len = prec;
|
||||
n = width - len;
|
||||
if (!left)
|
||||
{
|
||||
if (padchar != ' ' && *s == '-')
|
||||
{
|
||||
len--;
|
||||
__putch(mode, *s); s++;
|
||||
}
|
||||
while (n-- > 0)
|
||||
__putch(mode, padchar);
|
||||
}
|
||||
while (len--) {
|
||||
__putch(mode, *s); s++;
|
||||
}
|
||||
while (n-- > 0)
|
||||
__putch(mode, padchar);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
__putch(mode, c)
|
||||
int mode;
|
||||
char c;
|
||||
{
|
||||
if (mode)
|
||||
*__str++ = c;
|
||||
else
|
||||
putc(c,__stream);
|
||||
return (c);
|
||||
}
|
||||
|
||||
char *
|
||||
pftoa(addr,buf,prec)
|
||||
float *addr;
|
||||
char *buf;
|
||||
int prec;
|
||||
{
|
||||
float fp;
|
||||
|
||||
if (prec<0)
|
||||
prec = 6;
|
||||
fp = *addr;
|
||||
return( ftoa(fp, buf, prec) );
|
||||
}
|
||||
|
||||
char *
|
||||
petoa(addr,buf,prec)
|
||||
float *addr;
|
||||
char *buf;
|
||||
int prec;
|
||||
{
|
||||
float fp;
|
||||
|
||||
if (prec<0)
|
||||
prec = 6;
|
||||
fp = *addr;
|
||||
return( etoa(fp, buf, prec) );
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) ftoa - jan 24, 1982"; */
|
||||
|
||||
/*
|
||||
* FFP Floating Point to Ascii String Conversion Routine :
|
||||
* FFP Standard Single Precision Representation Floating Point
|
||||
*
|
||||
* char *
|
||||
* ftoa(f,buf,prec)
|
||||
* float f;
|
||||
* char *buf;
|
||||
* int prec;
|
||||
*
|
||||
* No more than 9 decimal digits are allowed in single precision.
|
||||
* Largest positive number is 3.4 * 10^33 and the smallest positive
|
||||
* number is 1.2 * 10^-38.
|
||||
* Rely's on the fact that a long and a float are both 32 bits.
|
||||
*/
|
||||
|
||||
#define BIAS 127L
|
||||
|
||||
float ffptof();
|
||||
|
||||
char *
|
||||
ftoa(fl,buf,prec)
|
||||
long fl; /* ffp formatted float */
|
||||
char *buf;
|
||||
int prec;
|
||||
{
|
||||
register char *bp;
|
||||
register int exp, digit;
|
||||
float f;
|
||||
|
||||
prec = (prec <= 0) ? 1 : (prec <= 9) ? prec : 9;
|
||||
bp = buf;
|
||||
f = ffptof(fl); /* get floating point value */
|
||||
if (f < 0.0) { /* negative float */
|
||||
*bp++ = '-';
|
||||
f = -f; /* make it positive */
|
||||
}
|
||||
if (f == 0.0) {
|
||||
*bp++ = '0'; *bp++ = '.';
|
||||
while (prec--)
|
||||
*bp++ = '0';
|
||||
*bp = 0;
|
||||
return(buf);
|
||||
}
|
||||
for (exp=0; f < 1.0; f = f * 10.0) /* get negative exp */
|
||||
exp--;
|
||||
for ( ; f >= 1.0; f = f / 10.0) /* 0.XXXXXXE00 * 10^exp */
|
||||
exp++;
|
||||
|
||||
if (exp<=0) /* one significant digit */
|
||||
*bp++ = '0';
|
||||
for ( ; exp>0; exp--) { /* get significant digits */
|
||||
f = f * 10.0;
|
||||
digit = f; /* get one digit */
|
||||
f = f - digit;
|
||||
*bp++ = digit + '0';
|
||||
}
|
||||
*bp++ = '.';
|
||||
for( ; exp<0 && prec; prec--, exp++) /* exp < 0 ? */
|
||||
*bp++ = '0';
|
||||
while(prec-- > 0) {
|
||||
f = f * 10.0;
|
||||
digit = f; /* get one digit */
|
||||
f = f - digit;
|
||||
*bp++ = digit + '0';
|
||||
}
|
||||
*bp = 0;
|
||||
return(buf);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) fptoffp - Feb 1, 1983"; */
|
||||
|
||||
/*
|
||||
* Floating Point to FFP Floating Point Routine :
|
||||
* FFP Standard Single Precision Representation Floating Point
|
||||
*
|
||||
* long
|
||||
* fptoffp(f)
|
||||
* float f;
|
||||
*
|
||||
* Rely's on the fact that a long and a float are both 32 bits.
|
||||
*/
|
||||
|
||||
long
|
||||
fptoffp(f) /* convert current machine float to ffp rep */
|
||||
float f; /* unsigned input, guaranteed positive */
|
||||
{
|
||||
register int exp, count, sign;
|
||||
long l;
|
||||
|
||||
if (f == 0.0)
|
||||
return(0L);
|
||||
if (f < 0.0) {
|
||||
f = -f;
|
||||
sign = 1;
|
||||
}
|
||||
else
|
||||
sign = 0;
|
||||
exp = 0L;
|
||||
for( ; f >= 1.0; f = f / 2.0)
|
||||
exp++;
|
||||
for( ; f < 0.5; f = f * 2.0)
|
||||
exp--;
|
||||
f = f * 16777216.0; /* 2 ^ 24 */
|
||||
l = f;
|
||||
l =<< 8;
|
||||
exp =+ 0x40;
|
||||
l =| (exp & 0x7f);
|
||||
if (sign)
|
||||
l =| 0x80;
|
||||
return(l);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/* char *version "@(#) ftol - Feb 1, 1983"; */
|
||||
|
||||
/*
|
||||
* Floating Point Float to Long Routine :
|
||||
* Front End to IEEE Floating Point Package.
|
||||
*
|
||||
* long
|
||||
* fpftol(fparg)
|
||||
* double fparg;
|
||||
*
|
||||
* Return : Fixed Point representation of Floating Point Number
|
||||
*/
|
||||
|
||||
long
|
||||
fpftol(f)
|
||||
long f;
|
||||
{
|
||||
register long l;
|
||||
register int exp, sign;
|
||||
|
||||
exp = (f & 0x7f) - 0x40;
|
||||
if (f == 0L || exp < 0) /* underflow or 0 */
|
||||
return(0L);
|
||||
sign = (f & 0x80);
|
||||
if (exp > 31) /* overflow */
|
||||
return( (sign) ? 0x80000000 : 0x7fffffff);
|
||||
l = (f>>8) & 0xffffff;
|
||||
exp =- 24;
|
||||
for( ; exp < 0 ; exp++)
|
||||
l =>> 1;
|
||||
for( ; exp > 0; exp--)
|
||||
l =<< 1;
|
||||
if (sign)
|
||||
l = -l;
|
||||
return(l);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
/*char *version "@(#) fpltof - Feb 1, 1983"; */
|
||||
|
||||
/*
|
||||
* Floating Point Long to Float Routine :
|
||||
* Front End to FFP Floating Point Package.
|
||||
*
|
||||
* double
|
||||
* fpltof(larg)
|
||||
* long larg;
|
||||
*
|
||||
* Return : Floating Point representation of Long Fixed point integer
|
||||
*/
|
||||
|
||||
long
|
||||
fpltof(l)
|
||||
long l;
|
||||
{
|
||||
register long exp;
|
||||
register int sign;
|
||||
|
||||
if (l < 0L) { /* signed ?? */
|
||||
sign = 1;
|
||||
l = -l;
|
||||
}
|
||||
else
|
||||
sign = 0;
|
||||
if (l == 0L)
|
||||
return(0L);
|
||||
exp = 24L;
|
||||
for( ; l & 0x7f000000; exp++) /* something in upper 7 bits */
|
||||
l =>> 1;
|
||||
for( ; !(l & 0x00800000); exp--) /* get mantissa : .F */
|
||||
l =<< 1;
|
||||
l =<< 8; /* mantissa (.F) into top 24 bits */
|
||||
exp =+ 0x40;
|
||||
l =| (exp & 0x7f);
|
||||
if (sign)
|
||||
l =| 0x80;
|
||||
return(l);
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
Copyright 1982
|
||||
Alcyon Corporation
|
||||
8716 Production Ave.
|
||||
San Diego, Ca. 92121
|
||||
*/
|
||||
|
||||
//char *version "@(#)printf - jan 24, 1982";
|
||||
|
||||
/**
|
||||
** formated print
|
||||
**/
|
||||
|
||||
#define BUFSIZ 80
|
||||
#define MAXFILES 15
|
||||
|
||||
char *etoa();
|
||||
char *ftoa();
|
||||
char *petoa();
|
||||
char *pftoa();
|
||||
|
||||
printf(arg1,arg2,arg3)
|
||||
char *arg1, *arg2, *arg3;
|
||||
{
|
||||
register char *fmt, c;
|
||||
char buf[BUFSIZ];
|
||||
extern char *__prtshort(), *__pprtld(), *__prtld();
|
||||
int mode;
|
||||
char *fd;
|
||||
register char **p;
|
||||
register int *pi;
|
||||
int width, prec;
|
||||
int left, longf;
|
||||
char padchar;
|
||||
char *s;
|
||||
int n;
|
||||
auto (*fn)();
|
||||
int len;
|
||||
|
||||
if( arg1 == -1 ) {
|
||||
mode = 2;
|
||||
fd = arg2;
|
||||
p = &arg3;
|
||||
}
|
||||
else if( arg1 < MAXFILES ) {
|
||||
mode = 1; /* printf(fd,fmt,...) or printf(-1,str,fmt,...) */
|
||||
fd = arg1;
|
||||
p = &arg2;
|
||||
}
|
||||
else {
|
||||
mode = 0;
|
||||
fd = 0;
|
||||
p = &arg1;
|
||||
}
|
||||
fmt = *p++;
|
||||
|
||||
pi = p;
|
||||
while (c = *fmt++)
|
||||
{
|
||||
p = pi;
|
||||
if (c != '%')
|
||||
{
|
||||
__pputch(mode, &fd, c);
|
||||
continue;
|
||||
}
|
||||
left = 0;
|
||||
if ((c = *fmt++) == '-')
|
||||
{
|
||||
c = *fmt++;
|
||||
left++;
|
||||
}
|
||||
padchar = ' ';
|
||||
if (c == '0')
|
||||
{
|
||||
padchar = c;
|
||||
c = *fmt++;
|
||||
}
|
||||
width = -1;
|
||||
while (c >= '0' && c <= '9')
|
||||
{
|
||||
if (width < 0)
|
||||
width = 0;
|
||||
width = width * 10 + (c - '0');
|
||||
c = *fmt++;
|
||||
}
|
||||
prec = -1;
|
||||
if (c == '.')
|
||||
{
|
||||
prec = 0;
|
||||
c = *fmt++;
|
||||
}
|
||||
while (c >= '0' && c <= '9')
|
||||
{
|
||||
prec = prec * 10 + (c - '0');
|
||||
c = *fmt++;
|
||||
}
|
||||
longf = 0;
|
||||
if (c == 'l')
|
||||
{
|
||||
longf++;
|
||||
c = *fmt++;
|
||||
}
|
||||
/* we now have all the prelims out of the way;
|
||||
let's see what we want to print */
|
||||
|
||||
s = buf;
|
||||
switch (c)
|
||||
{
|
||||
|
||||
case 'd': /* decimal signed */
|
||||
case 'D':
|
||||
if (longf)
|
||||
fn = __prtld;
|
||||
else
|
||||
fn = __prtshort;
|
||||
__prtint(pi++, buf, 10, 1, fn, 0);
|
||||
if (longf)
|
||||
pi++;
|
||||
break;
|
||||
|
||||
case 'u': /* decimal unsigned */
|
||||
case 'U':
|
||||
__prtint(pi++, buf, 10, 0, __prtshort, 0);
|
||||
break;
|
||||
|
||||
case 'o': /* octal unsigned */
|
||||
case 'O':
|
||||
if (longf)
|
||||
fn = __prtld;
|
||||
else
|
||||
fn = __prtshort;
|
||||
__prtint(pi++, buf, 8, 0, fn, 0);
|
||||
if (longf)
|
||||
pi++;
|
||||
break;
|
||||
|
||||
case 'x': /* hexadecimal unsigned */
|
||||
case 'X':
|
||||
if (longf)
|
||||
fn = __prtld;
|
||||
else
|
||||
fn = __prtshort;
|
||||
__prtint(pi++, buf, 16, 0, fn, c == 'X');
|
||||
if (longf)
|
||||
pi++;
|
||||
break;
|
||||
|
||||
case 's': /* string */
|
||||
case 'S':
|
||||
s = *p++;
|
||||
pi = p;
|
||||
break;
|
||||
|
||||
case 'c': /* character */
|
||||
case 'C':
|
||||
n = *pi++;
|
||||
buf[0] = n;
|
||||
buf[1] = '\0';
|
||||
break;
|
||||
|
||||
case 'e': /* exponential */
|
||||
case 'E':
|
||||
petoa(pi, buf, prec);
|
||||
pi =+ 2;
|
||||
prec = -1;
|
||||
break;
|
||||
|
||||
case 'f': /* floating */
|
||||
case 'F':
|
||||
pftoa(pi, buf, prec);
|
||||
pi =+ 2;
|
||||
prec = -1;
|
||||
break;
|
||||
|
||||
case 'g': /* e or f */
|
||||
case 'G':
|
||||
pftoa(pi, buf, prec);
|
||||
if (strlen(buf) > (7 + prec) ) /* smallest fp string */
|
||||
petoa(pi, buf, prec);
|
||||
pi =+ 2;
|
||||
prec = -1;
|
||||
break;
|
||||
|
||||
default: /* just print the character */
|
||||
__pputch(mode, &fd, c);
|
||||
continue;
|
||||
|
||||
}
|
||||
len = __length(s);
|
||||
if (prec < len && prec >= 0)
|
||||
len = prec;
|
||||
n = width - len;
|
||||
if (!left)
|
||||
{
|
||||
if (padchar != ' ' && *s == '-')
|
||||
{
|
||||
len--;
|
||||
__pputch(mode, &fd, *s++);
|
||||
}
|
||||
while (n-- > 0)
|
||||
__pputch(mode, &fd, padchar);
|
||||
}
|
||||
while (len--)
|
||||
__pputch(mode, &fd, *s++);
|
||||
while (n-- > 0)
|
||||
__pputch(mode, &fd, padchar);
|
||||
}
|
||||
if (mode == 2)
|
||||
*fd = '\0';
|
||||
}
|
||||
|
||||
|
||||
__pputch(mode, pfd, c)
|
||||
int mode;
|
||||
char c;
|
||||
char **pfd;
|
||||
{
|
||||
register long fd;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
|
||||
case 0:
|
||||
if (write(1,&c,1) != 1) return(-1);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
fd = *pfd;
|
||||
if (write((int)fd,&c,1) != 1) return(-1);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
*(*pfd)++ = c;
|
||||
break;
|
||||
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
|
||||
char *
|
||||
pftoa(addr,buf,prec)
|
||||
float *addr;
|
||||
char *buf;
|
||||
int prec;
|
||||
{
|
||||
float fp;
|
||||
|
||||
if (prec<0)
|
||||
prec = 6;
|
||||
fp = *addr;
|
||||
return( ftoa(fp, buf, prec) );
|
||||
}
|
||||
|
||||
char *
|
||||
petoa(addr,buf,prec)
|
||||
float *addr;
|
||||
char *buf;
|
||||
int prec;
|
||||
{
|
||||
float fp;
|
||||
|
||||
if (prec<0)
|
||||
prec = 6;
|
||||
fp = *addr;
|
||||
return( etoa(fp, buf, prec) );
|
||||
}
|
||||
Reference in New Issue
Block a user