Line | |
---|
1 | /*
|
---|
2 | (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
---|
3 | See the copyright notice in the ACK home directory, in the file "Copyright".
|
---|
4 | */
|
---|
5 |
|
---|
6 | /* $Header: /cvsup/minix/src/lib/ack/float/cif8.fc,v 1.1 2005/10/10 15:27:42 beng Exp $ */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | CONVERT INTEGER TO FLOAT (CIF n 8)
|
---|
10 |
|
---|
11 | THIS ROUTINE WORKS BY FILLING AN EXTENDED
|
---|
12 | WITH THE INTEGER VALUE IN EXTENDED FORMAT
|
---|
13 | AND USES COMPACT() TO PUT IT INTO THE PROPER
|
---|
14 | FLOATING POINT PRECISION.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #include "FP_types.h"
|
---|
18 |
|
---|
19 | void
|
---|
20 | cif8(ss,src)
|
---|
21 | int ss; /* source size */
|
---|
22 | long src; /* largest possible integer to convert */
|
---|
23 | {
|
---|
24 | EXTEND buf;
|
---|
25 | DOUBLE *result; /* for return value */
|
---|
26 | short *ipt;
|
---|
27 | long i_src;
|
---|
28 |
|
---|
29 | result = (DOUBLE *) ((void *) &ss); /* always */
|
---|
30 | zrf_ext(&buf);
|
---|
31 | if (ss == sizeof(long)) {
|
---|
32 | buf.exp = 31;
|
---|
33 | i_src = src;
|
---|
34 | }
|
---|
35 | else {
|
---|
36 | ipt = (short *) &src;
|
---|
37 | i_src = (long) *ipt;
|
---|
38 | buf.exp = 15;
|
---|
39 | }
|
---|
40 | if (i_src == 0) {
|
---|
41 | zrf8(result);
|
---|
42 | return;
|
---|
43 | }
|
---|
44 | /* ESTABLISHED THAT src != 0 */
|
---|
45 | /* adjust exponent field */
|
---|
46 | buf.sign = (i_src < 0) ? 0x8000 : 0;
|
---|
47 | /* clear sign bit of integer */
|
---|
48 | /* move to mantissa field */
|
---|
49 | buf.m1 = (i_src < 0) ? -i_src : i_src;
|
---|
50 | /* adjust mantissa field */
|
---|
51 | if (ss != sizeof(long))
|
---|
52 | buf.m1 <<= 16;
|
---|
53 | nrm_ext(&buf);
|
---|
54 | compact(&buf,&result->d[0],8);
|
---|
55 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.