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".
|
|
|
|
*/
|
|
|
|
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1988-04-07 11:40:46 +00:00
|
|
|
|
1988-04-07 10:57:49 +00:00
|
|
|
/*
|
1988-07-25 10:46:15 +00:00
|
|
|
CONVERT FLOAT TO SIGNED (CFI m n)
|
1988-04-07 10:57:49 +00:00
|
|
|
|
|
|
|
N.B. The caller must know what it is getting.
|
|
|
|
A LONG is always returned. If it is an
|
|
|
|
integer the high byte is cleared first.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "FP_trap.h"
|
|
|
|
#include "FP_types.h"
|
1989-07-25 14:21:09 +00:00
|
|
|
#include "FP_shift.h"
|
1988-04-07 10:57:49 +00:00
|
|
|
|
|
|
|
long
|
|
|
|
cfi(ds,ss,src)
|
|
|
|
int ds; /* destination size (2 or 4) */
|
|
|
|
int ss; /* source size (4 or 8) */
|
1993-01-05 12:06:58 +00:00
|
|
|
DOUBLE src; /* assume worst case */
|
1988-04-07 10:57:49 +00:00
|
|
|
{
|
|
|
|
EXTEND buf;
|
|
|
|
long new;
|
1989-07-25 14:21:09 +00:00
|
|
|
short max_exp;
|
1988-04-07 10:57:49 +00:00
|
|
|
|
1993-01-05 12:06:58 +00:00
|
|
|
extend(&src.d[0],&buf,ss); /* get extended format */
|
1989-07-25 14:21:09 +00:00
|
|
|
if (buf.exp < 0) { /* no conversion needed */
|
1993-01-05 12:06:58 +00:00
|
|
|
src.d[ss == 8] = 0L;
|
1988-04-07 10:57:49 +00:00
|
|
|
return(0L);
|
|
|
|
}
|
1989-07-25 14:21:09 +00:00
|
|
|
max_exp = (ds << 3) - 2; /* signed numbers */
|
1988-04-07 10:57:49 +00:00
|
|
|
/* have more limited max_exp */
|
|
|
|
if (buf.exp > max_exp) {
|
1989-07-25 14:21:09 +00:00
|
|
|
if (buf.exp == max_exp+1 && buf.sign && buf.m1 == NORMBIT &&
|
|
|
|
buf.m2 == 0L) {
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
trap(EIOVFL); /* integer overflow */
|
|
|
|
buf.exp %= max_exp; /* truncate */
|
|
|
|
}
|
1988-04-07 10:57:49 +00:00
|
|
|
}
|
1989-07-25 14:21:09 +00:00
|
|
|
new = buf.m1 >> (31-buf.exp);
|
1988-04-07 10:57:49 +00:00
|
|
|
if (buf.sign)
|
|
|
|
new = -new;
|
|
|
|
done:
|
1993-01-05 12:06:58 +00:00
|
|
|
src.d[ss == 8] = new;
|
1988-04-07 10:57:49 +00:00
|
|
|
return(new);
|
|
|
|
}
|