forked from Stichting-MINIX-Research-Foundation/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextend.c
More file actions
executable file
·111 lines (101 loc) · 2.48 KB
/
Copy pathextend.c
File metadata and controls
executable file
·111 lines (101 loc) · 2.48 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
(c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
/*
CONVERTS FLOATING POINT TO EXTENDED FORMAT
Two sizes of FLOATING Point are known:
SINGLE and DOUBLE
*/
/********************************************************/
/*
It is not required to normalize in extended
format, but it has been chosen to do so.
Extended Format is as follows (at exit):
->sign S000 0000 | 0000 0000 <SIGN>
->exp 0EEE EEEE | EEEE EEEE <EXPONENT>
->m1 LFFF FFFF | FFFF FFFF <L.Fraction>
FFFF FFFF | FFFF FFFF <Fraction>
->m2 FFFF FFFF | FFFF FFFF <Fraction>
FFFF F000 | 0000 0000 <Fraction>
*/
/********************************************************/
#include "FP_bias.h"
#include "FP_shift.h"
#include "FP_types.h"
#include "get_put.h"
/********************************************************/
void
extend(from,to,size)
unsigned long *from;
EXTEND *to;
int size;
{
register char *cpt1;
unsigned long tmp;
int leadbit = 0;
cpt1 = (char *) from;
#if FL_MSL_AT_LOW_ADDRESS
#if FL_MSW_AT_LOW_ADDRESS
to->exp = uget2(cpt1);
#else
to->exp = uget2(cpt1+2);
#endif
#else
#if FL_MSW_AT_LOW_ADDRESS
to->exp = uget2(cpt1+(size == sizeof(DOUBLE) ? 4 : 0));
#else
to->exp = uget2(cpt1+(size == sizeof(DOUBLE) ? 6 : 2));
#endif
#endif
to->sign = (to->exp & 0x8000); /* set sign bit */
to->exp ^= to->sign;
if (size == sizeof(DOUBLE))
to->exp >>= DBL_EXPSHIFT;
else
to->exp >>= SGL_EXPSHIFT;
if (to->exp > 0)
leadbit++; /* will set Lead bit later */
else to->exp++;
if (size == sizeof(DOUBLE)) {
#if FL_MSL_AT_LOW_ADDRESS
to->m1 = get4(cpt1);
cpt1 += 4;
tmp = get4(cpt1);
#else
tmp = get4(cpt1);
cpt1 += 4;
to->m1 = get4(cpt1);
#endif
if (to->exp == 1 && to->m1 == 0 && tmp == 0) {
to->exp = 0;
to->sign = 0;
to->m1 = 0;
to->m2 = 0;
return;
}
to->m1 <<= DBL_M1LEFT; /* shift */
to->exp -= DBL_BIAS; /* remove bias */
to->m1 |= (tmp>>DBL_RPACK); /* plus 10 == 32 */
to->m2 = (tmp<<DBL_LPACK); /* plus 22 == 32 */
}
else { /* size == sizeof(SINGLE) */
to->m1 = get4(cpt1);
to->m1 <<= SGL_M1LEFT; /* shift */
if (to->exp == 1 && to->m1 == 0) {
to->exp = 0;
to->sign = 0;
to->m1 = 0;
to->m2 = 0;
return;
}
to->exp -= SGL_BIAS; /* remove bias */
to->m2 = 0L;
}
to->m1 |= NORMBIT; /* set bit L */
if (leadbit == 0) { /* set or clear Leading Bit */
to->m1 &= ~NORMBIT; /* clear bit L */
nrm_ext(to); /* and normalize */
}
}