ack/mach/proto/fp/cif4.c

58 lines
1.2 KiB
C
Raw Normal View History

1988-04-07 11:40:46 +00:00
/*
(c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
1988-04-07 10:57:49 +00:00
/*
1993-01-05 12:06:58 +00:00
CONVERT INTEGER TO SINGLE (CIF n 4)
1988-04-07 10:57:49 +00:00
THIS ROUTINE WORKS BY FILLING AN EXTENDED
WITH THE INTEGER VALUE IN EXTENDED FORMAT
AND USES COMPACT() TO PUT IT INTO THE PROPER
FLOATING POINT PRECISION.
*/
#include "FP_types.h"
1993-01-05 12:06:58 +00:00
SINGLE
1988-04-07 10:57:49 +00:00
cif4(ss,src)
int ss; /* source size */
long src; /* largest possible integer to convert */
{
EXTEND buf;
short *ipt;
long i_src;
1993-01-05 12:06:58 +00:00
SINGLE *result;
1988-04-07 10:57:49 +00:00
zrf_ext(&buf);
if (ss == sizeof(long)) {
1989-07-25 14:21:09 +00:00
buf.exp = 31;
1988-04-07 10:57:49 +00:00
i_src = src;
1993-01-05 12:06:58 +00:00
result = (SINGLE *) &src;
1988-04-07 10:57:49 +00:00
}
else {
ipt = (short *) &src;
i_src = (long) *ipt;
1989-07-25 14:21:09 +00:00
buf.exp = 15;
1993-01-05 12:06:58 +00:00
result = (SINGLE *) &ss;
1988-04-07 10:57:49 +00:00
}
if (i_src == 0) {
1993-01-05 12:06:58 +00:00
*result = (SINGLE) 0L;
1988-04-07 10:57:49 +00:00
return(0L);
}
/* ESTABLISHED THAT src != 0 */
/* adjust exponent field */
buf.sign = (i_src < 0) ? 0x8000 : 0;
/* clear sign bit of integer */
/* move to mantissa field */
buf.m1 = (i_src < 0) ? -i_src : i_src;
/* adjust mantissa field */
if (ss != sizeof(long))
buf.m1 <<= 16;
nrm_ext(&buf); /* adjust mantissa field */
1993-01-05 12:06:58 +00:00
compact(&buf, result,sizeof(SINGLE)); /* put on stack */
1988-04-07 10:57:49 +00:00
return(*result);
}