source: trunk/minix/lib/float/cfi.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.2 KB
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/float/cfi.c,v 1.1.1.1 2005/04/21 14:56:10 beng Exp $ */
7
8/*
9 CONVERT FLOAT TO SIGNED (CFI 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#include "FP_shift.h"
19
20long
21cfi(ds,ss,src)
22int ds; /* destination size (2 or 4) */
23int ss; /* source size (4 or 8) */
24DOUBLE src; /* assume worst case */
25{
26 EXTEND buf;
27 long new;
28 short max_exp;
29
30 extend(&src.d[0],&buf,ss); /* get extended format */
31 if (buf.exp < 0) { /* no conversion needed */
32 src.d[ss == 8] = 0L;
33 return(0L);
34 }
35 max_exp = (ds << 3) - 2; /* signed numbers */
36 /* have more limited max_exp */
37 if (buf.exp > max_exp) {
38 if (buf.exp == max_exp+1 && buf.sign && buf.m1 == NORMBIT &&
39 buf.m2 == 0L) {
40 }
41 else {
42 trap(EIOVFL); /* integer overflow */
43 buf.exp %= max_exp; /* truncate */
44 }
45 }
46 new = buf.m1 >> (31-buf.exp);
47 if (buf.sign)
48 new = -new;
49done:
50 src.d[ss == 8] = new;
51 return(new);
52}
Note: See TracBrowser for help on using the repository browser.