Rev | Line | |
---|
[9] | 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/float/cfu.c,v 1.1.1.1 2005/04/21 14:56:10 beng Exp $ */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | CONVERT FLOAT TO UNSIGNED (CFU m n)
|
---|
| 10 |
|
---|
| 11 | N.B. The caller must know what it is getting.
|
---|
| 12 | A LONG is always returned. If it is an
|
---|
| 13 | integer the high byte is cleared first.
|
---|
| 14 | */
|
---|
| 15 |
|
---|
| 16 | #include "FP_trap.h"
|
---|
| 17 | #include "FP_types.h"
|
---|
| 18 |
|
---|
| 19 | long
|
---|
| 20 | cfu(ds,ss,src)
|
---|
| 21 | int ds; /* destination size (2 or 4) */
|
---|
| 22 | int ss; /* source size (4 or 8) */
|
---|
| 23 | DOUBLE src; /* assume worst case */
|
---|
| 24 | {
|
---|
| 25 | EXTEND buf;
|
---|
| 26 | long new;
|
---|
| 27 | short newint, max_exp;
|
---|
| 28 |
|
---|
| 29 | extend(&src.d[0],&buf,ss); /* get extended format */
|
---|
| 30 | if (buf.exp < 0) { /* no conversion needed */
|
---|
| 31 | src.d[ss == 8] = 0L;
|
---|
| 32 | return(0L);
|
---|
| 33 | }
|
---|
| 34 | max_exp = (ds << 3) - 1;
|
---|
| 35 | if (buf.exp > max_exp) {
|
---|
| 36 | trap(EIOVFL); /* integer overflow */
|
---|
| 37 | buf.exp %= max_exp;
|
---|
| 38 | }
|
---|
| 39 | new = buf.m1 >> (31-buf.exp);
|
---|
| 40 | done:
|
---|
| 41 | src.d[ss == 8] = new;
|
---|
| 42 | return(new);
|
---|
| 43 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.