forked from Stichting-MINIX-Research-Foundation/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcfi.fc
More file actions
executable file
·52 lines (46 loc) · 1.12 KB
/
Copy pathcfi.fc
File metadata and controls
executable file
·52 lines (46 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
(c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
/*
CONVERT FLOAT TO SIGNED (CFI m n)
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"
#include "FP_shift.h"
long
cfi(ds,ss,src)
int ds; /* destination size (2 or 4) */
int ss; /* source size (4 or 8) */
DOUBLE src; /* assume worst case */
{
EXTEND buf;
long new;
short max_exp;
extend(&src.d[0],&buf,ss); /* get extended format */
if (buf.exp < 0) { /* no conversion needed */
src.d[ss == 8] = 0L;
return(0L);
}
max_exp = (ds << 3) - 2; /* signed numbers */
/* have more limited max_exp */
if (buf.exp > max_exp) {
if (buf.exp == max_exp+1 && buf.sign && buf.m1 == NORMBIT &&
buf.m2 == 0L) {
}
else {
trap(EIOVFL); /* integer overflow */
buf.exp %= max_exp; /* truncate */
}
}
new = buf.m1 >> (31-buf.exp);
if (buf.sign)
new = -new;
done:
src.d[ss == 8] = new;
return(new);
}